Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main(void)
- {
- ifstream inFile;
- ofstream outFile;
- string employeeName;
- int filechoice;
- double yearsOfService;
- double bonus;
- //User chooses input file.
- cout << "Exercise #4" << endl;
- cout << endl;
- cout.fill('*');
- cout << setw(60) << " " << endl;
- cout.fill(' ');
- cout << "Select the input file: " << endl;
- cout << "1. ex4-1Data.txt" << endl;
- cout << "2. ex4-2Data.txt" << endl;
- cout.fill('*');
- cout << setw(60) << " " << endl;
- cout.fill(' ');
- cout << "Input file choice: ";
- cin >> filechoice;
- cout << endl;
- //Input file is opened depending on what the user entered.
- if (filechoice == 1 )
- {
- inFile.open("ex4-1Data.txt");
- cout << "ex4-1Data.txt has been opened." << endl;
- }
- else if (filechoice == 2)
- {
- inFile.open("ex4-2Data.txt");
- cout << "ex4-2Data.txt has been opened." << endl;
- }
- else
- {
- cout << "Invalid choice selected." << endl;
- }
- getline(inFile,employeeName);
- getline(inFile,yearsOfService);
- //Task 1 - Years of Service, give an extra bonus
- outFile.fill('*');
- outFile << setw(60) << " " << endl;
- outFile.fill(' ');
- outFile << "Task 1 - Years of Service, give an extra bonus" << endl;
- outFile << left << setw (30) << "Name" << right << setw(15) << employeeName << endl;
- outFile << left << setw (30) << "Years of Service" << right << setw(15) << yearsOfService << endl;
- outFile << left << setw (30) << "Bonus" << right << setw(15) << bonus << endl;
- outFile.fill('*');
- outFile << setw(60) << " " << endl;
- outFile.fill(' ');
- inFile.close();
- outFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement