Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main(void)
  9. {
  10. ifstream inFile;
  11. ofstream outFile;
  12.  
  13. string employeeName;
  14.  
  15. int filechoice;
  16. double yearsOfService;
  17. double bonus;
  18.  
  19. //User chooses input file.
  20. cout << "Exercise #4" << endl;
  21. cout << endl;
  22. cout.fill('*');
  23. cout << setw(60) << " " << endl;
  24. cout.fill(' ');
  25. cout << "Select the input file: " << endl;
  26. cout << "1. ex4-1Data.txt" << endl;
  27. cout << "2. ex4-2Data.txt" << endl;
  28. cout.fill('*');
  29. cout << setw(60) << " " << endl;
  30. cout.fill(' ');
  31. cout << "Input file choice: ";
  32. cin >> filechoice;
  33. cout << endl;
  34.  
  35.  
  36.  
  37. //Input file is opened depending on what the user entered.
  38. if (filechoice == 1 )
  39. {
  40. inFile.open("ex4-1Data.txt");
  41. cout << "ex4-1Data.txt has been opened." << endl;
  42. }
  43. else if (filechoice == 2)
  44. {
  45. inFile.open("ex4-2Data.txt");
  46. cout << "ex4-2Data.txt has been opened." << endl;
  47. }
  48. else
  49. {
  50. cout << "Invalid choice selected." << endl;
  51. }
  52.  
  53. getline(inFile,employeeName);
  54. getline(inFile,yearsOfService);
  55.  
  56. //Task 1 - Years of Service, give an extra bonus
  57. outFile.fill('*');
  58. outFile << setw(60) << " " << endl;
  59. outFile.fill(' ');
  60. outFile << "Task 1 - Years of Service, give an extra bonus" << endl;
  61. outFile << left << setw (30) << "Name" << right << setw(15) << employeeName << endl;
  62. outFile << left << setw (30) << "Years of Service" << right << setw(15) << yearsOfService << endl;
  63. outFile << left << setw (30) << "Bonus" << right << setw(15) << bonus << endl;
  64. outFile.fill('*');
  65. outFile << setw(60) << " " << endl;
  66. outFile.fill(' ');
  67.  
  68.  
  69.  
  70. inFile.close();
  71. outFile.close();
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement