Question
C++: Can somebody help me make my inputdata function to return a value! much thanks and here is my code: #include #include using namespace std;
C++:
Can somebody help me make my inputdata function to return a value! much thanks and here is my code:
#include
int numberOfTests[10]; char calgrade[10]; int howManyStudents;
int inputData(string* str, double** grade); char* calcGrade(double** grade, int howManyStudents); void displayData(string* students, double** grade, char* calgrade, int howManyStudents); void cleanHeap(string* students, double** grade, char* calgrade, int howManyStudents);
int main() { string students[10]; double** ary = new double*[10]; for(int i = 0; i < 10; ++i) ary[i] = new double[10]; inputData(students,ary); calcGrade(ary,howManyStudents); displayData(students,ary,calgrade,howManyStudents);
} /// gets user input and sorts it into an array and it gets... /// how many students and there grades and it returns all. int inputData(string*str, double** grade) { double gr;
string students; cout << "How many students do you have in the system? "; cin >> howManyStudents; cout << endl;
for(int i = 0; i < howManyStudents; i++) { cout << "Enter the student's name: "; cin.ignore(); getline(cin,students); label1 : cout << "How many tests " << students << " took: "; cin >> numberOfTests[i];
if( numberOfTests[i] < 0) { cout << "Please enter a positive number of tests taken" << endl; goto label1; } str[i] = students; for(int j = 0; j < numberOfTests[i]; j++) { label2 : cout << "please enter grade #" << j+1 << ": "; cin >> gr;
if( gr < 0 || gr > 100) { cout << "Please enter a grade between 0 and 100 ." << endl; goto label2; } grade[i][j] = gr; } cout << endl; } } /// it calculate the grade for the students that the user entered and it returns the... ///average score for each student. char* calcGrade(double** grade, int howManyStudents) { double average; for(int i = 0; i < howManyStudents; i++) { average = 0; for(int j = 0; j < numberOfTests[i]; j++) average += grade[i][j]; average = average/numberOfTests[i]; if(average >= 90 && average <= 100) calgrade[i] = 'A'; else if(average >= 80 && average <= 89) calgrade[i] = 'B'; else if(average >= 70 && average <= 79) calgrade[i] = 'C'; else if(average >= 60 && average <= 69) calgrade[i] = 'D'; else if(average < 60) calgrade[i] = 'F';
} return calgrade; } /// it displays the average grade for each student and it returns the score for each student. void displayData(string* students, double** grade, char* calgrade, int howManyStudents) { cout << " You have " << howManyStudents << " students in the system. "; for(int i = 0; i < howManyStudents; i++) { cout << " Name of the student #" << i+1 << ": " << students[i]; cout << " Grades for student #" << i+1 << ": "; for(int j = 0; j < numberOfTests[i]; j++) cout << grade[i][j] << " "; cout << " Average of grades for student #" << i+1 << ": " << calgrade[i]; cout << endl; cout << endl; } } /// it erase all the garbage in the heap that we created. it returns nothing. void cleanHeap(string* students, double** grade, char* calgrade, int howManyStudents) { delete[] students; delete[] calgrade; for(int i = 0; i < 10; ++i) delete[] grade[i]; delete[] grade; }
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