Hi everyone, I am trying to fill this array for my COMP lab and have the grades be given from user input, 3 grades each for 4 students. I do not know where to go next with it but hopefully someone can help me out.
//Classwork 1 Submit finished code and .exe in one .zip file (see #1 and #2)
//DISPLAY 7.13 Two-Dimensional Array
//Reads quiz scores for each student into the two-dimensional array grade (but
//the input code is not shown in this display). Computes the average score
//for each student and the average score for each quiz. Displays the quiz scores
//and the averages.
//#include "stdafx.h" //for visual studio project only
#include <iostream>
#include <iomanip>
using namespace std;
const int NUMBER_STUDENTS = 4, NUMBER_QUIZZES = 3;
//void find(const int grade[ ][NUMBER_QUIZZES], int target); // #2Add this function
//Reads quiz scores for all students and returns the location of the first match to the target
void compute_st_ave(const int grade[][NUMBER_QUIZZES], double st_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES
//are the dimensions of the array grade. Each of the indexed variables
//grade[st_num-1, quiz_num-1] contains the score for student st_num on quiz
//quiz_num.
//Postcondition: Each st_ave[st_num-1] contains the average for student
//number stu_num.
void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], double quiz_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES
//are the dimensions of the array grade. Each of the indexed variables
//grade[st_num-1, quiz_num-1] contains the score for student st_num on quiz
//quiz_num.
//Postcondition: Each quiz_ave[quiz_num-1] contains the average for quiz number
//quiz_num.
void display(const int grade[][NUMBER_QUIZZES],
const double st_ave[], const double quiz_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES are the
//dimensions of the array grade. Each of the indexed variables grade[st_num-1,
//quiz_num-1] contains the score for student st_num on quiz quiz_num. Each
//st_ave[st_num-1] contains the average for student stu_num. Each
//quiz_ave[quiz_num -1] contains the average for quiz number quiz_num.
//Postcondition: All the data in grade, st_ave, and quiz_ave has been output.
//int _tmain(int argc, _TCHAR* argv[]) //for visual studio project only
int main( )
{
int grade[NUMBER_STUDENTS][NUMBER_QUIZZES];
double st_ave[NUMBER_STUDENTS];
double quiz_ave[NUMBER_QUIZZES];
//The code for filling the array grade goes here, #1 WRITE IT.
for (int i = 0; i < NUMBER_STUDENTS; i++)
{
}
compute_st_ave(grade, st_ave);
compute_quiz_ave(grade, quiz_ave);
display(grade, st_ave, quiz_ave);
//call find function here;
//Write a function to print student number \t student grade average \n to a file.
system ("pause");
return 0;
}
void compute_st_ave(const int grade[][NUMBER_QUIZZES], double st_ave[])
{
for (int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++)
{//Process one st_num:
double sum = 0;
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
sum = sum + grade[st_num -1][quiz_num -1];
//sum contains the sum of the quiz scores for student number st_num.
st_ave[st_num -1] = sum/NUMBER_QUIZZES;
//Average for student st_num is the value of st_ave[st_num-1]
}
}
void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], double quiz_ave[])
{
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
{//Process one quiz (for all students):
double sum = 0;
for (int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++)
sum = sum + grade[st_num -1][quiz_num -1];
//sum contains the sum of all student scores on quiz number quiz_num.
quiz_ave[quiz_num -1] = sum/NUMBER_STUDENTS;
//Average for quiz quiz_num is the value of quiz_ave[quiz_num-1]
}
}