Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here you\'re going to extend your program to also provide the grade distribution

ID: 3756460 • Letter: H

Question

Here you're going to extend your program to also provide the grade distribution of the scores, meaning the number of A's, B's, C's, D's and F's assuming a traditional 90-80-70-60 scale (i.e A is 90+, B is 80-89, etc.). For example, suppose the file "scores.txt" contains the following values: 92 100 68 42 67 When the program runs, the user will provide two inputs: scores.txt 10 The first input is to determine which file to read. The second input is to determine the maximum amount of asterisks that can be printed on any line of the grade distribution histogram (see below). The program then opens the file, imputs the values, counts, computes the average, and outputs the following: cabox@box-codeanywhere:-/workspace/projectss g+ nain.cpp cabox@box-codeanywhere:+/workspace/project55s -/a.out scores.txt 18 # students: 8 # zero: 2 # with 106: 1 Average: 74.8333 Grade Distribution: B: : D: F:99 The O's are not incladed in the average, bat are couniod as F grades. In gemeral, assume the input file contains I or more valid istegers in the range 0 100, inclusive As another example, let's look at one of the larger inpat files, say"esamsst".In this case, the usage should look like this caboxjbox-codeanywhere: /workspace/projectss /a.out 5e a students: 256 zeroi 7 with 100: 36 Average: 82.8153 Grade Distribution: Please notice that when there are more grades than what was inputed as the second input (5o, i his cane), there are only that many (50, in this case) asierisks printed, follkowed byand the number of total counted scores in that grade catogory If the second input is 0, no grade distribution should be printedtThe last sis lines in the PIC.cOLLAGE

Explanation / Answer

If you have any doutbs, please give me comment...

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;
void print_histogram(int n, int max);
int main()
{
string filename;
int max;
cin >> filename >> max;
ifstream in;
in.open(filename.c_str());
if (in.fail())
{
cout << "Error: unable to open file!" << endl;
return 0;
}
int no_students(0), zero(0), score100(0), countA(0), countB(0), countC(0), countD(0), countF(0), score;
double average = 0.0;
while (!in.eof())
{
in >> score;
if(in.fail())
break;
no_students++;
if(score==0)
zero++;
else if(score==100)
score100++;
average += score;
if (score >= 90)
countA++;
else if (score >= 80)
countB++;
else if (score >= 70)
countC++;
else if (score >= 60)
countD++;
else
countF++;
}
in.close();
average /= (no_students-zero);
cout<<"# students: "<<no_students<<endl;
cout<<"# zero: "<<zero<<endl;
cout<<"# with 100: "<<score100<<endl;
cout<<"Average: "<<average<<endl;
cout<<"Grade Distribution:"<<endl;
cout<<"A: ";
print_histogram(countA, max);
cout<<"B: ";
print_histogram(countB, max);
cout<<"C: ";
print_histogram(countC, max);
cout<<"D: ";
print_histogram(countD, max);
cout<<"F: ";
print_histogram(countF, max);

return 0;
}

void print_histogram(int n, int max){
for(int i=0; i<n && i<max; i++){
cout<<"*";
}
if(n>max){
cout<<"..."<<n;
}
cout<<endl;
}