the program is supposed to read a file of students and grades
and calculate the student average and the course average..
we are reading from 3 diff files, the first has 10 students, the second is empty and the third one student.
so, what i want it to
have the header line: student gpa special notations
porint just once if there is data and then list the students and their gpa with a warning or honors for high and low grades, but if the file has no info print <NO DATA>...
Code:
//Michele D'Addio
//cs201 HW_10/03/02
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<string>
using namespace std;
int main(){
int IDnum;
double gr1, gr2, gr3, gr4;
double average;
int total = 0;
int gr1Count = 1;
int gr2Count = 1;
int gr3Count = 1;
int gr4Count = 1;
double gr1Av;
double gr2Av;
double gr3Av;
double gr4Av;
ifstream infile("A:\\IF1.txt");
if(!infile){
cerr << "Cannot open input file" << endl;
return 1;
}
ofstream outfile("A:\\0F1.txt");
if(!outfile){
cerr << "Cannot open output file" << endl;
return 1;
}
cout << setprecision(3);
cout << setiosflags(ios::fixed | ios::showpoint);
bool flag = true;
while(infile >> IDnum >> gr1 >> gr2 >> gr3 >> gr4){
if(flag == true)
{
cout<<setw(10)<<"\t\t\tSTUDENT"<<setw(10)<<"GPA"<<setw(20)<<"SPECIAL NOTE"<<endl;
flag = false;
}
else{
cout << "<NO DATA>"<< endl;
}
average =(gr1+gr2+gr3+gr4)/4;
if (average <= 1.5)
cout << setw(10) << "\t\t\t" << IDnum << setw(15) << average << setw(15) << "WARNING" << endl;
else if (average >= 3.5)
cout << setw(10) << "\t\t\t" << IDnum << setw(15) << average << setw(15) << "HONORS" << endl;
else
cout << setw(10) << "\t\t\t" << IDnum << setw(15) << average << setw(15) << endl;
total++;
gr1Count++;
gr2Count++;
gr3Count++;
gr4Count++;
}
return 0;
}
thx 4 your help, Bonkey