68 355
Assignments Done
98,7%
Successfully Done
In November 2018

Answer to Question #50221 in C++ for John

Question #50221
Write a program that can enter marks for number of students and calculate their Total and class
average with the following format

The inputs:
ID (As 1 dimension array of Integers),marks(as 2 dimensional array of double), Grad (As 1 dimension
array of Chars)
The Grades are: A for 90’s, B for 80’s, C for 70’s, D for 60’s and F for less than 60.

Use the following functions to find
1. void inputID(int[]);
2. void inputMarks(double [][4]);
3. void Total(double[][4]);
4. void Grade(double[][4],char[]);
5. double ClassAverage(double[][4]);
6. void print(int[],double[][4],char[]);

The output:
St_Nm ID First Second Final Total Grade
1 20071156 15.5 16.5 30.1 62.1 D
2 20071154 15.0 16.5 30.1 62.6 D

Class average for 10 students is: 72.5
Expert's answer
#include <iostream>
using namespace std;
//prototype of functions
void inputID(int[]);
void inputMarks(double [][4]);
void Total(double[][4]);
void Grade(double[][4],char[]);
double ClassAverage(double[][4]);
void print(int[],double[][4],char[]);
//main method
int main()
{
//The inputs:
    //ID (As 1 dimension array of Integers),marks(as 2 dimensional array of double), Grad (As 1 dimension array of Chars)
int IDs[10];
double marks[10][4];
char Grad[10];
inputID(IDs);
inputMarks(marks);
Total(marks);
Grade(marks,Grad);
print(IDs,marks,Grad);
//delay
system("pause");
return 0;
}
//input ID
void inputID(int IDs[]){
for(int i=0;i<10;i++){
cout<<"Enter id for student["<<(i+1)<<"]: ";
cin>>IDs[i];
}
}
//input Marks
void inputMarks(double marks[10][4]){
for(int i=0;i<10;i++){
for(int j=0;j<3;j++){
cout<<"Enter mark "<<(j+1)<<" for student["<<(i+1)<<"]: ";
cin>>marks[i][j];
}
cout<<"\n";
}
}
//Total
void Total(double marks[10][4]){
for(int i=0;i<10;i++){
double total=0;
for(int j=0;j<3;j++){
total+=marks[i][j];
}
marks[i][3]=total;
}
}
//find Grades
void Grade(double marks[10][4],char Grad[10]){
for(int i=0;i<10;i++){
double total=marks[i][3];
//The Grades are: A for 90’s, B for 80’s, C for 70’s, D for 60’s and F for less than 60.
if(total>=90){
Grad[i]='A';
}
if(total>=80 && total<90){
Grad[i]='B';
}
if(total>=70 && total<80){
Grad[i]='C';
}
if(total>=60 && total<70){
Grad[i]='D';
}
if(total<60){
Grad[i]='F';
}
}
}
//calucltae Class Average
double ClassAverage(double marks[][4]){
double total=0;
for(int i=0;i<10;i++){
for(int j=0;j<3;j++){
total+=marks[i][j];
}
}
return total/30;
}
//print
void print(int IDs[10],double marks[10][4],char Grad[10]){
//print header
cout<<"St_Nm ID First Second Final Total Grade\n";
//print result
for(int i=0;i<10;i++){
cout<<IDs[i]<<"\t"<<marks[i][0]<<"\t"<<marks[i][1]<<"\t"<<marks[i][2]<<"\t"<<marks[i][3]<<"\t"<<Grad[i]<<"\n";
}
    cout<<"\nClass average for 10 students is: "<<ClassAverage(marks)<<"\n";
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions