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
|
#include <iostream>
#include <cmath>
#include <string>
//Robert Gillooly
//CSCI 272-02
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
string name;
char lastname;
double hwAve;
double testAve;
double finalScore;
int grade;
double tests[2];
double homework[1];
double part;
} int grade[3];
char getInput ( char Lastname [], char);
void process ( char Lastname [], char );
void display ( char Lastname [], char );
}
int n;
n=getInput ( stu,3 );
if(n<0)
return 1;
process ( stu,n );
display(stu,n);
while (cin.get() != '\n');
}
char getInput ( char Lastname stu[], char)
{ifstream in;
int i,m=0;
string last,first;
in>>first;
while(in)
{in>>last;
stu[m].name=first+" "+last;
for(i=0;i<2;i++)
in>>stu[m].tests[i];
for(i=0;i<3;i++)
in>>stu[m].homework[i];
stu[m].part=100;
m++;
in>>first;
}
in.close();
return m;
}
void process ( SStudent stu[], intn) // send numberof students really stored in the array
// calculate hwAve, testAve, finalScore, and grade
// for each student on the array
{int i,j;
double maxpoints[3]={25,30,40,50,35,35,50};
char grades[6]={'F','D','C','B','A','A'};
double tot;
for(i=0;i<n;i++)
{
stu[i].testAve=(stu[i].tests[0]+stu[i].tests[1])/2.;
tot=0;
for(j=0;j<3;j++)
tot+=stu[i].homework[j]/maxpoints[j]*100.;
stu[i].hwAve=tot/3.;
stu[i].finalScore=stu[i].testAve*.6+stu[i].hwAve*.3+stu[i].part*.1;
j=stu[i].finalScore/3.-9;
if(j<0)
j=0;
stu[i].grade=grades[j];
}
}
void display ( const SStudent stu[], int n) // send number ofstudents really stored in array
// do grade analysis and display result
// open output file should be done in the function
{int i,a=0,b=0,c=0,d=0,f=0;
out<<fixed<<showpoint<<setprecision(1);
out<<"STUDENTID HWAVE TEST AVE FINALSCORE GRADE\n";
for(i=0;i<n;i++)
{
out<<setw(15)<<left<<stu[i].name<<setw(13)<<right<<stu[i].hwAve<<setw(15);
out<<stu[i].testAve<<setw(20)<<stu[i].finalScore<<setw(22)<<stu[i].grade<<endl;
if(stu[i].grade=='A')
a++;
else if(stu[i].grade=='B')
b++;
else if(stu[i].grade=='C')
c++;
else if(stu[i].grade=='D')
d++;
else f++;
}
out<<endl;
out<<"Number of A's: "<<a<<endl;
out<<"Number of B's: "<<b<<endl;
out<<"Number of C's: "<<c<<endl;
out<<"Number of D's: "<<d<<endl;
out<<"Number of F's: "<<f<<endl;
out.close();
}
system("Pause");
return 0;
}
|