Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++: Can somebody help me make my inputdata function to return a value! much tha

ID: 3879724 • Letter: C

Question

C++:

Can somebody help me make my inputdata function to return a value! much thanks and here is my code:

#include <iostream>
#include <string>
using namespace std;

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

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;

int numberOfTests[10];
char calgrade[10];


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()
{
int howManyStudents;
    string students[10];
    double** ary = new double*[10];
    for(int i = 0; i < 10; ++i)
        ary[i] = new double[10];
    howManyStudents=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;
    int noOfStudents;
    cout << "How many students do you have in the system? ";
    cin >> noOfStudents;
    cout << endl;

    for(int i = 0; i < noOfStudents; 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;
    }
    return noOfStudents;
}
/// 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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote