Code:
# include <iostream> # include <fstream> # include <iomanip> # include <cstdlib> // needed for exit () using namespace std; int main() { ifstream inFile; ofstream outFile; inFile.open("registration.txt"); // attempt to open the file for input Student ID first { char registration; if (!inFile.fail()) // if it does not fail, the file exists cout <<"A file exits by name Registration.txt.\n" <<" Do you want to continue and overwrite it\n" <<" with the new information (y or n): "; cin >> registration; if (tolower(registration) == 'n') { cout << " File cannot be overwritten." << endl; exit (1); // Terminate program execution } } outFile.open("registration.txt"); // open the file for Writing if (inFile.fail()) // Successfully Open or Not { cout << "\nThe file was not sucessfully opened try again" << endl; exit (1); cout << "The file was successfully opened for output." << endl; return 0; } }// I/O file
I need a WHILE loop to read and process all the students
MAKE SURE TO READ STUDENT ID FIRST, THE RANGE OF STUDENT ID IS BETWEEN 1 and 999. The Input file should have up to 12 student's data which I already have in put file.
Code:
STUDENT ID # RESIDENCE STUDY # of CREDITS FEE --------------- ----------------- --------------- -------------- ------------ 55 In-state Undergraduate 19 $7345 100 Out-of- State Graduate 13 $5233 974 In-state Undergraduate 8 $5235 196 In-state Graduate 3 $990 999 Out-of- State Undergraduate 18 $7213 100 In-state Graduate 5 $1034 497 In-state Undergraduate 20 $7994 734 Out-of- State Graduate 7 $2403 691 Out-of- State Undergraduate 12 $4013 143 In-state Graduate 21 $8034 555 Out-of- State Undergraduate 10 $3985 01 Out of Country Graduate 04 $101 THE AVERAGE REGISTRATION FEE IS : $4465 THE MOST CREDIT WAS 21 TAKEN BY STUDENT 143. LESS THAN 12 CREDITS 196 In-State Graduate 3 $990
Comment