Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you correct my code ,add some comments , and tell me why do I have a runtime error ? thanks: #include #include using namespace

Can you correct my code ,add some comments , and tell me why do I have a runtime error ? thanks:

#include

#include

using namespace std;

int inputData(string*&, double**&); void displayData(string*, double**, int); void cleanHeap(string*, double**, int);

int main() { string* numberOfStudent; double** grades; int students = inputData(numberOfStudent, grades); displayData(numberOfStudent, grades, students); cleanHeap(numberOfStudent, grades, students); }

int inputData(string*& name, double**& grade) {

int numberOfStudent = 0, numberOfTest = 0; // Prompting a positive number of students do { cout << "How many students do you have in system : "; cin >> numberOfStudent; if (numberOfStudent < 0) { cout << "Please enter a positive number of students " << endl; } } while (numberOfStudent < 0); cout << endl << endl; name = new string[numberOfStudent]; grade = new double* [numberOfStudent];

// Prompting a positive number of tests per students for (int i = 0; i < numberOfStudent; i++) {

{ cin.ignore(); cout << "Enter the student's name : "; getline(cin, name[i]); do { cout << "Enter how many tests " << name[i] << " took :"; cin >> numberOfTest; if (numberOfTest < 0) { cout << "Please enter a positive number of tests : " << endl; }

} while (numberOfTest < 0); }

// Allocating memory for the student's grade grade[i] = new double[numberOfTest];

for (int j = 0; j < numberOfTest; j++)

// Prompting a grade between 0 and 100 do {

cout << "Enter grade #" << j + 1 << " "; cin >> grade[i][j]; if (grade[i][j] < 0 || grade[i][j] > 100) { cout << "Please enter a grade between 0 and 100 "; }

} while (grade[i][j] < 0 || grade[i][j] > 100); } return numberOfStudent; } void displayData(string* name, double** scores, int numberOfStudent) { // Displaying th number of students cout << "You have " << numberOfStudent << " students " << "in the system "; for (int i = 0; i < numberOfStudent; i++) { cout << "Name of student#" << i + 1 << ": " << name[i] << endl; cout << "Grade for student #" << i + 1 << ":"; for (int j = 0; j < numberOfStudent; j++) { cout << scores[i][j] << " "; } cout << endl; } } void cleanHeap(string* name, double** scores, int numberOfStudent) { delete[] name; for (int i = 0; numberOfStudent; i++) { delete[] scores[i]; } delete[] scores; }

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_2

Step: 3

blur-text-image_3

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

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions

Question

When is an alphabetic derivation code useful?

Answered: 1 week ago

Question

3. Define the roles individuals play in a group

Answered: 1 week ago