Writea 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), First(As1 dimension array of Doubles), Second (As 1 dimension
array of Doubles), Final (As 1 dimension arrayof Doubles), Total (As 1 dimension array of Doubles), Grad
(As 1 dimension array of Chars)
The Grades are: A for 90’s, B for 80’s, C for70’s, D for 60’s and F for less than 60.
Example of 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
Solution.
//Connectinglibraries
#include<iostream>
#include<iomanip>
usingnamespace std;
constint SIZE = 10;
//Declaringof prototypes functions
voidinputID(int[]);
voidinputMarks(double[]);
doubleClassAverage(double []);
voidGrade(double[],char[]);
voidTotal(double[],double[],double [],double[]);
voidprint(int[] , double[],double[] , double[],double[], char[]);
//Create a main function
intmain()
{
//Declaringvariables
intID[SIZE]={0};
doublemarksFirst[SIZE]={0}, marksSecond[SIZE]={0}, marksFinal[SIZE]={0};
doubletotal[SIZE]={0};
doubleaverage[SIZE]={0};
charcourseGrade[SIZE]="\0";
//Callingfunctions
inputID(ID);
cout<<endl<<"First: "<<endl;
inputMarks(marksFirst);
cout<<endl<<"Second: "<<endl;
inputMarks(marksSecond);
cout<<endl<<"Final: "<<endl;
inputMarks(marksFinal);
//Callingfunction determination Total
Total(marksFirst, marksSecond,marksFinal, total);
//Callingfunction determination Grade
Grade(total,courseGrade);
//Callingfunction print
print(ID, marksFirst, marksSecond,marksFinal, total, courseGrade);
//Stop console
cin.get();
cin.get();
return 0;
}
voidinputID(int ID[])
{
for(int i=0; i<SIZE; i++)
{
cout<<"Enter ID for "<<i+1<< " student: ";
cin>>ID[i];
cout<<endl;
}
}
voidinputMarks(double marks[])
{
for(int i=0; i<SIZE; i++)
{
cout<<"Enter marks for "<<i+1<< " student: "<<endl;
cin>>marks[i];
cout<<endl;
}
}
voidTotal(double marksFirst[],double marksSecond[],doublemarksFinal[],double total[])
{
for(int i=0; i<SIZE; i++)
{
total[i] = marksFirst[i] +marksSecond[i] + marksFinal[i];
}
}
voidGrade(double average[] ,char courseGrade[])
{
for(int i=0; i<SIZE; i++)
{
if(average[i] >= 90)
{
courseGrade[i] = 'A';
}
elseif (average[i] >= 80 && average[i]< 90)
{
courseGrade[i] = 'B';
}
elseif (average[i] >= 70 && average[i]< 80)
{
courseGrade[i] = 'C';
}
elseif (average[i] >= 60 && average[i]< 70)
{
courseGrade[i] = 'D';
}
elseif (average[i] < 60)
{
courseGrade[i] = 'F';
}
}
}
voidprint(int ID[] , doublemarksFirst[], double marksSecond[] , double marksFinal[], doubletotal[], char courseGrade[])
{
cout<<"St_Nm ID First Second Final Total Grade"<<endl;
for(int i=0; i<SIZE; i++)
{
cout<<setw(4)<<i+1<<setw(9)<<ID[i]<<setw(5)<<marksFirst[i]<<setw(7)<<marksSecond[i]<<setw(7)<<marksFinal[i]<<setw(7)<<total[i]<<setw(3)<<courseGrade[i];
cout<<endl;
}
cout<<endl<<endl<<"Class average for 10 students is: "<<ClassAverage(total);
}
doubleClassAverage(double total[])
{
doubleavg=0;
for(int i=0; i<SIZE; i++)
{
avg+=total[i];
}
returnavg/SIZE;
}
Comments
Leave a comment