fork download
  1. // Kurt Feiereisel CSC5 Chapter 7, p. 445, #8
  2. /*******************************************************************************
  3.  *
  4.  * Calculate Wages for Employee ID Numbers
  5.  * _____________________________________________________________________________
  6.  * This program allows a user to enter the number of hours worked by an employee
  7.  * ID number, and the payrate of an employee ID number. The program will then
  8.  * calculate and report the gross wages for each employee ID number, and the
  9.  * hours worked by each employee ID number.
  10.  * _____________________________________________________________________________
  11.  * Formula:
  12.  * wages[NUM] = payRate[NUM] * hours[NUM]
  13.  *
  14.  * INPUT:
  15.  * empId[] : Employee's ID numbers
  16.  * hours[] : Number of hours worked by an employee Id number
  17.  * payRate[] : Payrate for an employee ID number
  18.  *
  19.  * OUTPUT:
  20.  * wages[] : The gross wages for an employee ID number
  21.  *
  22.  * ****************************************************************************/
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. // Function prototypes
  28. void getInfo(int empId[], int hours[], float payRate[], int NUM);
  29. void calcGross(int hours[], float payRate[], float wages[], int NUM);
  30. void displayArray(int empId[], int hours[], float wages[], int NUM);
  31.  
  32. int main()
  33. {
  34. // Initialize Constants
  35. const int NUM = 7;
  36.  
  37. // Declare / Initialize Array's
  38. int empId[] = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
  39. 7580489}; // Input : Employee ID numbers
  40. int hours[NUM]; // Input : Hours worked
  41. float payRate[NUM]; // Input : Pay rate
  42. float wages[NUM]; // Output : Gross Wages
  43.  
  44. // Call Functions
  45. getInfo(empId, hours, payRate, NUM);
  46. calcGross(hours, payRate, wages, NUM);
  47. displayArray(empId, hours, wages, NUM);
  48. return 0;
  49. }
  50.  
  51. /*
  52.  * Definition of getInfo Function
  53.  * This function allows a user to enter hours worked, pay rate, and wages of
  54.  * an employee ID.
  55.  */
  56. void getInfo(int id[], int h[], float p[], int num)
  57. {
  58. // Input Hours for Employee ID
  59. for (int index = 0; index < num; index++)
  60. {
  61. cout << "Enter Employee #" << id[index] << "'s information:\n";
  62.  
  63. // Input Hours
  64. cout << "Hours: ";
  65. cin >> h[index];
  66.  
  67. // Input Verification
  68. while(h[index] < 0)
  69. {
  70. cout << "Please enter a positive number for hours.";
  71. cin >> h[index];
  72. }
  73.  
  74. // Input PayRate
  75. cout << "Pay Rate: ";
  76. cin >> p[index];
  77.  
  78. // Input Verification
  79. while (p[index] < 6.00)
  80. {
  81. cout << "Please enter a pay rate more than $6.00.";
  82. cin >> p[index];
  83. }
  84. cout << endl;
  85. }
  86. }
  87.  
  88. /*
  89.  * Definition of calcGross
  90.  * This function calculates the gross wages for an employee ID
  91.  */
  92. void calcGross(int h[], float p[], float w[], int num)
  93. {
  94. // Calculate and Store Gross Wages
  95. for(int index = 0; index < num; index++)
  96. w[index] = (h[index] * p[index]);
  97. }
  98.  
  99. /*
  100.  * Definition of displayArray
  101.  * This function will display the hours and wages for each employee ID
  102.  */
  103. void displayArray(int id[], int h[], float w[], int num)
  104. {
  105. // Display Header
  106. cout << "Employee ID" << setw(4) << "| " << setw(6)
  107. << "Hours" << setw(4) << "| " << setw(6) << "Wages" << endl;
  108. cout << "-----------------------------------" << endl;
  109.  
  110. // Implement for loop to display hours and wages for each employee ID
  111. for(int index = 0; index < num; index ++)
  112. {
  113. cout << fixed << setprecision(2) << showpoint;
  114. cout << id[index] << setw(7) << "|" << " " << h[index]
  115. << setw(6) << "|" << " " << w[index] << endl;
  116. }
  117. }
  118.  
  119.  
Success #stdin #stdout 0s 5304KB
stdin
40
23.45
43
23.50
50
28.32
32
19.85
96
12.23
19
12.34
60
32.34
stdout
Enter Employee #5658845's information:
Hours: Pay Rate: 
Enter Employee #4520125's information:
Hours: Pay Rate: 
Enter Employee #7895122's information:
Hours: Pay Rate: 
Enter Employee #8777541's information:
Hours: Pay Rate: 
Enter Employee #8451277's information:
Hours: Pay Rate: 
Enter Employee #1302850's information:
Hours: Pay Rate: 
Enter Employee #7580489's information:
Hours: Pay Rate: 
Employee ID  |  Hours  |  Wages
-----------------------------------
5658845      |  40     |   938.00
4520125      |  43     |   1010.50
7895122      |  50     |   1416.00
8777541      |  32     |   635.20
8451277      |  96     |   1174.08
1302850      |  19     |   234.46
7580489      |  60     |   1940.40