Write a program that a C++ program what can be used to determine grades at the e
ID: 3661644 • Letter: W
Question
Write a program that a C++ program what 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 grade averages 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 a weight of 0.3, and the fourth grade 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 X 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:
Your program should print the grade matrix ( table gridline not required), including the averages. Then it should calculate the mean and standard deviation for both averages for the class and print the results.
Program organization: The main() function 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.
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 64Explanation / Answer
Grades.cpp
// Compute.cpp : Defines the entry point for the console application.
//
#include<iostream>
#include<cmath>
using namespace std;
void compute(double grades[][7]);
void display(double grades[][7]);
double standard_deviation(double grades[][7], int n);
double mean(double grades[][7], int n);
int _tmain(int argc, _TCHAR* argv[])
{
double grades[60][7] = { 0 };
for (int i = 0; i < 5; ++i)
{
if (i == 0)
{
grades[i][0] = i + 1;
grades[i][1] = 100;
grades[i][2] = 100;
grades[i][3] = 100;
grades[i][4] = 100;
}
else if (i == 1)
{
grades[i][0] = i + 1;
grades[i][1] = 100;
grades[i][2] = 0;
grades[i][3] = 100;
grades[i][4] = 0;
}
else if (i == 2)
{
grades[i][0] = i + 1;
grades[i][1] = 82;
grades[i][2] = 94;
grades[i][3] = 73;
grades[i][4] = 86;
}
else if (i == 3)
{
grades[i][0] = i + 1;
grades[i][1] = 64;
grades[i][2] = 74;
grades[i][3] = 84;
grades[i][4] = 94;
}
else if (i == 4)
{
grades[i][0] = i + 1;
grades[i][1] = 94;
grades[i][2] = 84;
grades[i][3] = 74;
grades[i][4] = 64;
}
}
compute(grades);
return 0;
}
//To compute the average and weighted average of grades
void compute(double grades[][7])
{
for (int i = 0; i < 60; ++i)
{
if (grades[i][0] != 0)
{
double gradeSum = 0;
double weightedGrade = 0;
for (int j = 1; j < 5; j++)
{
gradeSum += grades[i][j];
if (j == 1)
{
weightedGrade += 0.2*grades[i][j];
}
else if (j == 2)
{
weightedGrade += 0.3*grades[i][j];
}
else if (j == 3)
{
weightedGrade += 0.3*grades[i][j];
}
else
{
weightedGrade += 0.2*grades[i][j];
}
}
grades[i][5] = gradeSum / 4;
grades[i][6] = weightedGrade;
}
}
display(grades);
cout << "Mean of grades averages " << mean(grades, 5) << endl;
cout << "Mean of weighted grades averages " << mean(grades, 5) << endl;
cout << "Standard Deviation of grades averages " << standard_deviation(grades, 6) << endl;
cout << "Standard Deviation of weighted grades averages " << standard_deviation(grades, 6) << endl;
}
//To display only the rows which have a non zero student id
void display(double grades[][7])
{
for (int i = 0; i < 60; ++i)
{
//If student id is 0 that means this row is empty so no need to display
if (grades[i][0] != 0)
{
for (int j = 0; j < 7; ++j)
{
cout << grades[i][j] << " ";
}
cout << endl;
}
}
}
//Function to calculate standard deviation,column variable is for defining the column no for which standard deviation is to be calculated
double standard_deviation(double grades[][7], int column)
{
double gradeMean = 0.0, sum_deviation = 0.0;
gradeMean = mean(grades, column);
int n = 0;
for (int i = 0; i < 60; ++i)
{
//If student id is 0 that means this row is empty so no need to include it in calculation
if (grades[i][0] != 0)
{
sum_deviation += (grades[i][column] - gradeMean)*(grades[i][column] - gradeMean);
n++;
}
}
return sqrt(sum_deviation / n);
}
//To calculate the mean of a column of 2d array and column no is passed as a parameter
double mean(double grades[][7], int column)
{
double mean = 0.0;;
int n = 0;
for (int i = 0; i < 60; ++i)
{
if (grades[i][0] != 0)
{
mean += grades[i][column];
n++;
}
}
if (n > 0)
{
mean = mean / n;
}
return mean;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.