Question: .I need help on this C++ Program. I am almost done but my code it is not outputting what is meant to output. My code

.I need help on this C++ Program. I am almost done but my code it is not outputting what is meant to output. My code is on the bottom. Please check what i am doing wrong and tell me how i can fix it so that it will output the same thing as the sample output provided belowe. Thank you!

Program Description:

Write a program to analyze students scores. Each students ID and 4 original test scores are saved in the attached file student_ID_scores.txt. Assume there are exactly 15 students in the class.

CT1001 62 89 63 59 CT1002 99 91 95 86 CT1003 67 45 67 77 CT1004 61 78 90 73 CT1005 97 99 82 90 CT1006 90 96 81 92 CT1007 65 67 62 85 CT1008 78 80 79 90 CT1009 80 75 65 89 CT1010 87 98 90 92 CT1011 76 81 69 92 CT1012 100 95 86 95 CT1013 90 79 66 82 CT1014 80 68 71 66 CT1015 88 95 67 98

The program first opens the file, reads students IDs and scores from the file and saves them in two arrays:

o Create a one-dimensional string array IDs to store the students IDs.

o Create a (parallel) two-dimensional int array scores to store students original test scores. This array has 5 columns, the original 4 test scores should be saved in the first 4 columns, and the last column will be used to save the average score after the calculation in next step.

The program then retrieves test scores from the array scores, calculates average score and determines the final letter grade based on the rules in the table below for each student. Assume average score is integer value.

average score = (score1 + score2 + score3 + score4) / 4

Average score

Letter grade

90 ~ 100

A

80 ~ 89

B

70 ~ 79

C

60 ~ 70

D

0 ~ 60

F

The average score should be saved back in the 5th column of scores array.

Create a new parallel one-dimensional char array grades to save each students letter grade.

Program also needs to find the number of A, number of B, number of C, number of D and number of F grade. As well as the highest, lowest and average score of the class.

Finally, program will display all of the original scores and all results on the computer screen using the format shown as the sample output below.

The program must contain at least the following functions:

(1) A function GetScores to read and store data into IDs and scores arrays.

(2) A function AnalyzeScores to calculate students average score, determine letter grade, get the number of A, B, C, D and F, find the highest, lowest and average score of the class.

(3) A function DisplayResults to display all of the results as shown in the sample output.

Sample output:

I need help on this C++ Program. I am almost done but my code it is not outputting what is meant to output. it is suppose to output the following:

IDS TEST1 TEST2 TEST3 TEST4 Average Grade

CT1001 62 89 63 59 68.25 D CT1002 99 91 95 86 92.75 A CT1003 67 45 67 77 64.00 D CT1004 61 78 90 73 75.50 C CT1005 97 99 82 90 92.00 A CT1006 90 96 81 92 89.75 B CT1007 65 67 62 85 69.75 D CT1008 78 80 79 90 81.75 B CT1009 80 75 65 89 77.25 C CT1010 87 98 90 92 91.75 A CT1011 76 81 69 92 79.50 C CT1012 100 95 86 95 94.00 A CT1013 90 79 66 82 79.50 C CT1014 80 68 71 66 71.25 C CT1015 88 95 67 98 87.00 B

4 students got A's.

3 students got B's.

5 students got C's.

3 students got D's.

0 students got F's.

The highest score in the class is: 94.00

The lowest scored in the class is: 64.00

The average score of the class is: 80.92

MY CODE SO FAR:

#include "stdafx.h" #include #include #include #include

using namespace std;

//Constants const int SIZE = 15; const int COLUMN = 5;

//Declaring variables double classAvg = 0; double highestScore = 0; double lowestScore = 0;

//Declaring functions void GetScores(ifstream& inf, string IDData[], double scoresData[][COLUMN]); void AnalyzeScores(double scoresDATA[][COLUMN], char grade[], int gradeCount[], double stats[]); void DisplayResults(string IDData[], double scoresData[][COLUMN], char grade[], int gradeCount[], double stats[]);

