In: Computer Science
Create a c++ program with this requirements:
(90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, 0 to 60 is a F)
It would just be based on this template:
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main ( )
{
int ValidScores=0, InvalidScores=0, numA=0, numB=0, numC=0, numD=0, numF=0;
double score, averageScore, highScore, lowScore;
ifstream In;
In.open( );
if ( )
{
cout << "Input file not found. Program ends" << endl;
return -1;
}
In >> score;
while ( )
{
}
if (ValidScores + InvalidScores) == 0)cout << "No data in the input file" << endl;
else if (ValidScores == 0) cout << InvalidScore << " invalid scores entered. No statistics" << endl;
else
{
}
return 0;
}
Here is the complete C++ code, I could not finish the histogram as the question does not show the output of the program and I could not figure out as how it needs to be displayed, could you please add that part, so that i can complete it. Rest all done.!
Thank you.
=======================================================================
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main ( )
{
int ValidScores=0, InvalidScores=0, numA=0, numB=0,
numC=0, numD=0, numF=0;
double score, averageScore, highScore, lowScore;
ifstream In;
In.open("scores.txt"); // update the input file name
here
if (In.bad() || !In.is_open() )
{
cout << "Input file not found. Program ends"
<< endl;
return -1;
}
In >> score;
while ( In)
{
if(score<0 || score>100)
InvalidScores+=1;
else if(score>=90)
numA+=1;
else if(score>=80)
numB+=1;
else if(score>=70)
numC+=1;
else if(score>=60)
numD+=1;
else numF+=1;
if(score<=100 &&
score>=0){
ValidScores+=1;
averageScore +=
score;
if(ValidScores==1) highScore=lowScore=score;
if(highScore<score) highScore = score;
if(lowScore>score) lowScore = score;
}
In >> score;
}
In.close();
if ((ValidScores + InvalidScores) == 0)cout <<
"No data in the input file" << endl;
else if (ValidScores == 0) cout << InvalidScores
<< " invalid scores entered. No statistics" <<
endl;
else {
cout<<"Total Invalid Scores:
"<<InvalidScores<<endl;
cout<<"Total valid Scores:
"<<ValidScores<<endl;
cout<<"Total A Scores:
"<<numA<<endl;
cout<<"Total B Scores:
"<<numB<<endl;
cout<<"Total C Scores:
"<<numC<<endl;
cout<<"Total D Scores:
"<<numD<<endl;
cout<<"Total F Scores:
"<<numF<<endl;
cout<<"Max Score:
"<<highScore<<endl;
cout<<"Low Score:
"<<lowScore<<endl;
cout<<setprecision(2)<<showpoint<<fixed;
cout<<"Average Score:
"<<averageScore/ValidScores<<endl;
}
return 0;
}
-====================================================================