File Input and Output

Additional Exercises


  1. Write a program to read in the marks for a class. The file contains a number to indicate how many students are in the class, and then the name of a student followed by four marks, one for each of the subjects they are studying. The format of the input file is shown below:-

    3
    bob 10 10 10 10
    fred 2 12 14 15
    john 3 4 5 6

    The program will then calculate the average mark for each student, it will write the name of the student and their average mark to another file. For the example above, the output file will contain

    bob 10
    fred 10.75
    john 4.5

    In addition the program will print the overall average for the class to the screen.

    NOTE:
    You can assume that the maximum length of the name for any student is 10 characters.


Back to Main Page for Lecture 8