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

You have been asked to implement a program that determines the letter grade for

ID: 3876011 • Letter: Y

Question

You have been asked to implement a program that determines the letter grade for students at a school. At this school, a student’s grade is determined entirely by tests. Because not every student has the same teacher, not every student will have taken the same number of tests. For example, student A may have taken 5 tests while student B has only taken 3 tests.

Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have their name, list of test scores, and an average of all test scores (shown as a letter grade) displayed.

Your program must have at least the following functions:

int inputData(string*&, double**&);

     The inputData function accepts a string pointer and a pointer to a double pointer, both passed by reference. Inside the function, the user will be prompted to enter how many students they will input. For each student, the user will input the student’s name and a list of the student’s test scores. The function will return the number of students that have been entered.

After the function call, the string pointer should point to an array of every student name and the pointer to a double pointer should point to an array where each array entry contains an array of that student’s test scores. Remember that you do not know beforehand how many students will be entered or the number of test scores each student will have.

char* calcGrade(double**, int);

The calcGrade function accepts a pointer to the array of student test scores and the number of students. The function will calculate each student’s average test score, convert the score to a letter grade, and store the letter grade in a dynamically-allocated array. A standard grading scale will be used:

                        90 - 100 A

                        80 - 89   B

                        70 - 79   C

                        60 - 69   D

                        < 60       F

The function will return a pointer to the dynamically-allocated array containing every student’s letter grade.

void displayData(string*, double**, char*, int);

The displayData function accepts a pointer to the array of student names, a pointer to the array of student test scores, a pointer to the array of student letter grades, and the number of students. The function should output the following to the console:

The number of students,

and for each student

the student’s name

a list of the student’s test scores

the average for all test scores, shown as a letter grade

void cleanHeap(string*, double**, char*, int);

The cleanHeap function accepts a pointer to the array of student names, a pointer to the array of student test scores, a pointer to the array of student letter grades, and the number of students. Inside the function, anything that was dynamically-allocated should be cleaned up appropriately.  

Additionally,

You must validate the user’s input

The number of students and the number of test scores must be a positive value

Each test score must be between 0 and 100, inclusive

You must use pointer arithmetic to access array elements instead of using the subscript operator. For example, to access the fifth element of arr, you must write *(arr + 4) instead of arr[4]

Sample Run:

That's what I have so far:

#include <iostream>
#include <string>

using namespace std;

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

int main()
{
int howManyStudents;
string students;
int numberOfTests;
double grade;
cout << "How many students do you have in the system?";
cin >> howManyStudents;
cout << endl;

for(int i = 1; i <= howManyStudents; i++)
{
cout << "Enter the student's name:";
cin.ignore();
getline(cin,students);
cout << "How many tests " << students << " took:";
cin >> numberOfTests;
if( numberOfTests < 0)
cout << "Please enter a positive number of tests taken"<< endl;

for(int j = 1; j <= numberOfTests; j++)
{
cout << "please enter grade #"<< j << ":"<< endl;
cin >> grade;
}
cout << endl;
}

}

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;
int numberOfTests[10];
char calgrade[10];
int howManyStudents;
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 << ":"<< endl;
cin >> gr;
  
if( gr < 0 || gr > 100)
{
cout << "Please enter a grade between o and 100 ."<< endl;
goto label2;
}
grade[i][j]=gr;
}
cout << endl;
}
}
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]='E';
  
}
return calgrade;
  
}
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];
}
}
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;
}


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

}

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