You are asked to write a program that will prompt 1. Student name, 2. Test I score and 3. Test II score. Your program will compute the test score average for each student and assign a grade based on the test average.
There are 5 students and NUM_STUDENT is defined as a constant that stores the number of students.
An array of structure - student is used and the members of the structure are as follows:
struct studentInfo {
string name;
int test1;
int test2;
int testAverage;
char grade;
};
const int NUM_STUDENT = 5; // Array size
studentInfo student[NUM_STUDENT]; // array variable declaration
Formula to compute the test average:
Test Average = (Test 1 score + Test 2 Score) /2
The grades are assigned based on the following table:
Test Average | Grade |
90 - 100 | A |
80 - 89 | B |
70 - 79 | C |
60 - 69 | D |
0 - 59 | F |
Use the following functions to perform different tasks.
1. The function getData is used to enter the student name, Test I score and Test II Score.
getData (students, NUM_STUDENT);
2. The function computeGrade will compute the average test score and the grade for each student. The average test score and the grade are stored in structure members - testAverage and grade.
computeGrade (students, NUM_STUDENT);
3. The function computeClassAverage will compute the class average of all test averages. The variable classAverage is to be declared as double.
classAverage = computeClassAverage (students, NUM_STUDENT);
4. The function printSummary will display the output as shown below.
printSummary (students, classAverage, NUM_STUDENT);
Use the following data:
Linda Smith,97, 85
Carol Melville,70, 80
Marilyn Lloyd,65, 88
Joyce Davis,59, 77
Susan White, 89, 98
Sample Output:
Name | Test I | Test II | Test Average | Grade |
Linda Smith | 97 | 85 | 91 | A |
Carol Melville | 70 | 80 | 75 | C |
Marilyn Lloyd | 74 | 88 | 81 | B |
Joyce Davis | 59 | 77 | 68 | D |
Susan White | 59 | 43 | 51 | F |
Test Average of Class | 73.2 |
The test average for the class is displayed with 1 digit after the decimal point.
Tips:
1.Use getline function to enter the name of the students
2.Use cout << setprecision(1) << fixed << showpoint to display the test average of the class.