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
|
#include <fstream>
#include <iostream>
using namespace std;
ifstream infile;
ofstream outfile;
void grades(int&,int&,int&,int&); // Grades from the input file
int myavg(int,int,int); // Calculates the Average of the 3 grades
void letters(int,int,int&); // Letter Grade: (P)ass or (F)ail
void heading(void); // Heading of the table
int main()
{
int x,y,z,w,average,studentid,letter;
heading();
cin >> studentid; // Entering the student's ID
while (studentid >= 0){
grades(x,y,z,w);
letters(average,x,y);
average = myavg(y,z,w);
outfile << "\t" << studentid << "\t\t\t" << y << " " << z << " " << w << "\t"
<< " " << average << endl;
cin >> studentid;
}
system("PAUSE");
return 0;
}
void grades(int &a,int &b,int &c, int &d)// Grades from the input file
{
infile.open("grades.txt");
while(!infile.eof()){
infile >> a >> b >> c;
cout << a << " " << b << " " << c << endl;
}
return;
}
int myavg(int a, int b, int c)// Average of the 3 grades
{
int average;
average = (a + b + c)/ 3;
cout << average << endl;
return average;
}
void letters(int a, int b, int& average)// Letter Grade: (P)ass or (F)ail
{
if (average >= 70)
outfile << "\t\t\t\t\t\t\t\t " << "P" << endl;
else
outfile << "\t\t\t\t\t\t\t\t " << "F" << endl;
}
void heading(void) // Heading of the table
{
outfile.open("Table.txt");
outfile << "\t\t\t\t\tStudent Information" << endl << endl;
outfile << "\tStudent ID\t\tGrade\t\tAverage\t\tLetter Grade" << endl<< endl;
return;
}
|