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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
#include <cstdlib>
using namespace std;
void Sort(int ID[], string NAME[], double GRADES[], int size );
void FindHigh(string NAME[], double GRADES[]);
void FindLow(string NAME[], double GRADES[]);
void Stats(int ID[], string NAME[], double GRADES[], int size );
int main()
{
int i,x,m,n,M,size=10;
int ID[]={1,2,3,4,5,6,7,8,9,10};
double GRADES[]={99.32, 100, 83.67, 73.67, 62.12, 35.22, 83.66, 23.11, 99.25, 72.86};
string NAME[]={"Tom","Mary","John","Jerry","Susan","David","Andy","Ken","Kathy","Frank"},ID,NAME,GRADE;
double maxVal,minVal,mean,median,variance,stdev,sum,N;
char selection;
ofstream outfile;
ifstream infile;
outfile.open("Bonus.dat");
infile>>S1>>S2>>S3;
cout<<setw(5)<<S1<<setw(10)<<S2<<setw(10)<<S3<<endl;
for(i=0;i<ID[10];i++)
{
infile>>ID>>NAME>>GRADE;
cout<<setw(5)<<ID[i]<<setw(10)<<NAME[i]<<setw(10)<<GRADE[i]<<endl;
}
infile.close();
for(int m=0; m<N;m++)
{
cout<<setw(5)<<id[m]<<setw(10)<<name[m]<<setw(10)<<grades[m]<<endl;
}
do
{
cout << "MENU\n\n"
<< "1. Sort the grade in a descending order. \n"
<< "2. Find the highest score of the class. \n"
<< "3. Find the lowest score of the class. \n"
<< "4. Calculate the mean, median, variance and standard deviation for the class. \n"
<< "5. Quit\n\n"
<< "SELECTION:\n\n ";
selection = cin.get();
switch(selection)
{
case '\n': break;
case '1': Sort(ID,NAME,GRADES,size); break;
case '2': FindHigh(NAME,GRADES); break;
case '3': FindLow(NAME,GRADE); break;
case '4': Stats(ID,NAME,GRADES,size); break;
default: cout << '\a';
}
}
while( selection != '5' );
{
system("pause");
return 0;
}
}
void Sort( int ID[], string NAME[], double GRADES[], int size )
{
system("cls");
int i,x,m,size=10;
int ID[]={1,2,3,4,5,6,7,8,9,10};
double GRADES[]={99.32, 100, 83.67, 73.67, 62.12, 35.22, 83.66, 23.11, 99.25, 72.86};
string NAME[]={"Tom","Mary","John","Jerry","Susan","David","Andy","Ken","Kathy","Frank"},ID,NAME,GRADE;
double tempg;
int tempi;
string temps;
for (int x=0;x<size-1;x++)
{
for(int i=x+1;i<size;i++)
{
if (GRADES[i]>GRADES[x])
{
tempi=ID[x];
ID[x]=ID[i];
ID[i]=tempi;
tempg=GRADES[x];
GRADES[x]=GRADES[i];
GRADES[i]=tempg;
temps=NAME[x];
NAME[x]=NAME[i];
NAME[i]=temps;
}
}
}
for(int m=0; m<size;m++)
{
cout<<setw(5)<<ID[m]<<setw(10)<<NAME[m]<<setw(10)<<GRADES[m]<<endl;
}
return;
}
void FindHigh(string NAME[], double GRADES[]);
{
system("cls");
double GRADES[]={99.32, 100, 83.67, 73.67, 62.12, 35.22, 83.66, 23.11, 99.25, 72.86};
string NAME[]={"Tom","Mary","John","Jerry","Susan","David","Andy","Ken","Kathy","Frank"},ID,NAME,GRADE;
for (int M=1;M<size-1;++M)
{
if (GRADES[M]>maxVal)
maxVal=GRADES[M];
}
cout<<maxVal;
cout.precision(2);
return;
}
void FindLow(string NAME[], double GRADES[]);
{
system("cls");
int i,x,m,size=10;
double GRADES[]={99.32, 100, 83.67, 73.67, 62.12, 35.22, 83.66, 23.11, 99.25, 72.86};
string NAME[]={"Tom","Mary","John","Jerry","Susan","David","Andy","Ken","Kathy","Frank"},ID,NAME,GRADE;
double maxVal,minVal,mean,median,variance,stdev,sum,N;
minVal=grades[0];
for (int m=1;m>size-1;m--)
{
if (grades[m]<minVal)
minVal=grades[m];
}
cout<<minVal;
cout.precision(2);
return;
}
void Stats(int ID[], string NAME[], double GRADES[], int size )
{
system("cls");
int i,x,m,size=10;
double GRADES[]={99.32, 100, 83.67, 73.67, 62.12, 35.22, 83.66, 23.11, 99.25, 72.86};
string NAME[]={"Tom","Mary","John","Jerry","Susan","David","Andy","Ken","Kathy","Frank"},ID,NAME,GRADE;
double maxVal,minVal,mean,median,variance,stdev,sum,N;
for (int i=0;i<10;++i)
{
sum+=grades[i];
mean=sum/10;
}
cout<<"Mean: "<<mean<<endl;
Sort(ID, NAME, GRADES, size);
median=(GRADES[4]+GRADES[5])/2;
cout<<"Median: "<<median<<endl;
variance=_sum/(i-1);
cout<<"Variance: "<<variance<<endl;
stdev=sqrt(((pow(sum+2))-((1/sum)*(pow(sum+2))))/(sum-1));
cout<<"Standard Deviation: "<<stdev<<endl;
system("pause");
}
|