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
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
#define N 51
struct gradebook_t { //structure definition
string IdNum;
string lastname;
string firstname;
char MI;
int q1;
int q2;
int midex;
int finex;
} gradebook [N];
void printgrade (gradebook_t gbook);
int main (){
ifstream myfile;
int i, x;
myfile.open("LAB08.in");
while(!myfile.eof){ //getting the data from the file
getline (myfile,i);
for (x=0; x<i; x++)
{
getline(myfile,gradebook[x].IdNum);
getline(myfile,gradebook[x].lastname);
getline(myfile,gradebook[x].firstname);
getline(myfile,gradebook[x].MI);
getline(myfile,gradebook[x].q1);
getline(myfile,gradebook[x].q2);
getline(myfile,gradebook[x].midex);
getline(myfile,gradebook[x].finex);
cout << "\n";
}
}
for (x=0; x<i; x++){ //standard given grade policy
if ((gradebook[x].q1 <= 10) && (gradebook[x].q2 <= 10) && (gradebook[x].midex <= 100) && (gradebook[x].finex) <= 100){
printgrade (gradebook[x]);
}
else
cout << "invalid grades for " << gradebook[x].IdNum << "\n\n";
}
myfile.close();
return 0;
}
void printgrade (gradebook_t gbook){
double qper, midper, finper, fgrade; //stores the quiz, midterm and final exam percentage
int ng;
qper = ((gbook.q1+gbook.q2) / 20.0) * 25.0; //computes for the average
midper = (gbook.midex / 100.0) * 25.0;
finper = (gbook.finex / 100.0) * 50.0;
fgrade = qper+midper+finper;
ng = static_cast<int>(fgrade + 0.5);
cout << "ID Number: " << gbook.IdNum; //displays info and computed grades
cout << "\n" << "Name: " << gbook.lastname << ", " << gbook.firstname << " " << gbook.MI << ".";
cout << "\n" << "Q1: " << gbook.q1;
cout << "\n" << "Q2: " << gbook.q2;
cout << "\n" << "ME: " << gbook.midex;
cout << "\n" << "FE: " << gbook.finex;
cout << "\n" << "NG: " << ng;
cout << "\n" << "LG: ";
if (fgrade >= 90.0)
cout << "A";
if ((fgrade >= 80.0) && (fgrade < 90.0))
cout << "B";
if ((fgrade >= 70.0) && (fgrade < 80.0))
cout << "C";
if ((fgrade >= 60.0) && (fgrade < 70.0))
cout << "D";
if (fgrade < 60.0)
cout << "F";
cout << "\n\n";
}
|