CS 010 - Introduction to Computer Science I
Lab 7. Lab Practical; Assignment 4 Review; File I/O

Grading
Attendance & participation: 10 points

After this lab you should be comfortable:
        Reading from and writing to files.
        Formatting output.


Part 0: Lab Practical


Part 1: Assignment 4 Review (functions)


Part 2: Computing the Average

Write a program that takes input from a file of numbers of type double and outputs the average of those numbers to the screen. You may use the file avg.dat to test your program. The output to the screen when using this file should be:

Average = 15.2325

Your program should not continue if an error occurs while opening the file.


Part 3: Converting grades

Write a program that takes a name and their numeric grade from an input file and converts them to letter grades that are then output to an output file. The numeric grades are integers from 0 to 100. The scale for converting to letter grades is:

  > 89  = A
80 - 89 = B
70 - 79 = C
60 - 69 = D
  < 60  = F
You may use the file in_grades.dat as your input file to test your program. The output file given this input file should look something like this:

Matt F
John A
Mary A
Joan A
Jeremy D
Paul F
Lisa F
Lorena D
Brandon C
John B
Jim A
Kim A
Nellie A

You can use a string variable to store the name. An example string variable declaration is:

     char name[16];

This variable name can now store strings up to 15 (16-1) characters long.
Pages 241-244 in the textbook goes into more detail about inputting and storing string variables.


Part 4: Formatting Output

Modify your program from Part 2 so that it outputs both the numeric grade and the letter grade next to their name. Format the output so that it looks like this:

Matt     34     F
John     90     A
Mary     95     A
Joan     99     A
Jeremy   67     D
Paul     59     F
Lisa     58     F
Lorena   60     D
Brandon  70     C
John     80     B
Jim      90     A
Kim     100     A
Nellie  101     A

You may want to review section 5.2 in the textbook before tackling this part.


Part 5: User Input, File Output

Modify your program so that it takes input from the user instead of a file. The program should get a name and that person's numeric score. It then should output the name, the numeric score and the corresponding letter grade to an output file. The name of the output file should come from the user. You should format your output as in part 3. The program should continue to get input from the user until the user states they are done (they no longer want to continue).