Write a program that a C++ program what can be used to determine grades at the e
ID: 3573283 • 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:
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
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.
Explanation / Answer
#include <iostream>
#include <math.h>
using namespace std;
int grade_Calc(int sg[][5]);
int main()
{
int student_grades[5][5] =
{
{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},
};
grade_Calc(student_grades);
return 0;
}
int grade_Calc(int sg[][5])
{
int sum_for_avg = 0;
double weighted_grade = 0.0;
double simple_avg = 0.0;
double sum2 = 0.0;
cout << "Stdnt" << " " << "Grd1" << " " << "Grd2" << " " << "Grd3" << " " << "Grd4" << " " << "Avg1" << " " << "Avg2" << endl;
for (int r = 0; r < 5; r++)
{
for (int c = 0; c < 5; c++)
{
cout << sg[r][c] << " ";
if (c != 0)
{
sum_for_avg += sg[r][c];
if ((c == 1) || (c == 4))
{
weighted_grade += (0.3 * sg[r][c]);
}
else
{
weighted_grade += (0.2 * sg[r][c]);
}
}
}
simple_avg = (sum_for_avg / 4.0);
cout << " " << simple_avg << " " << weighted_grade;
for (int k = 0; k < 5; k++)
{
if (k != 0)
{
sum2 += pow((sg[r][k] - simple_avg), 2);
}
}
sum_for_avg = 0;
weighted_grade = 0.0;
cout << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.