Answer on Question #50356 - Programming, C++
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), First (As 1 dimension array of Doubles), Second (As 1 dimension array of Doubles), Final (As 1 dimension array of 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 for 70'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.
//Connecting libraries
#include <iostream>
#include <iomanip>
using namespace std;
const int SIZE = 10;
//Declaring of prototypes functions
void inputID(int[]);
void inputMarks(double[]);
double ClassAverage(double []);
void Grade(double[], char []);
void Total(double[], double [], double [], double[]);
void print(int[], double[], double[], double[], double[], char[]);
// Create a main function
int main()
{
//Declaring variables
int ID[SIZE]={0};
double marksFirst[SIZE]={0}, marksSecond[SIZE]={0}, marksFinal[SIZE]={0};
double total[SIZE]={0};
double average[SIZE]={0};
char courseGrade[SIZE]={0};
//Calling functions
inputID(ID);
cout<<endl<<"First: "<<endl;
inputMarks(marksFirst);
cout<<endl<<"Second: "<<endl;
inputMarks(marksSecond);
cout<<endl<<"Final: "<<endl;
inputMarks(marksFinal);
//Calling function determination Total
Total(marksFirst, marksSecond, marksFinal, total);
//Calling function determination Grade
Grade(total,courseGrade);
//Calling function print
print(ID, marksFirst, marksSecond, marksFinal, total, courseGrade);
//Stop console
cin.get();
cin.get();
return 0;
}
void inputID(int ID[])
{
for(int i=0; i<SIZE; i++)
{
cout << "Enter ID for student " << i + 1 << ": ";
cin >> ID[i];
}
}
void inputMarks(double marks[])
{
for(int i=0; i<SIZE; i++)
{
cout << "Enter marks for student " << i + 1 << ": ";
cin >> marks[i];
}
}
void Total(double marksFirst[], double marksSecond[], double marksFinal[], double total[])
{
for(int i=0; i<SIZE; i++)
{
total[i] = marksFirst[i] + marksSecond[i] + marksFinal[i];
}
}
void Grade(double total[], char courseGrade[])
{
for(int i=0; i<SIZE; i++)
{
if (total[i] >= 90)
{
courseGrade[i] = 'A';
}
else if (total[i] >= 80)
{
courseGrade[i] = 'B';
}
else if (total[i] >= 70)
{
courseGrade[i] = 'C';
}
else if (total[i] >= 60)
{
courseGrade[i] = 'D';
}
else
{
courseGrade[i] = 'F';
}
}
}
void print(int ID[], double marksFirst[], double marksSecond[], double marksFinal[], double total[], 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] << endl;
}
cout << endl << endl << "Class average for 10 students is: " << ClassAverage(total);
}
double ClassAverage(double total[])
{
double avg = 0;
for (int i = 0; i < SIZE; i++)
{
avg += total[i];
}
return avg/SIZE;
}http://www.AssignmentExpert.com/