fork download
  1. //=========================================================
  2. // File: HW_10c
  3. // Programmer: Elaine Torrez
  4. // Class: CMPR 121
  5. //=========================================================
  6. // Description:
  7. // This program uses vectors to store employee
  8. // hours and wages. It calculates and displays
  9. // the gross pay for each employee.
  10. //=========================================================
  11.  
  12. #include <iostream>
  13. #include <iomanip>
  14. #include <vector>
  15.  
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. const int NUM_EMPLOYEES = 5;
  21.  
  22. vector<int> hours(NUM_EMPLOYEES);
  23. vector<double> wage(NUM_EMPLOYEES);
  24.  
  25. int index;
  26.  
  27. cout << "Enter hours worked and hourly wage of each employee:\n\n";
  28.  
  29. for (index = 0; index < hours.size(); index++)
  30. {
  31. cout << "Hours for Employee #"
  32. << index + 1
  33. << ": ";
  34.  
  35. cin >> hours[index];
  36.  
  37. cout << "Wage for Employee #"
  38. << index + 1
  39. << ": ";
  40.  
  41. cin >> wage[index];
  42. }
  43.  
  44. system("cls");
  45.  
  46. cout << fixed << setprecision(2);
  47.  
  48. cout << "Gross pay for each employee:\n\n";
  49.  
  50. for (index = 0; index < hours.size(); index++)
  51. {
  52. cout << setw(11)
  53. << "Employee #"
  54. << index + 1
  55. << setw(5)
  56. << "$"
  57. << setw(7)
  58. << hours[index] * wage[index]
  59. << endl;
  60. }
  61.  
  62. cout << endl;
  63.  
  64. cout << "Employee #1 hours = "
  65. << hours.front()
  66. << endl;
  67.  
  68. cout << "Employee #5 hours = "
  69. << hours.back()
  70. << endl;
  71.  
  72. return 0;
  73. }
Success #stdin #stdout #stderr 0.01s 5308KB
stdin
Standard input is empty
stdout
Enter hours worked and hourly wage of each employee:

Hours for Employee #1: Wage for Employee #1: Hours for Employee #2: Wage for Employee #2: Hours for Employee #3: Wage for Employee #3: Hours for Employee #4: Wage for Employee #4: Hours for Employee #5: Wage for Employee #5: Gross pay for each employee:

 Employee #1    $   0.00
 Employee #2    $   0.00
 Employee #3    $   0.00
 Employee #4    $   0.00
 Employee #5    $   0.00

Employee #1 hours = 0
Employee #5 hours = 0
stderr
sh: 1: cls: not found