| CMSC 201 |
Lab 9: File I/OAssignmentFor this assignment you will be reading a list of grades in from a file called grades.txt and calculating their weighted average and assigning a letter grade to it. At the end, calculate a class average and write it to the file as well. Each line starts with a student name. After that, the first value is the weight of the grade, followed by the grade itself. This can repeat as many times as necessary but the format will always be correct. No error checking will be needed. We will not be rounding. Below 90 is a B, below 80 is a C, etc. The results of these calculations should be written to a text file called grade_report.txt Here is grades.txt in its entirety. It is ok to hard-code the file name for this lab. Simply copy-paste this into a file of the same name in your lab9 folder before you begin working: Alice 0.03 74 0.03 79 0.03 72 0.03 69 0.03 81 0.03 75 0.03 73 0.03 70 0.08 75 0.08 73 0.25 82 0.25 71 0.10 28 Bob 0.03 84 0.03 79 0.03 87 0.03 90 0.03 85 0.03 82 0.03 86 0.03 83 0.08 87 0.08 89 0.25 82 0.25 84 0.10 80 Charlie 0.03 66 0.03 63 0.03 89 0.03 65 0.03 57 0.03 70 0.03 64 0.03 67 0.08 65 0.08 62 0.25 70 0.25 61 0.10 27 Lisa 0.03 91 0.03 99 0.03 89 0.03 90 0.03 100 0.03 100 0.03 98 0.03 95 0.08 85 0.08 100 0.25 94 0.25 92 0.10 99 Your output file should look like this: Alice: 70.68 - C Bob: 83.86 - B Charlie: 61.84 - D Lisa: 94.06 - A Class average: 77.61 Tips:
|