Guest User

Untitled

a guest
Dec 12th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. ...
  6. }
  7.  
  8. A) Write a statement that includes the header files fstream, string, and
  9. iomanip in this program.
  10.  
  11. B) Write statements that declare inFile to be an ifstream variable and
  12. outFile to be an ofstream variable.
  13.  
  14. C) The program will read data from the file inData.txt and write output
  15. to the file outData.txt. Write statements to open both of these files,
  16. associate inFile with inData.txt, and associate outFile with outData.txt.
  17.  
  18. D) Suppose that the file inData.txt contains the following data:
  19.  
  20. Giselle Robinson Accounting
  21. 5600 5 30
  22. 450 9
  23. 75 1.5
  24.  
  25. The first line contains a person's first name, last name, and the department
  26. the person works in. In the second line, the first number represents the monthly
  27. gross salary, the bonus (as a percent), and the taxes (as a percent). The third
  28. line contains the distance traveled and the traveling time. The fourth line
  29. contains the number of coffee cups sold and the cost of each coffee cup. Write
  30. statements so that after the program executes, the contents of the file outData.txt
  31. are shown as below. If necessary, declare additional variables. Your statements
  32. should be general enough so that if the contents of the input file changes and the
  33. program is run again (without editing and recompilin), it outputs the appropriate results.
  34.  
  35. Name : Giselle Robinson, Department : Accounting
  36. Monthly Gross Salary: $5600.00, Monthly Bonus: 5.00%, Taxes: 30.00%
  37. Paycheck: $4116.00
  38.  
  39. Distance Traveled: 450.00 miles, Traveling Time: 9.00 hours
  40. Average Speed: 50.00 miles per hour
  41.  
  42. Number of Coffee Cups Sold: 75, Cost: $1.50 per cup
  43. Sales Amount = $112.50
  44.  
  45. E) Write statements that close the input and output files.
  46.  
  47. F) Write C++ program that tests the statements in parts a through e.
  48.  
  49. #include "stdafx.h"
  50. #include <fstream>
  51. #include <string>
  52. #include <iomanip>
  53.  
  54. using namespace std;
  55.  
  56. int main()
  57. {
  58. ifstream inFile;
  59. ofstream outFile;
  60.  
  61. inFile.open("inData.txt");
  62. outFile.open("outData.txt");
  63.  
  64. string firstName, lastName, department;
  65.  
  66. double monthlySalary, gross, bonus, tax, distance, time, cost, salesAmount, speed;
  67.  
  68. int count;
  69.  
  70. inFile.open("inData.txt");
  71. outFile.open("outData.txt");
  72.  
  73. inFile >> firstName >> lastName >> department;
  74. outFile << "Name:" << firstName << "" << lastName
  75. << ", Department:" << department << endl;
  76. inFile >> gross >> bonus >> tax;
  77. outFile << "Monthly Gross Salary: $" << gross
  78. << ", Monthly Bonus: " << bonus << "%Taxes:" << tax << "%" << endl;
  79.  
  80. inFile >> distance >> time;
  81. outFile << "Distance Travelled:" << distance
  82. << ", Traveling Time:" << time << "hours" << endl;
  83.  
  84. speed = distance / time;
  85. outFile << "Average Speed:" << speed
  86. << ", miles per hour" << endl;
  87.  
  88. inFile >> count >> cost;
  89. outFile << "Numbeer of Coffee Cups Sold:" << count
  90. << " Cost: $" << cost << "per cup" << endl;
  91.  
  92. monthlySalary = gross + ((gross*bonus) / 100);
  93. monthlySalary = monthlySalary - (monthlySalary * 30) / 100;
  94.  
  95. salesAmount = count*cost;
  96. return 0;
  97. }
  98.  
  99. outFile << "Name:" << firstName << "" << lastName
  100. << ", Department:" << department << endl;
  101.  
  102. cout << "Name:" << firstName << "" << lastName
  103. << ", Department:" << department << endl;
Add Comment
Please, Sign In to add comment