Create a program in C++ ( using one dimensional and two dimensional array traversals). An example of
Create a program in C++ ( using one dimensional and two dimensional array traversals). An example of
the test data for the program is given below. Your program should work for any number of students, assume a maximum of 40 students.
Input data for the program contains information about students in a graduating class. For
each student, the following information is given per line:
– student's name (string)
– student's identification number (integer)
– student's score in each of eight subjects (floats)
You are to write a program to do the following:
1. Compute the average score for each student.
2. Compute the average score for each subject.
3. Compute the overall average score in two ways, by averaging the student averages
and by averaging the subject averages.
For each student, your program should print a line showing the student's name, id number, score in each
subject, and average score. The program should then print a line showing the average score for each
subject. Two more lines should then be printed and should be labeled as follows (where XX.X are the
overall averages):
AVERAGE SCORE USING STUDENT AVERAGES: XX.X
AVERAGE SCORE USING SUBJECT AVERAGES: XX.X
You must use appropriate arrays to store and manipulate your data. Your output should be in columnar
format and should include appropriate headers. Each score should be printed with one decimal point.
many simple program modules is strongly recommended. Assume a maximum of 40 students.
EXAMPLE TEST DATA
Lozini, Femeo 322838549 57.4 88.4 54.0 97.1 49.5 78.4 91.3 39.4
Romulus, Mary 419548265 54.8 58.4 94.6 74.8 84.0 67.7 84.6 79.8
The output should look like :
Name ID Scores Student's average
Lozini, Femeo 322838549 57.4 88.4 54.0 97.1 49.5 78.4 91.3 39.4 69.4
Romulus, Mary 419548265 54.8 58.4 94.6 74.8 84.0 67.7 84.6 79.8 74.8
Average per subject 56.1 73.4 74.3 85.95 66.8 73.1 88.0 59.6
AVERAGE SCORE USING STUDENT AVERAGES: 72.5
AVERAGE SCORE USING SUBJECT AVERAGES: 72.5
Example of coding
Reading the Input Data File into Your Program
1. The following program will read in and print the entire input data file:
#include
#include
#include
using namespace std;
int main ()
{
ifstream inData;
char LstName[10], FstName[10]; //or string LstName, FstName;
int i, ID;
float scores[8];
inData.open (“studentdata.txt”);
inData >> LstName >> FstName >> ID;
for (i=0; i<=7; i++) inData >> scores [i];
while (inData) {
cout
for (i=0; i
cout
}
cout
inData >> LstName >> FstName >> ID;
for (i=0; i
inData >> scores [i];
}
inData.close ();
return 0;
}
2. The above program does not store the data into arrays. To store the data into arrays, the declarations
would have to be changed to something like:
char LstName[40][10], FstName[40][10]; //or string LstName[40], FstName[40];
int ID[40], stu;
float scores[40][8];
A loop similar to the following would then be needed:
stu = 0;
inData >> LstName[stu] >> FstName[stu] >> ID[stu];
for (i=0; i
inData >> scores [stu][i];
}
while (inData) {
stu++
inData >> LstName[stu] >> FstName[stu] >> ID[stu];
for (i=0; i
inData >> scores [stu][i];
}