Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me correct the below code. Please pay attention to details. /* Write a program that uses a structure to store the following data:

Please help me correct the below code. Please pay attention to details.

/* Write a program that uses a structure to store the following data: Name - Student name, Idnum - Student ID number, Tests - Pointer to an Array of test scores, Average - Average test score, Grade - Course grade The Program should keep a list of test scores for a group of students. It should ask the user how many test scores there are to be and how many students there are. It should then dynamically allocate an array of structures. Each structure's Tests member should point to a dynamically allocated array that will hold the test scores. After the arrays have been dynamically allocated, the program should ask for the ID number and all the test scores of each student. The average test score should be calculated and stored in the average member of each structure. The course grade should be computer on the basis of the following grading scale: 91-100 = A, 81-90 = B, 71-80 = C, 61-70 = D, 60 of below is F. The course grade should then be stored in the Grade member of each structure. Once all this data is calculated, a table should be displayed on the screen listing each student's name, ID number, average test score, and course grade. Input validation: Be sure all the data for each student is entered. Do not accept negative numbers for any test score. */

#include #include #include using namespace std;

//Structure for the student data struct StudentData { string Name; // student name int IDnum; // Student ID number int* Tests; // pointer to an array f test scores double Average; //Average test scores char Grade; //course grade };

// function prototype void getData(); // to get and store the students data void gradeInfo(); // to calculate the students' grades

int main() { int numOfTestScores; int numOfStudents;

// Header cout << " *** This program will store and show the table of student data. ***" << endl; cout << " **** Programmed by (my name)" << endl; cout << "********************************************************************" << endl;

//It should ask the user how many test scores there are to be and how many //students there are. cout << " Enter the number of test scores: "; cin >> numOfTestScores; cout << "/n Enter the number of students: "; cin >> numOfStudents;

//It should then dynamically allocate an array of structures. //Each structure's Tests member should point to a dynamically allocated array //that will hold the test scores. StudentData* s = new StudentData[numOfStudents];

//Each structure's Tests member should point to a dynamically allocated array //that will hold the test scores. for (int student = 0; student < numOfStudents; student++) { s[student].Tests = new int[numOfTestScores]; } getData(); gradeInfo(); //Dislay results: //a table should be displayed on the screen listing each //student's name, ID number, average test score, and course grade.

cout << "/t/tStudent Information" << endl; cout << "/n_______________________________________________________" << endl; cout << setw(10) << "Name" << setw(10) << "ID Number"; cout << setprecision(4) << setw(10) << "Average" << setw(10) << "Grade" << endl; cout << "/n_______________________________________________________" << endl;

}

void getData(int numOfStudents, double totalScores, double testScores) { string name; do { for (int student = 0; student < numOfStudents; student++) { cout << " Enter the name of the student " << student << ": "; cin >> name; cout << "/nEnter the ID number (digits only) : " << endl; cout << " Enter the test score : "; cin >> testScores; } } while (testScores > 0); totalScores += testScores; }

void gradeInfo(double Average, double totalScores, int numOfStudents) { Average = totalScores / numOfStudents; if (Average > 89) cout << " The student Average is A" << endl; else if (Average < 90 && Average >79) cout << " The student Average is B" << endl; else if (Average < 80 && Average >69) cout << " The student Average is C" << endl; else if (Average < 70 && Average >59) cout << " The student Average is D" << endl; else cout << " The student average is F" << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

12-4 Briefly discuss options for group-based incentives. PAGE 439

Answered: 1 week ago

Question

Know the principles of effective service recovery systems.

Answered: 1 week ago

Question

Explain the service recovery paradox.

Answered: 1 week ago