#include<fstream> #include<iomanip> #include<string> #include<iostream> #include<cmath> using namespace std; int main() { int stunum;//# of students in the class string stuname;// Name of the student float Test1;//score for test 1 float Test2;//score for test 2 float Midterm;//score for midterm float Final;//score for final float Term;//score for term project float Grade; float NumA=0; float NumB=0; float NumC=0; float NumF=0; ifstream inFile; ofstream outFile; inFile.open ("ClassData.dat"); outFile.open ("ClassOutput"); inFile>>stunum;//reads in the # of students in the class outFile<<"The # of students in the class:"<<stunum<<endl; for (int j=0; j<stunum; j++); { while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term); } outFile<<setw(10)<<"Name"<<setw(10)<<"Test1"<<setw(10)<<"Test2"<<setw(10)<<"Midterm"<<setw(10)<<"Final"<<setw(12)<<"Project"<<setw(14)<<"Total Grade"<<setw(16)<<"Letter Grade"<<endl; Grade= Test1+Test2+Midterm+Final+Term; { { outFile<<setw(10)<<stuname<<setw(10)<<Test1<<setw(10)<<Test2<<setw(10)<<Midterm<<setw(10)<<Final<<setw(10)<<Term<<setw(10)<<Grade<<endl; { float Grade= Test1+Test2+Midterm+Final+Term; if(Grade>=90) { outFile<<"A "; NumA++; } else if (Grade>=80) { outFile<<"B "; NumB++; } else if (Grade>=70) { outFile<<"C "; NumC++; } else if (Grade<70) { outFile<<"F "; NumF++; outFile<<endl; } inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term; } outFile<<"The # of A's:"<<NumA<<endl; outFile<<"The # of B's:"<<NumB<<endl; outFile<<"The # of C's:"<<NumC<<endl; outFile<<"The # of F's:"<<NumF<<endl; } } inFile.close(); outFile.close(); return 0; }
Thanks for the assistance:
If I were to do the following, why does it only show the information for Kenez from my inFile?
10
Gayle 75 82 62 61 59
Brown 79 100 17 19 89
Byles 100 94 81 79 81
Watts 71 22 48 100 17
Walsh 41 85 71 88 81
Ahmed 93 47 76 64 94
Ellis 87 99 100 70 83
Silny 80 76 85 78 81
Simms 88 93 42 84 65
Kenez 75 48 77 69 82
-------------------------------------------------------------------------------