Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in C++ Instructions Consider a file containing a double dimensional array, where

ID: 3883771 • Letter: I

Question

in C++

Instructions

Consider a file containing a double dimensional array, where each row represents a student’s grades, and each column represents all the grades received on a specific exaam (example below). For the sake of simplicity, assume there are 10 students (rows) and 5 exaams (columns). We will not be testing your program with any other numbers. Read in these grades, find each student’s average grade, the average grade scored for each exaam, then write the grades and averages to a file in the format described below. Create your own input file for testing purposes, with numbers separated by spaces. You are provided with the definitions for several functions that will help you on the next page - YOU ARE REQUIRED TO USE THESE FUNCTIONS.

Example of Input File

100 70 75 80 100

98 45 99 100 95

65 78 75 81 75

100 78 99 34 100

58 64 72 89 88

87 82 84 48 76

100 100 98 100 98

38 45 89 76 76

56 80 91 92 90

87 70 72 80 72

Required Functions

1. void readGrades(string fileName, int numberOfExaams, int numOfStudents);

a. This function should read in the grades from your file, and store it in a double-dimensional array, which should be a global variable.

2. void getWeights(double weights[], int numOfExaams);

a. Inside this function, you should accept user input from the keyboard (use cin) in order to fill the weights[] array with the relative weight of each exaam (you may use any values you like, but they should all add up to 1).

b. Note: You are passing in weights[] by reference, and therefore any operations performed on the array will modify whichever array is initially passed into it.

3. void getAvgsOfExaams(double exaamAvgs[], int numOfExaams, int numOfStudents);

a. This function should fill the array exaamAvgs with the average grade scored by all students on each exaam.

b. Note: Again, you are passing in exaamAvgs[] by reference, so any modifications inside the function will modify the array that is initially passed into the function

4. void getAvgsOfStudents(double studentAvgs[], double weights[], int numOfExaams, int numOfStudents);

a. This function should fill studentAvgs[] with the weighted averages of their two exaams.

5. void writeFinalGrades(double exaamAvgs[], double studentGrades[], int numOfExaams, int numOfStudents);

a. Writing to a file titled “finalgrades.txt”, the student’s grades should be outputted, with each row followed by its final average, and each exaam’s overall average at the bottom of their corresponding columns.

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;

//global variable
int array [20][20];

void readGrades(string Filename, int numofExams, int numofStudents); ////function read in the grades from file, and store it in a double-dimensional array
void getWeights(double weights[], int numOfExams); //function accept user input from the keyboard and fill the weights[] array with the relative weight of each exaam
void getAvgsOfExaams(double exaamAvgs[], int numOfExaams, int numOfStudents); //function fill the array exaamAvgs with the average grade scored by all students on each exaam.
void getAvgsOfStudents(double studentAvgs[], double weights[], int numOfExaams, int numOfStudents);
void writeFinalGrades(double exaamAvgs[], double studentGrades[], int numOfExaams, int numOfStudents);

int main()
{
int i,j;
int numofExams=3,numofStudents=2;
double weights[numofExams],exaamAvgs[numofExams],studentAvgs[numofStudents],studentGrades[numofStudents];
string Filename="input1.txt";
readGrades(Filename,numofExams,numofStudents);
getWeights(weights, numofExams);
getAvgsOfExaams(exaamAvgs, numofExams, numofStudents);
getAvgsOfStudents(studentAvgs, weights, numofExams, numofStudents);
writeFinalGrades(exaamAvgs, studentGrades, numofExams, numofStudents);
return 0;
}

//function read in the grades from file, and store it in a double-dimensional array
void readGrades(string Filename, int numofExams, int numofStudents)
{
ifstream file;
int i,j;
file.open(Filename);
if (!file.is_open())
cout<<"Can not open file"<<endl;
//int array [numofExams][numofStudents];
for (i=0; i < numofStudents; i++)
{
for (j=0; j< numofExams; j++)
{
file >> array[i][j];
}
}
cout<<"exams-->"<<endl;
for (i=0; i < numofStudents; i++)
{
cout<<"Stud "<<i+1<<":";
for (j=0; j< numofExams; j++)
{
cout<<array[i][j]<<" ";
}
cout<<endl;
}
  
  
}

//function accept user input from the keyboard and fill the weights[] array with the relative weight of each exaam
void getWeights(double weights[], int numOfExams)
{
int i;
for(i=0;i<numOfExams;i++)
{
cout<<"Enter weight for exam "<<i+1<<": ";
cin>>weights[i];
}
}

//function fill the array exaamAvgs with the average grade scored by all students on each exaam
void getAvgsOfExaams(double exaamAvgs[], int numOfExams, int numOfStudents)
{
int i,j;
double total=0;
for(i=0;i<numOfExams;i++)
{
for(j=0;j<numOfStudents;j++)
{
total+=array[j][i];
}
exaamAvgs[i]=total/numOfStudents;
total=0;
}
cout<<"Exam avg:"<<endl;
for(i=0;i<numOfExams;i++)
{
cout<<"exam "<<i+1<<": "<<exaamAvgs[i]<<endl;
}
cout<<endl;
}

void getAvgsOfStudents(double studentAvgs[], double weights[], int numOfExaams, int numOfStudents)
{
int i,j;
double weights_avg[numOfStudents];
double total_weigth=0,total_avg=0;
for(i=0;i<2;i++)
total_weigth+=weights[i];
for(i=0;i<numOfStudents;i++)
{
for(j=0;j<2;j++) //only for 2 exams
{
total_avg+=array[i][j]*weights[j];
}
total_avg=total_avg/total_weigth;
weights_avg[i]=total_avg;
total_avg=0;
}
for(i=0;i<numOfStudents;i++)
{
studentAvgs[i]=weights_avg[i];
}
cout<<"Student average for 2 exams: "<<endl;
for(i=0;i<numOfStudents;i++)
{
cout<<"stud " <<i+1<<": "<<studentAvgs[i]<<endl;
}
  
}

void writeFinalGrades(double exaamAvgs[], double studentGrades[], int numOfExaams, int numOfStudents)
{
int i,j;
ofstream myfile;
myfile.open ("finalgrades.txt");
myfile << "Student Grade File."<<endl<<endl;
double grade=0;
for(i=0;i<numOfStudents;i++)
{
for(j=0;j<numOfExaams;j++)
{
grade+=array[i][j];
}
studentGrades[i]=grade/numOfExaams;
grade=0;
}
myfile<<"Student Grades"<<endl;
for(int i=0;i<numOfStudents;i++)
{
myfile<<studentGrades[i]<<endl;
}
}

input1.txt

10 20 30
40 50 60

please provide sample of finalgrades.txt file so that i can get the idea of output you want.