In: Computer Science
In C++
The existing code provides number of students who get A grade ( >=91 ), their average points. You may need to provide code for other students who got B, C, D and F grades with grade >= 81, 71, 61 and below 61 respectively. You are asked to write a print function to display / print name of group ( such as Grade A group) , number, and average grade. in the main function, you just make the function call for each group of students.
You may be asked to write a function to translate average point of class to letter grade. For example, when average point of class is 82.45, the overall letter grade of class is B
You may be asked to provide statistics how many input, and how many errors are there ?
Below is code that needs to be updated with above information
#include <iostream> #include <string> #include <iomanip> using namespace std; int main() { const int MAX_GRADE = 100; const int A_GRADE = 91; // Grad A's points int countGradeA = 0; // number of Grade A students double totalGradeA = 0.; // total points of Grade A students int counter = 0; // number of students int grade; // student's grade; must be positive and <= MAX_GRADE double average; // grade average double total = 0; // total grades while (true) { cout << "Enter grade, Ctr-Z (Windows) / Ctr-D ( Unix) to end : ", cin >> grade; if ( cin.fail()) { if ( cin.eof()) { cout << "Finish entering data !" << endl; break; } else { string error; cin.clear(); cin >> error; cout << error << " Wrong data type " << endl; } } else if ( grade < 0 || grade > MAX_GRADE) { cout << grade << " Wrong data, must be positive and <= " << MAX_GRADE << endl; } else { total += grade; counter++; cout << grade << endl; if ( grade >= A_GRADE) { countGradeA++; totalGradeA += grade; } } } // compute an average of grades cout << fixed << setprecision(2); if ( counter > 0) { average = total / counter; cout << setw(20) << "Total students: " << setw(10) << counter << setw(10) << "Average: " << setw(10) << average << endl; } else { cout << "No grade entered " << endl; } if (countGradeA > 0) { cout << setw(20) << "Grade A Students: " << setw(10) << countGradeA << setw(10) << " Average: " << setw(10) << totalGradeA / countGradeA << endl; } return 0; }
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
string letterGrade(double average);
int main()
{
const int MAX_GRADE = 100;
const int A_GRADE = 91; // Grad A's points
const int B_GRADE = 81;
const int C_GRADE = 71;
const int D_GRADE = 61;
int countGradeA = 0; // number of Grade A students
double totalGradeA = 0.; // total points of Grade A students
int countGradeB = 0; // number of Grade A students
double totalGradeB = 0.; // total points of Grade A students
int countGradeC = 0; // number of Grade A students
double totalGradeC = 0.; // total points of Grade A students
int countGradeD = 0; // number of Grade A students
double totalGradeD = 0.; // total points of Grade A students
int countGradeF = 0; // number of Grade A students
double totalGradeF = 0.; // total points of Grade A students
int counter = 0; // number of students
int grade; // student's grade; must be positive and <=
MAX_GRADE
double average; // grade average
double total = 0; // total grades
while (true)
{
cout << "Enter grade, Ctr-Z (Windows) / Ctr-D ( Unix) to end : ", cin >> grade;
if (cin.fail())
{
if (cin.eof())
{
cout << "Finish entering data !" << endl;
break;
}
else
{
string error;
cin.clear();
cin >> error;
cout << error << " Wrong data type " <<
endl;
}
}
else if (grade < 0 || grade > MAX_GRADE)
{
cout << grade << " Wrong data, must be positive and
<= " << MAX_GRADE << endl;
}
else
{
total += grade;
counter++;
cout << grade << endl;
if (grade >= A_GRADE)
{
countGradeA++;
totalGradeA += grade;
}
else if (grade >= B_GRADE)
{
countGradeB++;
totalGradeB += grade;
}
else if (grade >= C_GRADE)
{
countGradeC++;
totalGradeC += grade;
}
else if (grade >= D_GRADE)
{
countGradeD++;
totalGradeD += grade;
}
else if (grade <D_GRADE)
{
countGradeF++;
totalGradeF += grade;
}
}
}
// compute an average of grades
cout << fixed << setprecision(2);
if (counter > 0)
{
string gradeLetter;
average = total / counter;
gradeLetter= letterGrade(average);
cout << setw(20) << "Total students: " <<
setw(10) << counter << setw(10)
<< "Average: " << setw(10) << average <<
endl;
cout<<"Overall Grade Letter
:"<<gradeLetter<<endl;
}
else
{
cout << "No grade entered " << endl;
}
if (countGradeA > 0)
{
cout << setw(20) << "Grade A Students: " <<
setw(10) << countGradeA << setw(10)
<< " Average: " << setw(10) << totalGradeA /
countGradeA << endl;
}
if (countGradeB > 0)
{
cout << setw(20) << "Grade B Students: " <<
setw(10) << countGradeB << setw(10)
<< " Average: " << setw(10) << totalGradeB /
countGradeB << endl;
}
if (countGradeC > 0)
{
cout << setw(20) << "Grade C Students: " <<
setw(10) << countGradeC << setw(10)
<< " Average: " << setw(10) << totalGradeC /
countGradeC << endl;
}
if (countGradeD > 0)
{
cout << setw(20) << "Grade D Students: " <<
setw(10) << countGradeD << setw(10)
<< " Average: " << setw(10) << totalGradeD /
countGradeD << endl;
}
if (countGradeF > 0)
{
cout << setw(20) << "Grade F Students: " <<
setw(10) << countGradeF << setw(10)
<< " Average: " << setw(10) << totalGradeF /
countGradeF << endl;
}
return 0;
}
string letterGrade(double average)
{
string gradeLetter;
if (average >= 90 && average<=100)
gradeLetter = 'A';
else if (average >= 80 && average < 90)
gradeLetter = 'B';
else if (average >= 70 && average < 80)
gradeLetter = 'C';
else if (average >= 60 && average < 70)
gradeLetter = 'D';
else if (average < 60)
gradeLetter = 'F';
return gradeLetter;
}
=====================================
Output:
===================================Thank You