Question

In: Computer Science

In C++ The existing code provides number of students who get A grade ( >=91 ),...

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;
}

Solutions

Expert Solution

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


Related Solutions

The reading speed of second grade students is approximately normal, with a mean of 91 words...
The reading speed of second grade students is approximately normal, with a mean of 91 words per minute (wpm) and a standard deviation of 11. A) What is the probability that a single randomly selected student will read more than 97 words per minute? B) What is the probability that a random sample of 12 students will have a mean reading rate of more than 97 words per minute? C) There is a 5% chance that the mean reading speed...
how to code in c# to get the total number of 1's as the numbers are...
how to code in c# to get the total number of 1's as the numbers are added in a Listbox in windows forms
Write a C program that calculates the average grade for a specified number of students from...
Write a C program that calculates the average grade for a specified number of students from each student's test1 and test2 grades. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the test1 grade (grade #1) and test2 grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (test1 and test2). Use a two-dimensional float array to store...
This is the final grade and number of absences for a set of students. Regress grade...
This is the final grade and number of absences for a set of students. Regress grade on absences. Use a 95% confidence level. Give the equation of estimation. Interpret the equation. According to the regression, now much does a tardy (= 1/2 an absence) change your grade? Evaluate the model. What evaluation criterion did you use? Could this be a case of reverse causality? If so, give an example of how the causation could run in the opposite direction. Student...
A biology professor claims that, on the average, 10% of her students get a grade of...
A biology professor claims that, on the average, 10% of her students get a grade of A, 30% get a B, 40% get a C, 10% get a D, and 10% get an F. The grades of a random sample of 100 students were recorded. The following table presents the results. Grade A B C D F Observed 10 34 46 6 4 Test the hypothesis that the grades follow the distribution claimed by the professor. Use the α =...
Grade distribution: A statistics teacher claims that, on the average, 10% of her students get a...
Grade distribution: A statistics teacher claims that, on the average, 10% of her students get a grade of A, 24% get a B, 38% get a C, 18% get a D, and 10% get an F. The grades of a random sample of 100 students were recorded. The following table presents the results. A. Compute the expected frequencies B. List all of the grades which were given more often than expected separate by commas. The grades which were given more...
Please Show Calculations: 1. The table below provides the grade categories along with the number of...
Please Show Calculations: 1. The table below provides the grade categories along with the number of students obtaining a particular grade in the last five years in a difficult English course at a Caribbean University. Grade Frequency A 57 B 44 C 237 D 189 Fail 121 Based on the data, what is the probability that a currently enrolled randomly selected student will obtain an A? a. 0 b. 0.16 c. 0.09 2. The random variable X denotes the number...
Data was collected from students to determine the effects on overall grade average and number of...
Data was collected from students to determine the effects on overall grade average and number of hours spent playing video games per week. Grade   Hours/Week 20 23 96 3 74 6 85 5 67 8 56 14 79 4 65 7 Which is the: -Independent variable?   _______________________ -Dependent variable?   _______________________ -Calculate the coefficient of correlation and interpret the results. -Determine both the coefficient of determination and non-determination and explain the result. -Determine the unrounded regression equation for this data set....
c++ Given the test scores of 7 students are 96, 88, 83, 76, 90, 91, 87....
c++ Given the test scores of 7 students are 96, 88, 83, 76, 90, 91, 87. Write a program that will calculate the average and the standard deviation. ( Standard deviation is given by sqrt[ sum(score-avg)^2/(N-1) ]  )
In C++ and input code using the template below Get a copy of the caseswitch.cpp. The...
In C++ and input code using the template below Get a copy of the caseswitch.cpp. The purpose of the program is to demonstrate how to use Switch statement. Complete the for loop so that the program will ask the user for 6 input grades. Compile and run this C++ program. Use input value A, B, C, D, E, and F. Notice there is no output for B and E. Add cases for them. B is "Good Work." Add a case...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT