/* seqFileIO.cpp Name: CIS 150 Sequential file I/O lab Date: Lab to demonstrate sequential file reading and writing. */ // Finish the parts of the program marked ** TODO ** // A separate data file named pres.txt should also be downloaded. #include #include #include #include using namespace std; bool displayFile(string filename); int main(int argc, char* argv[]) { string fname = "pres.txt"; string pres44 = "Barack Obama"; string pres45 = "Donald Trump"; int year44 = 2009; int year45 = 2016; cout << "Before adding last two presidents:\n"; bool ok = displayFile(fname); if (ok) { // ** TODO ** // Open the file specified by fname for appending text output. // If file error, display error message and exit with EXIT_FAILURE status. // Output to file: year44, " ", pres44, "\n" // Output to file: year45, " ", pres45, "\n" // Close the file // ** END OF TODO ** cout << "\nAfter adding last two presidents:\n"; displayFile(fname); } cout << "Press enter to continue..."; cin.get(); return EXIT_SUCCESS; } bool displayFile(string filename) { int year; string name; int number; // ** TODO ** // Open the file specified by fname for text input. // If file error, display error message and return false. // ** END OF TODO ** number = 0; // ** TODO ** // Loop while reading the year from the file does not cause an error. // Increment number. // Ignore any blanks in the input stream from the file. // Read a line of text from the file into the variable name. // Display number, ". ", name, " (", year, ")\n" on the screen // Close the file. // ** END OF TODO ** return true; }