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

THIS IS A C++ CODE. Your friend has asked you to help them with a project. He ne

ID: 2247151 • Letter: T

Question

THIS IS A C++ CODE.

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 number of scores and calculates the average score. You will also need to prompt for the total points possible.

Use a dynamically allocated array to handle an unlimited number of test scores.

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.

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

When quitting, display the sorted list of scores and average with appropriate headings.

Constraints.

Comment your code with the constraint number above the bulk of the code implementing the constraint - so I can find it. Like this:

// Constraint 1 - No negative numbers.
Just comment the bulk of the code if code for that constraint ap-

pears in several places.

1. Do not accept negative numbers for test scores.
2. Use new() and delete() to properly handle your array. 3. Write a text file containing the grade summary.
4. Use Object Oriented Programming techniques.

***EDIT** The grade is general A-F scale.

90-100 A

80-89 B

70-79 C

60-69 D

<59 F

Explanation / Answer

For array,inspite of dynamic allocation you have to input size of array first. But if you want to have unlimited number of test score and grafe without inputting fixed size,you have to use vector data structure in place of array.

Below is solution for arrays

#include<iostream>

#include<algorithm>

#include<fstream>

#include<string.h>

using namespace std;

class Grade//creating Grade Class

{

int score;

string grade;

public:

void input(int input_score)//taking of input scores and calculating Grades

{

score=input_score;

grade_calculation();

}

string get_grade()//getting the grade for object

{

return grade;

}

int get_score()//getting the score for object

{

return score;

}

void grade_calculation()//grade calculation according to score

{

if(score<59)

grade="F";

else if(60<=score && score<=69)

grade="D";

else if(70<=score && score<=79)

grade="C";

else if(80<=score && score<=89)

grade="B";

else if(90<=score && score<=100)

grade="A";

}

};

int score_sort(Grade g1,Grade g2)//sort function to sort grades based on scores

{

return g1.get_score()<g2.get_score();

}

int main()

{

int n;

cout<<"Enter the Number of Test Scores ";

cin>>n;

Grade *g;

g=new Grade[n]; //using new function for dynamic allocation

char user_menu;

int j=0,test_score;//j=number of test score entered by user should be less than n

while(user_menu!='3')

{

cout<<"1 - Help 2 - Enter Score 3 - Quit ";

cin>>user_menu;

if(user_menu=='1')

cout<<"Help Section ";

else if(user_menu=='2')

{

cout<<"Enter the Test Score ";

cin>>test_score;

if(test_score<0 || test_score>100) // checking of input score is non negative and less than 100

cout<<"Invalid Score ";

else

{

g[j].input(test_score);

j++;

}

}

else if(user_menu!='1' && user_menu!='2' && user_menu!='3')//checking for valid input menu choice

{

cout<<"Invalid Input ";

}

if(j==n)

{

cout<<"Number of Input Scores are Equal to Number of Test Scores ";

break;

}

}

sort(g,g+j,score_sort); //sorting the grade array based on scores

float average=0;

int i;

for(i=0;i<j;i++) //calculation of grade score average

{

average=average+ g[i].get_score();

}

average=average/j;

cout<<" Sorted List of Scores And Grades ";

for(i=0;i<j;i++)

cout<<g[i].get_score()<<" "<<g[i].get_grade()<<" ";

cout<<" Average Score - "<<average<<" ";

ofstream summary; //creating file variable

summary.open("grade_summary.txt"); //creating text file to store results

summary<<" Sorted List of Scores And Grades ";

for(i=0;i<j;i++)

{

summary<<g[i].get_score()<<" "; //writing grade and score to file

summary<<g[i].get_grade()<<" ";

}

summary<<" Average Score - "<<average<<" ";

summary.close(); // closing the file

delete g; //deleting the dynamice allocated array space

return 0;

}