int main() { //Declaring arrays string IDs[SIZE];//1D array double scores[SIZE][COLUMN]; //2D array char grade[SIZE]; int gradeCount[5] = { 0,0,0,0,0 }; //Number of A,B,C,D, and F grades double stats[3] = { 0.0,0.0,0.0 }; //Highest, Lowest, and average grade

// Get input file ifstream infile;

//Opening the file infile.open("student_ID_scores.txt", ios::in); if (!infile) { cout << "Error! Cannot open the input file." << endl; cout << "Program terminates!" << endl; return 1; }

//Run Analysis GetScores(infile, IDs, scores); AnalyzeScores(scores, grade, gradeCount, stats); DisplayResults(IDs, scores, grade, gradeCount, stats); infile.close();

//system("pause") char exit; cout << "Press any key to continue..."; cin >> exit;

return 0; }

// Function: Void // Description: Function that reads and stores data into "IDs" and "Scores" arrays.

void GetScores(ifstream& inf, string IDData[], double scoresData[][COLUMN]) { int r = 0; for (int r = 0; r < SIZE; r++) { inf >> IDData[r];

for (int c = 0; c < COLUMN - 1; c++) { inf >> scoresData[r][c]; } } }

// Function: Void // Description: Function that calculate students average score, determine letter grade, get the number of A, B, C, D and F, find the highest, lowest and average score of the class

void AnalyzeScores(double scoresDATA[][COLUMN], char grade[], int gradeCount[], double stats[]) { double classTotalAvg = 0.0; double avg = 0.0; for (int r = 0; r < SIZE; r++) { double total = 0;

for (int c = 0; c < COLUMN - 1; c++) //ONE 'FOR LOOP' INSIDE THE OTHER = NESTED { total = total + scoresDATA[r][c]; } //Calculate and store average value avg = scoresDATA[r][COLUMN - 1]; avg = (total) / (COLUMN - 1);

//Get and store grade if (avg >= 90 && avg <= 100) { grade[r] = 'A'; gradeCount[0]++; } else if (avg >= 80 && avg <= 89) { grade[r] = 'B'; gradeCount[1]++; } else if (avg >= 80 && avg <= 89) { grade[r] = 'C'; gradeCount[2]++; } else if (avg >= 70 && avg <= 79) { grade[r] = 'D'; gradeCount[3]++; } else { grade[r] = 'F'; gradeCount[4]++; }

//Calculating class sum of averages classTotalAvg += scoresDATA[r][COLUMN - 1];

//Finding class average classAvg = classTotalAvg / 15;

//Looking for highest score if (highestScore < scoresDATA[r][COLUMN - 1]) highestScore = scoresDATA[r][COLUMN - 1];

//Looking for lowest score if (lowestScore > scoresDATA[r][COLUMN - 1]) lowestScore = scoresDATA[r][COLUMN - 1]; }

//Storing highest, lowest & average grade stats[0] = highestScore; stats[1] = lowestScore; stats[2] = classAvg; }

// Function: void // Description: Function that displays results in the sample output.

void DisplayResults(string IDDATA[], double scoresData[][COLUMN], char grades[], int gradeCount[], double stats[]) { std::cout << std::setprecision(2) << std::fixed; cout << "IDs\tTest1\tTest2\tTest3\tTest4\tAvg\tGrade" << endl; cout << "--\t-----\t-----\t-----\t-----\t---\t-----" << endl;

for (int r = 0; r < SIZE; r++) { cout << IDDATA[r] << "\t";

for (int c = 0; c < COLUMN; c++) { cout << scoresData[r][c] << "\t"; cout << grades[r]; }

} //Printing statistical data int c = 0; { cout << " " << gradeCount[c] << " students got A's." << endl; cout << gradeCount[c] << " students got B's" << endl; cout << gradeCount[c] << " students got C's" << endl; cout << gradeCount[c] << " students got D's" << endl; cout << gradeCount[c] << " students got F's" << endl;

cout << " The highest score in the class is:" << stats[0] << endl; cout << "The lowest score in the class is:" << stats[1] << endl; cout << "The average score of the class is:" << stats[2] << endl; cout << " "; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!