THIS IS A C++ CODE. please help need code with all the constraints given below
Your friend has asked you to help them with a project. He needs to calculate his grades, but is finding it difficult to operate a calculator (too hard). Create a program which will accept an unlimited num- ber of scores and calculates the average score. You will also need to prompt for the total points possible.
1)Use object- oriented progrramming techniques
2)Use a dynamically allocated array to handle an unlimited number of test scores.
3)Create a Grade class which holds the test score and the letter grade. Use an assert to protect the letter grade by not allowing negative scores.
4)Create a simple menu: 1 – help, 2 – enter grade, 3 – quit. Use char user_menu; for menu input. If incorrect value entered, display the value in the error message (ie, 4 is not a valid input).
5)When quitting, display a list of scores and average grade with appropriate headings.
6)give average letter grade and average percentage.
7)sort the input given.
8)able to input class names for the grade.
9)use assert to end the program if the user chooses quit in the main menu.
10)using input validation for the main menu and all other places with user input.
Expert Answer
C++ CODE:
#include<iostream>
#include<algorithm>
using namespace std;
class Grade
{
double *scores;
int n;
char letter_grade;
public:
Grade()
{
cout <<“How many test scores would you like to enter? “;
cin >> n;
//Dynamic allocation of array for test scores
scores = new double[n];
}
void EnterGrade()
{
//Get the test scores
cout << “Enter the test scores below.n”;
for (int count = 0; count < n; count++)
{
cout << “Test Score ” << (count + 1) << “: “;
cin >> scores[count];
if(scores[count]<0)
{
cout<<“-VE scores not allowed!”<<endl;
exit(0);
}
}
sort(scores,scores+n);
}
void getLetterGrade()
{
double avg = avgGrade();
/*
Scheme for grading:
Scores Letter_Grade
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F
*/
if(avg>=90)
{
letter_grade=’A’;
}
else
if(avg>=80)
{
letter_grade=’B’;
}
else
if(avg>=70)
{
letter_grade=’C’;
}
else
if(avg>=60)
{
letter_grade=’D’;
}
else
{
letter_grade=’F’;
}
cout<<“AVerage Letter Grade = “<<letter_grade<<endl;
}
double avgGrade()
{
double avg,total=0;
//Calculate the total of the scores
for (int count = 0; count < n; count++)
{
total += scores[count];
}
//Calculate the average test score
avg = total / n;
cout<<“AVerage Percentage = “<<avg<<“%”<<endl;
return avg;
}
void displayScores()
{
for(int i=0;i<n;i++)
{
cout<<scores[i]<<” “;
}
cout<<endl;
}
};
int main()
{
Grade g;
while(1)
{
cout<<“n1 – help, 2 – enter grade, 3 – quit”<<endl;
char user_menu;
cin>>user_menu;
switch(user_menu)
{
case ‘1’:
cout<<“Help menu has othing to offer now”<<endl;
break;
case ‘2’:
g.EnterGrade();
break;
case ‘3’:
cout<<“List of scores : “;
g.displayScores();
g.getLetterGrade();
exit(0);
break;
default:
cout<<user_menu<<” is not a valid input.”<<endl;
}
}
return 0;
}
OUTPUT: