/***************************************************/ // L Frye // CSC135010 - Spring 2008 // Program #1 // Due: Feb 14, 2008 // Filename: avgs.cpp // Description: This program will find a student's test average /***************************************************/ #include #include #include #define NUMTESTS 3 using namespace std; int main() { // variable declarations string name; // student's name float test1, test2, test3; float avg; // test average ifstream infile; // Open file infile.open("averages.data"); if (infile.fail()) { cout << endl; cout << "Error opening input file averages.data" << endl << endl; return 0; } // end if fail cout << fixed << showpoint; // print in fixed-point with decimal cout << setprecision(2); // print two places after decimal // read first line of file getline(infile, name); infile >> test1; infile >> test2; infile >> test3; infile.ignore(10, '\n'); // skip over newline character while (!infile.eof()) { // processing avg = (test1 + test2 + test3) / NUMTESTS; // print results cout << left << setw(25) << name; cout << "Average = "; cout << right << setw(7) << avg << "%" << endl; // get input getline(infile, name); infile >> test1; infile >> test2; infile >> test3; infile.ignore(10, '\n'); // skip over newline character } // end eof loop infile.close(); return 0; }