Question: Program #7 Arrays2D You are to modify the program that you wrote for Program #6 (Arrays) to make use of 2D (two dimensional) arrays. Refer
Program #7 Arrays2D
You are to modify the program that you wrote for Program #6 (Arrays) to make use of 2D (two dimensional) arrays. Refer to that assignment for details not specified here.
First, name your program: arrays2D.cpp you can copy it from the old program as follows:
cp arrays.cpp arrays2D.cpp
In the previous program, you read student data from a file called studentScores.dat. You loaded the information into three parallel arrays, computing the average and letter grades for each student. You will do the same for this assignment, however, ALL of the data must be stored in parallel arrays first, two of which will be 2-dimensional, BEFORE any computation may be done.
Specifically, you should read the student id number (SID) as before into an array. The tests and programs scores should be loaded into two separate 2D arrays. The 2D array containing the test information will have 3 columns for each students 3 test scores. Similarly, the 2D array for the program scores will have 6 columns for the 6 program scores. You will also need a regular, one dimensional, array to store the final exam score. All of this should be done in main().
Once the data have been loaded into the parallel arrays, you can proceed to determine the average and the letter grade for each student and store them in the parallel arrays that were used in the previous assignment. Again, this should be done in main().
Finally, complete the assignment, as before, by generating the numbers of each grade (A, B, C, D, F), and the overall class average as described in the prior assignment.
Bottom line, the only real difference between these two assignments is that, instead of computing the individual students averages as the data is read from the file, you should first store all of the raw data in new, parallel, arrays, two of which are 2D. Then, go back and use the stored data to compute each students average. Once, you have that, the rest of the program is, essentially, the same and the output will look the same as well (So, you can use the executable arrays program from the last assignment as an example of what the output should look like).
As before, be sure to make all output neat and well formatted. (It should look the same as in the previous assignment.) Feel free to create any additional arrays that you might find helpful.
For refrence, here is the arrays.cpp file
#include
#include
#include
using namespace std;
void display(string sid[],double avg[],char grade[],int i);
void courseInf(char grade[],int i);
void courseAvg(double avg[],int i);
int main()
{
string sid[100];
int i=0;
double test,t,prog,p,final1,avg[100];
char grade[100];
ifstream infile;
infile.open("/export/home/public/carelli/csc135/InClass/studentScores.dat"); //opening source file
while(!infile.eof())//Repeat until EOF
{
infile>>sid[i];//Getting student ID
test=0;
//Getting test grade
for(int j=0;j<3;j++){
infile>>p;
test+=p;
}
prog=0;
//Getting program grade
for(int j=0;j<6;j++){
infile>>p;
prog+=p;
}
//Getting final grade
infile>>final1;
//Computing average grade
avg[i]=(test/3)*0.5+(prog/6)*0.25+final1*0.25;
//Determaining letter grade
if(avg[i]>89.5)
grade[i]='A';
else if(avg[i]>79.5)
grade[i]='B';
else if(avg[i]>69.5)
grade[i]='C';
else if(avg[i]>59.5)
grade[i]='D';
else
grade[i]='F';
i++;
}
display(sid,avg,grade,i);
courseInf(grade,i);
courseAvg(avg,i);
}
//Calculaing course average
void courseAvg(double avg[],int i)
{
double total=0;
for(int j=0;j
total+=avg[j];
cout<<" Course Average: "<<(total/i)< } //Determining number of A's,B's,C's,D's,F's void courseInf(char grade[],int i) { int a=0,b=0,c=0,d=0,f=0; for(int j=0;j { if(grade[j]=='A') a++; else if(grade[j]=='B') b++; else if(grade[j]=='C') c++; else if(grade[j]=='D') d++; else if(grade[j]=='F') f++; } cout<<"Course Information"<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
