Question
Please if you do not use Visual studio or online gdb do not answer. My code runs with the below output: Write a program that
Please if you do not use Visual studio or online gdb do not answer. My code runs with the below output:
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. */
Your program must include at least one function called by a pointer. Implement modularity as much as possible. The user is who decide to finish or continue the program. Data input, output and processing must be done in independent functions.
#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
int main() { int numOfTestScores; int numOfStudents; StudentData* s; char again; // Header cout
do { // Loop for the user is who decide to finish or continue the program.
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
// 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); //Determine whether the user want to enter more student data. cout > again; cin.ignore();
} while (again == 'Y' || again == 'y'); }
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 > numOfTestScores; cout > numOfStudents; }
void getData(int numOfTestScores, int numOfStudents, StudentData* s) // loop for getting details of students { for (int student = 0; student > s[student].IDnum;
// loop for getting test scores for (int i = 0; i > s[student].Tests[i]; } while (s[student].Tests[i]
}
void calcAvgScoreGrade(int numOfTestScores, int numOfStudents, StudentData* s) { for (int student = 0; student
// 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 79) return 'B'; else if (Average 69) return 'C'; else if (Average 59) return 'D'; else return 'F'; }
void displayData(int numOfTestScores, int numOfStudents, StudentData* s) { cout Name ID Number Average Grade f Sa 12345 85 B 0 0 0 Peter 65478 a ph 98756 - Doe 65478 mith 65423 enter more student data? (Y/N) Y er of test scores: 1 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started