#include #include #include const bool debugging = false; using namespace std; /* This is the contents of the file "grades.txt" sally 98 88 jim 34 67 jane 99 13 joe 23 21 martha 78 76 bill 100 56 I want to be told the average grade for each student, and also create two new files, one containing the data for the good students, the other containing the data for the bad student. */ int main() { ifstream gradefile("grades.txt"); // OPENing the file ofstream goodfile("goodgrades.txt"); ofstream badfile("badgrades.txt"); if (gradefile.fail() || goodfile.fail() || badfile.fail()) { cout << "Could not open file\n"; exit(1); } int linenum = 0; while (true) { string name; int g1, g2; gradefile >> name >> g1 >> g2; if (gradefile.fail()) break; linenum = linenum + 1; if (debugging) cout << "read :'" << name << "', " << g1 << ", " << g2 << "\n"; double avg = (g1+g2)/2.0; cout << linenum << ": " << name << ", avg " << avg << "\n"; if (avg < 60) badfile << name << " " << g1 << " " << g2 << "\n"; else goodfile << name << " " << g1 << " " << g2 << "\n"; } gradefile.close(); goodfile.close(); badfile.close(); cout << "Done\n"; }