LAB ASSIGNMENT:

 

Write a C++ program using arrays that will help grade a multiple choice test. (p 449 #6 slightly modified)

 

A file contains the following as the first line.

 

15 11 68 85 43 21.1 61.8 5 9 10 7 45 23 2 2 6 1 56 45.3 20

 

which corresponds to the answers in an arithmetic test.

 

Each of the next lines (less than 150 of them, but we are not sure of the exact amount) give a student’s  ID and student’s response, such as:

 

908-77-4532  14 11 67 85 43 21.1 61.8 5 9 10 7 45 23 2 2 6 1 56 45.3 20

 

We wish to write a program that will read in each of the student’s responses and print the student ID and grade to an output file. Since there are twenty question on the test, each one is worth 5 points out of 100.

 

  1. Declare an array, answer, that holds twenty variables (what type?) for the answer key.
  2. Declare an input file and output file and open them.
  3. Create a function, readarr, that reads the first line of the input file into the array answer.  This function takes the array answer, and the ifstream variable as parameters.

4.     In the main function, have a while loop that loops while there are still students in the file.

        Each time through the loop the student ID is read, and then a function getgrad is called.  This function takes the ifstream variable, the array answer, and a float reference variable as parameters.  The function reads the student’s answers from the file, compares them to the correct answers and places the final grade into the float reference variable.

5.      The main function prints the ID and grade to an output file.