Do Chapter 8’s Programming Exercise 13 on page 605, using the name Lab10TestScor
ID: 3814624 • Letter: D
Question
Do Chapter 8’s Programming Exercise 13 on page 605, using the name Lab10TestScores. Your program should read the input data from a file--to save yourself some typing, use the file named Lab10ScoresData.txt on the course website’s Unit 10 page. Use the image below as a guide for what your program’s output should look like. For this program it’s okay to assume that there are five tests scores for each student—you don’t need to make it flexible enough to handle a different number of tests. When declaring the two-dimensional array to hold the test scores, make it six columns wide instead of five, even though there are only five tests—use the sixth column to hold each student’s average, which your program must compute. Show me your working program.
wirte a program to calculate students average test scores and their grades. you may assume the following input data.
use three arrays. a one dimetional array to store the students names, a two dimensional array to store the test scores, and a parrallel one dimetional array to store grades. your prgram must contain at least the following function; a function to read and store data into two arrays, a function to calculate the average test score and grade, and a function to output the results. have your program also output the class average.
this is my code
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
const int NUMBER_OF_PEOPLE = 10;
const int NUMBER_OF_TESTS = 5;
void read(string names[], int namesSize, double
scores[][NUMBER_OF_TESTS], int scoresRowsize)
{
ifstream infile;
infile.open(" Lab10ScoresData.txt ");
int counterNames = 0, counterScores = 0;
while (counterNames < namesSize)
{
infile >> names [counterNames];
while (counterScores < NUMBER_OF_TESTS)
{
infile >> scores[counterNames][counterScores];
counterScores++;
}
counterScores = 0;
counterNames++;
}
}
void calculate(double matrix[], double scores[][NUMBER_OF_TESTS], int scoresRow_Size)
{
int counter = 0, num = 0;
double total = 0, average = 0;
cout << fixed << showpoint << setprecision(2) << endl;
while (counter < scoresRow_Size)
{
while (num < NUMBER_OF_TESTS)
{
total = total + scores[counter][num];
num++;
}
average = (total / NUMBER_OF_TESTS);
matrix[counter] = average;
total = 0;
average = 0;
num = 0;
counter++;
}
}
void print(double matrix[], string names[], int namesSize)
{
cout << setw(10) << " Name " << setw(12) << " Grade" << endl;
int counter = 0;
while (counter < namesSize)
{
cout << setw(10) << names[counter] << setw(12)
<< matrix[counter] << endl;
counter++;
}
}
int main()
{
string names[NUMBER_OF_PEOPLE];
double scores[NUMBER_OF_PEOPLE][NUMBER_OF_TESTS];
double grades[NUMBER_OF_PEOPLE];
read(names, 10, scores, 10);
calculate(grades, scores, 10);
print(grades, names, 10);
system(" pause ");
return 0;
}
it is missing things
but it is also supposed to list each student's test scores, and it is supposed to calculate and display a letter grade for each student, and it is supposed to calculate an average for the entire class. So you'll need to add more code to do those other things.
please dont forget to add the prgram description with it
Explanation / Answer
Function to calculate the class average:
You can take the individual average value which has been calculated for each student and add them up and sume obtained if divided by the number of students will provide the average for the whole class and also for grades we need addional info like how is grade decided based on the individual's average.
Thanks
void calculateClassAverage(double matrix[], int namesSize)
{
int counter = 0, clsAvg = 0, sum = 0 ;
while (counter < namesSize)
{
sum = sum + matrix[counter] ;
counter++;
}
clsAvg = sum/namesSize;
cout << "Class Avg: " << clsAvg << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.