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

using at least 2-D Arrays and at least 2 functions Create a database for up to 2

ID: 3537182 • Letter: U

Question

using at least 2-D Arrays and at least 2 functions


Create a database for up to 200 students quiz scores during a semester.

There are 5 quizs total.


averages of the individual quizes (menu option 2)

User must enter quiz scores first or get error message telling them to do so.

user then chooses a quiz and the program computes the average of all grades of all students for that quiz.


Class Average (menu option 3)

must check that user has input scores first

sum the students averages and divide them by the number of students

OR sum up the quiz averages and divide them by 6.


Calculate individual student Letter Grade (menu option 4)

using a 10 point grading scale (A+=95,A-=90,B+=85,B-=80,C+=75,C-=70, Else=Failed)


Should use a menu with 4 options, entering 0 to quit.

User must enter data to the first option (number of students in class, then students quiz scores for all 5 quizes.)

before they are able to proceed with other options.

Explanation / Answer

#include<iostream>

using namespace std;


int menu()

{

int option=1;

while(1)

{

cout<<" Choose one of the options: ";

cout<<"1.enter students quiz scores ";

cout<<"2.calculate averages of the individual quizes ";

cout<<"3.calculate class avergae score ";

cout<<"4.calculate individual student Letter Grade ";

cout<<"5. quit ";

cout<<"option: ";

cin>>option;


if(option<1 && option>5)

cout<<"invalid option ";

else

break;

}


return option;




}



int getQuizScores(int*** scores)

{

int n;

cout<<" Enter the number of students in class: ";

cin>>n;


int **s=NULL;


s=new int*[n];

for(int i=0;i<n;i++)

s[i]=new int[5];


cout<<" Enter 5 quiz scores for each "<<n<<" students ";

for(int i=0;i<n;i++)

{

cout<<"-----student "<<(i+1)<<"----- ";

for(int j=0;j<5;j++)

{

cout<<"quize "<<(j+1)<<" : ";

cin>>s[i][j];


}


}


*scores=s;

return n;


}


double calculateClassAverage(int** scores,int n)

{

if(scores==NULL)

{

cout<<" Enter quiz scores first using option 1 ";

return -1.0;

}

double average=0.0;

for(int i=0;i<n;i++)

for(int j=0;j<5;j++)

average+=scores[i][j];


return average/(5*n);

}


double calculateIndividualQuizesAverage(int** scores,int n)

{

int quiz;

double average=0.0;

if(scores==NULL)

{

cout<<" Enter quiz scores first using option 1 ";

return -1.0;

}


cout<<" Enter the quiz(1-5): ";

cin>>quiz;


for(int i=0;i<n;i++)

average+=scores[i][quiz-1];


return average/n;

}


void showStudentsletterGrade(int** scores,int n)

{


if(scores==NULL)

{

cout<<" Enter quiz scores first using option 1 ";

return ;

}

char* grade[]={"A+","A-","B+","B-","C+","C-","Failed"};

double average=0.0;

for(int i=0;i<n;i++)

{

cout<<" Student "<<i+1<<" : ";

average=0.0;

for(int j=0;j<5;j++)

average+=scores[i][j];


average/=5.0;


if(average>=95.0)

cout<<"A+ ";

else if (average>=90.0 && average<95.0)

cout<<"A- ";

else if (average>=85.0&& average<90.0)

cout<<"B+ ";

else if (average>=80.0&& average<85.0)

cout<<"B- ";

else if (average>=75.0&& average<80.0)

cout<<"C+ ";

else if (average>=70.0&& average<75.0)

cout<<"C- ";

else

cout<<"Failed ";



}


}


int main()

{

int** scores=NULL;

int n=0;

int option;

double average;


while(1)

{

option=menu();

if(option==5)break;


if(option==1)

n=getQuizScores(&scores);

else if(option==2)

{

average=calculateClassAverage(scores,n);

if(average!=-1.0)

cout<<" Avergae: "<<average<<endl;

}

else if(option==3)

{

average=calculateIndividualQuizesAverage(scores,n);

if(average!=-1.0)

cout<<" Quiz average: "<<average<<endl;

}

else

showStudentsletterGrade(scores,n);

}


return 0;


}