Averages using arrays by calling a function

Even the title of it sounds confusing to me...
This is the assignment and what I have so far. Which isn't very much since I'm having a hard time understanding how to approach this problem.

"Write a program that a C++ program that can be used to determine grades at the end of the semester. For each student, who is identified by an integer number between 1 and 60, four examination grades must be kept. Additionally, two final grades must be computed. The first grade average is simply the average of all four grades. The second grade average is computed by weighting the four grades as follows: the first grade gets a weight of 0.2, the second grade gets a weight of 0.3, the third grade gets a weight of 0.3 and the fourth grade gets a weight of 0.2; that is computed as:
0.2*grade1 + 0.3*grade2 + 0.3*grade3 + 0.2*grade4

Using this information, you are to construct a 60*7 two dimensional array, in which the first column is used for the student number, the next four columns for the grades and the last two columns for the computed final grades. The output of the program should be a display of the data in the completed array.
For the test purposes, the following table is provided:

Student Grade 1 Grade 2 Grade 3 Grade 4
---------------------------------------
1 100 100 100 100
2 100 0 100 0
3 82 94 73 86
4 64 74 84 94
5 94 84 74 64

The program should print the grade matrix including the averages. Then it should calculate the mean and standard deviation for both averages for the class and prints the results.

Program Organization
The main() routine should declare and populate the array with the test data shown above. It should then
call a function, passing in the array as a parameter. The function should perform the calculations and print
the result.

Heres what I have:
#include<iostream>
using namespace std;

void final1(int i[], int j[]);
void final2(int i, int j[]);
double clas[60][7]={0};
int nothing;
int main()
{

cout<<"Student Grade 1 Grade 2 Grade 3 Grade 4 Final 1 Final 2"<<endl;
cout<<"___________________________________________________________________"<<endl;
double clas[60][7]={{1,100,100,100,100},{2,100,0,100,0},{3,82,94,73,86},{4,64,74,84,94},{5,94,84,74,64}};
cout<<clas<<endl;
cin>>nothing;
return 0;
}

void final1(int i[], int j[])
{
for(int i=0,j=0;i<60;i++)
{
cout<<clas[i][j];
}
}


void final2(int i, int j[])
{
for(int j=1;j<4;j++)
{
cin>>clas[i][j];
clas[i][5]=clas[i][5]+clas[i][j];
}
clas[i][6]=(.3*clas[i][1])+(.2*clas[i][2])+(.2*clas[i][3])+(.3*clas[i][4]);
}



My idea was that the last two columns should be added to original 5 columns but I'm not sure how to do that...

Any help is appreciated,
Thanks!
Keiiy,
if you have some time, meaning if it isn't due in a few hours, then,
I would approach the problem in three steps.

You already have most of the code and it looks like building the 2D array and keeping everything in it's place and correct all at the same time, is adding to the confusion, including the pointers to each element.

Write the code with only a single student.
It doesn't even need to be an arrray at all to begin.
but as a 1-d array then the overall problem becomes much easier.
a_student[stud_ID,
stud_grade1,
stud_grade2,
stud_grade3,
stud_grade4,
grade1+grade2+grade3+grade4 / 4,
0.2*grade1 + 0.3*grade2 + 0.3*grade3 + 0.2*grade4
]

That's the array and it's contents for the first student,
or in this case, the Only student.

next,

The program should print the grade matrix including the averages.
Hold that thought, because printing a 60 by 7 array will take time & planning.


Then it should calculate the mean and standard deviation for both averages for the class and prints the results.

ok, so this will be another fnc call

int calc_mean( int grd_avg1, int grd_avg2 )
.......// calculate the mean and standard deviation for both averages
RETURN ( the result)

Remember to plan for a PRINT fnc(), maybe even Two;
one for the screen and one for paper (if the teacher wants to see it on paper.)

you 'can' also use one print fnc for both cases with OVERLOADING, but that's later.



You can then TEST the "Single Student" program with the
Five test examples provided in the test matrix - one at a time.
Run the Five students through your new program , one at a time,
and verify that the results are correct.


Once it works fine for One Student at a time,
Then you can modify the 1-d array a_student[1,7]
to a 60 student array a_student[60,7]

and hand it in.

Last edited on
Topic archived. No new replies allowed.