Question: I added this function: void continueOrExit(int choice, int numOfTestScores, int numOfStudents); // choose contnite or exit The user is who decides to finish or continue

I added this function: void continueOrExit(int choice, int numOfTestScores, int numOfStudents); // choose contnite or exit The user is who decides to finish or continue the program but I have errors. please correct 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 void getNumbers(int& numOfTestScores, int& numOfStudents);// get students test numbers from users void getData(int numOfTestScores, int numOfStudents, StudentData* s); // get student detail void calcAvgScoreGrade(int numOfTestScores, int numOfStudents, StudentData* s); // to calculate average test score and determine grade char gradeInfo(double Average); // to calculate the students' grades void displayData(int numOfTestScores, int numOfStudents, StudentData* s);// Display data void continueOrExit(int choice, int numOfTestScores, int numOfStudents); // choose contnite or exit

int main() { int numOfTestScores; int numOfStudents; StudentData* s; int choice;

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

getNumbers(numOfTestScores, numOfStudents); // call getNumbers function

//It should then dynamically allocate an array of structures. 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]; }

// Call function to get data from the user (getting data function) getData(numOfTestScores, numOfStudents, s);

//Call function to calculate the verage test score (data processing function) calcAvgScoreGrade(numOfTestScores, numOfStudents, s);

// Call function to display data output displayData(numOfTestScores, numOfStudents, s);

// The user is who decide to finish or continue the program. continueOrExit(choice, numOfTestScores, numOfStudents); }

void getNumbers(int& numOfTestScores, int& numOfStudents) { //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; }

void getData(int numOfTestScores, int numOfStudents, StudentData* s) // loop for getting details of students { for (int student = 0; student < numOfStudents; student++) { 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;

// loop for getting test scores for (int i = 0; i < numOfTestScores; i++) { do { cout << " Enter the test score: "; cin >> s[student].Tests[i]; } while (s[student].Tests[i] < 0); } }

}

void calcAvgScoreGrade(int numOfTestScores, int numOfStudents, StudentData* s) { for (int student = 0; student < numOfTestScores; student++) // loop for getting test scores { int totalScores = 0; // Loop to calculate total score for (int i = 0; i < numOfTestScores; i++) totalScores += s[student].Tests[i];

// Calculate average score s[student].Average = totalScores / numOfTestScores;

// Call function to determine the grade s[student].Grade = gradeInfo(s[student].Average);; } }

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'; }

void displayData(int numOfTestScores, int numOfStudents, StudentData* s) { 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; } }

void continueOrExit(int choice, int numOfTestScores, int numOfStudents) { StudentData* s; while (1) { cout << " Do you want to enter another string? " << endl; cout << " Enter a choice: 1- Enter again 2- Exit " << endl; cin >> choice;

switch (choice) { case 1: getNumbers(numOfTestScores, numOfStudents); // call getNumbers function

//It should then dynamically allocate an array of structures. 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]; }

// Call function to get data from the user (getting data function) getData(numOfTestScores, numOfStudents, s);

//Call function to calculate the verage test score (data processing function) calcAvgScoreGrade(numOfTestScores, numOfStudents, s);

// Call function to display data output displayData(numOfTestScores, numOfStudents, s); break; case 2: exit(0); // case 2 to trminate // if anything else enters default:cout << "Invalid choice.You didn't enter 1 or 2. " << endl; } }

}

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!