1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#define MAX 100
using namespace std;
/**************PROTOTYPES*******************/
void intro(void);
int read(float scores[],float totalscore,int numgrades, int max);
float findhigh(float scores[], int limit);
float findlow(float scores[], int limit);
float findavg(float totalscore, int numgrades);
void gradescale(float scores[], int gradeA, int gradeB, int gradeC, int gradeD, int gradeF, int limit);
void print(float high, float low, float avg, int numgrades,int gradeA, int gradeB, int gradeC, int gradeD, int gradeF,int limit);
/*************MAIN***************************/
int main()
{
float scores[MAX], high, low, avg, totalscore=0;
int limit = 0, numgrades = 0, gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;
string grades[MAX];
intro();
limit=read(scores,totalscore,numgrades, MAX);
if (limit > 0)
{
high = findhigh(scores,limit);
low = findlow (scores,limit);
avg = findavg (totalscore,numgrades);
gradescale(scores, gradeA, gradeB, gradeC, gradeD ,gradeF,limit);
print( high, low, avg, numgrades,gradeA,gradeB, gradeC, gradeD, gradeF,limit);
}
else
cout<<endl<<"No data in file."<<endl;
}
/******************ENDOFMAIN************************/
void intro (void)
{
cout << setw(43) << "Assignment 6\n";
cout << "=============================================================================="<<endl;
}
int read (float scores[],float totalscore,int numgrades, int max)
{
ifstream fin;
string filename;
int i=0;
cout << "Enter file name:";
getline (cin, filename);
fin.open(filename.c_str());
if ( fin.fail() )
cout <<endl <<"Bad File Name" <<endl;
while( !fin.eof())
{
for ( i = 0 ; i < max ; i++ )
{
fin >> scores[i];
numgrades++;
totalscore+=scores[i];
}
}
fin.close();
return (i);
}
float findHigh(float scores[], int limit)
{
float maximum = 0;
int i=0;
for(int i = 1; i < limit; i++)
{
if(scores[i] > maximum)
maximum = scores[i];
}
return (maximum);
}
float findlow(float scores[], int limit)
{
float minimum = 0; int i =0;
for(int i = 1; i<limit; i++)
{
if(scores[i] < minimum)
minimum = scores[i];
}
return (minimum);
}
float findavg(float totalscore, int numgrades)
{
float classavg = 0;
classavg= totalscore/numgrades;
return(classavg);
}
void gradescale(float scores[], int gradeA, int gradeB, int gradeC, int gradeD, int gradeF,int limit)
{
int i=0;
for ( i = 0 ; i < limit ; i++ )
{
if (scores[i] >= 90)
gradeA++;
if (scores[i] >= 80 && scores[i] < 90)
gradeB++;
if (scores[i] >=65 && scores[i] <80)
gradeC++;
if (scores[i] >=50 && scores[i] <65)
gradeD++;
else
gradeF++;
}
}
void print(float high, float low, float avg, int numgrades, int gradeA, int gradeB, int gradeC, int gradeD, int gradeF,int limit)
{
ofstream fout;
string fname;
cout << "Enter output file name:";
getline (cin, fname);
fout.open(fname.c_str());
if (fout.fail())
cout<<endl<<"could not creat file.";
fout<<fixed<<setprecision(2)<<left<<setw(20);
fout << "\t\t\t\tCLASS STATISTICS"<<endl;
fout << "Max score:" << high <<endl;
fout << "Min score:" << low <<endl;
fout << "Number of scores:" << numgrades <<endl;
cout<<fixed<<setprecision(2)<<left<<setw(20);
cout << "\t\t\t\tCLASS STATISTICS"<<endl;
cout << "Max score:" << high <<endl;
cout << "Min score:" << low <<endl;
cout << "Number of scores:" << numgrades <<endl;
cout<<endl<<"\t\t\t\tDistribution of Grades"<<endl;
cout<<"A's"<<setfill ('*')<<setw (gradeA)<<"("<<gradeA<<")"<<endl;
cout<<"B's"<<setfill ('*')<<setw (gradeB)<<"("<<gradeB<<")"<<endl;
cout<<"C's"<<setfill ('*')<<setw (gradeC)<<"("<<gradeC<<")"<<endl;
cout<<"D's"<<setfill ('*')<<setw (gradeD)<<"("<<gradeD<<")"<<endl;
cout<<"F's"<<setfill ('*')<<setw (gradeF)<<"("<<gradeF<<")"<<endl;
fout<<endl<<"\t\t\t\tDistribution of Grades"<<endl;
fout<<"A's"<<setfill ('*')<<setw (gradeA)<<"("<<gradeA<<")"<<endl;
fout<<"B's"<<setfill ('*')<<setw (gradeB)<<"("<<gradeB<<")"<<endl;
fout<<"C's"<<setfill ('*')<<setw (gradeC)<<"("<<gradeC<<")"<<endl;
fout<<"D's"<<setfill ('*')<<setw (gradeD)<<"("<<gradeD<<")"<<endl;
fout<<"F's"<<setfill ('*')<<setw (gradeF)<<"("<<gradeF<<")"<<endl;
fout.close();
}
|