Question: Data input, output, and processing must be done in independent functions. Below is my code please help me separate it. Write a program that uses

Data input, output, and processing must be done in independent functions. Below is my code please help me separate it.

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

char gradeInfo(double Average); // 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 << " 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]; } for (int student = 0; student < numOfStudents; student++)// loop for getting details of students { int totalScores = 0; cout << endl; cout << " Enter the name of the student " << (student + 1) << ": "; cin.ignore(); getline(cin, s[student].Name); cout << endl; cout << " Enter the ID number (digits only) : "; cin >> s[student].IDnum; for (int i = 0; i < numOfTestScores; i++) // loop for getting test scores { do { cout << " Enter the test score: "; cin >> s[student].Tests[i]; } while (s[student].Tests[i] < 0);

//calculate total score totalScores += s[student].Tests[i]; } //calculate average s[student].Average = totalScores / numOfTestScores; s[student].Grade = gradeInfo(s[student].Average); } //Dislay results: //a table should be displayed on the screen listing each //student's name, ID number, average test score, and course grade.

cout << "Student Information" << endl; cout << "_____________________________________________________________" << endl; cout << setw(20) << "Name" << setw(15) << "ID Number"; cout << setprecision(4) << setw(15) << "Average" << setw(10) << "Grade" << endl; cout << "_____________________________________________________________" << endl; for (int student = 0; student < numOfStudents; student++) { cout << setw(20) << s[student].Name << setw(15) << s[student].IDnum; cout << setprecision(4) << setw(15) << s[student].Average; cout << setw(10) << s[student].Grade << endl; } }

char gradeInfo(double Average) { if (Average > 89) return 'A'; else if (Average < 90 && Average >79) return 'B'; else if (Average < 80 && Average >69) return 'C'; else if (Average < 70 && Average >59) return 'D'; else return 'F'; }

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!