/** * Assignment #6 * Program to process grades. * Author: Mark Allen Weiss * SSN: 000-00-0000 * Course: COP-2210 Section 8 * Date: October 28, 1998 * * CERTIFICATION OF SOLE AUTHORSHIP * I certify that this work is solely my own and * that none if it is the work of any other person. * I further certify that I have not provided any * assistance to other students enrolled in COP-2210 that * would render their CERTIFICATION OF SOLE AUTHORSHIP * invalid. I understand that violations of this pledge * may result in severe sanctions. * * * * ----------------------------------- * (Mark Allen Weiss) <--- Put your name here, and sign above */ #include #include #include "apstring.h" void OpenInput( apstring & infile, ifstream & fin ); void OpenOutput( apstring infile, apstring outfile, ofstream & fout ); void ProcessFile( istream & fin, ostream & fout ); int main( ) { apstring infile; // Input file name apstring outfile; // Output file name ifstream fin; // Input file stream ofstream fout; // Output file stream OpenInput( infile, fin ); OpenOutput( infile, outfile, fout ); ProcessFile( fin, fout ); return 0; } /** * Usual stuff; you should copy this. */ void OpenInput( apstring & infile, ifstream & fin ) { for( ; ; ) { cout << "Enter the input file name: "; cin >> infile; fin.open( infile.c_str( ), ios::in | ios::nocreate ); if( !fin ) { cout << "Bad file." << endl; fin.clear( ); } else break; } } /** * Usual stuff. This routine also checks to * make sure that outfile is different from infile. * To avoid this test, call it with infile equal to "". */ void OpenOutput( apstring infile, apstring outfile, ofstream & fout ) { for( ; ; ) { cout << "Enter the output file name: "; cin >> outfile; if( infile == outfile ) { cout << "Input and output files are identical!!" << endl; continue; } fout.open( outfile.c_str( ) ); if( !fout ) { cout << "Bad file." << endl; fout.clear( ); } else break; } } /** * Compute the grades. * Pre: fin and fout are open and ready for reading or writing, respectively. */ void ProcessFile( istream & fin, ostream & fout ) { apstring Name, FirstName, LastName; int Grade1, Grade2, Grade3; double Average; char CourseGrade; int As, Bs, Cs, Ds, Fs; As = Bs = Cs = Ds = Fs = 0; while( fin >> LastName >> FirstName >> Grade1 >> Grade2 >> Grade3 ) { Average = Grade1 * 0.25 + Grade2 * 0.30 + Grade3 * 0.45; if( Average >= 90.0 ) { CourseGrade = 'A'; As++; } else if( Average >= 80.0 ) { CourseGrade = 'B'; Bs++; } else if( Average >= 70.0 ) { CourseGrade = 'C'; Cs++; } else if( Average >= 60.0 ) { CourseGrade = 'D'; Ds++; } else { CourseGrade = 'F'; Fs++; } cout << LastName << " " << FirstName << " " << CourseGrade << endl; fout << LastName << " " << FirstName << " " << Grade1 << " " << Grade2 << " " << Grade3 << " " << Average << " " << CourseGrade << endl; } // Write out grade distribution fout << "A " << As << endl; fout << "B " << Bs << endl; fout << "C " << Cs << endl; fout << "D " << Ds << endl; fout << "F " << Fs << endl; }