1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/* // A-1-1-01
Author: Andrya Newman // A-1-1-02
Date Written: December 11, 2011 // A-1-1-02
Course: CSIS 123, Internet // A-1-1-02
Program: Task 06-02, Chapter 4 // A-1-1-02
Program Description: This test, or driver, program, which demonstrates the "while" // A-1-1-02
repetition statement, determines gross pay for each of // A-1-1-02
several employees. The organization pays "straight time" for // A-1-1-02
the first 40 hours worked by each employee and pays // A-1-1-02
"time-and-a-half" for all hours worked in excess of 40 hours. // A-1-1-02
The program prompts the user for hours worked and hourly pay rate // A-1-1-02
for three employees and, from that information, calculates gross // A-1-1-02
pay. A list of employee number and gross pay is displayed after // A-1-1-02
all input as been accepted. // A-1-1-02
Compiler Used: Microsoft Visual C++ 2010 Express // A-1-1-02
SourceFile Name: Payroll.cpp // A-1-1-02
*/ // A-1-1-03
#include <iostream> // A-1-1-04
#include <iomanip> // A-1-1-05 TODO
#include <string> // A-1-1-06
using namespace std; // A-1-1-07
class Payroll { // A-1-1-08
public: // A-1-1-09
void calculateCurrentPayroll() { // A-1-1-10
const double c_maximumHoursWorkedWithoutOvertimePay = 40; // A-1-3-01 TODO
const int c_inputPromptWidth = 17; // A-1-3-02 TODO
double grossPay; // A-1-3-03
double hoursWorked; // A-1-3-04 TODO
double hourlyPayRate; // A-1-3-05 TODO
const double c_overtimePayRatePremium = 1.5; // A-1-3-06 TODO
int employeeNumber = 1; // A-1-3-07
while (employeeNumber <= getEmployeeCount()) { // A-1-3-08
cout << "\n\tEnter employee " << employeeNumber << ":"; // A-1-3-09 TODO
cout << setw( 17 ) << right << "\n\t\t Hours worked? "; // A-1-3-10 TODO
cin >> hoursWorked; // A-1-3-11 TODO
cout << setw( 17 ) << right << "\t\tHourly pay rate? "; // A-1-3-12 TODO
cin >> hourlyPayRate; // A-1-3-13 TODO
{
if (hoursWorked <= 40) // A-1-3-14 TODO
grossPay = hoursWorked * hourlyPayRate; // A-1-3-15 TODO
else // A-1-3-16 TODO
grossPay = (c_maximumHoursWorkedWithoutOvertimePay * hourlyPayRate // A-1-3-17 TODO
+ (hoursWorked - c_maximumHoursWorkedWithoutOvertimePay) // A-1-3-18 TODO
* hourlyPayRate * c_overtimePayRatePremium); // A-1-3-19 TODO
} // function calculategrossPay // A-1-3-20 TODO
grossPay = employeeGrossPay[employeeNumber - 1]; // A-1-3-21
++employeeNumber; // A-1-3-22
} // while // A-1-3-23
} // function calculateCurrentPayroll // A-1-1-11
void displayCurrentPayroll() { // A-1-1-12
int employeeNumber = 1; // A-1-3-24 TODO
while (employeeNumber <= getEmployeeCount()) { // A-1-3-25 TODO
cout << "\n\t" << employeeNumber; // A-1-3-26 TODO
cout << "\t$" << fixed << showpoint << setprecision (2); // A-1-3-27 TODO
cout << employeeGrossPay << (employeeNumber - 1); // A-1-3-28 TODO
++employeeNumber; // A-1-3-29 TODO
} // A-1-3-30 TODO
} // function displayCurrentPayroll // A-1-1-13
int getEmployeeCount() { // A-1-1-14
return c_employeeCount; // A-1-3-31
} // function getEmployeeCount // A-1-1-15
private: // A-1-1-16
const static int c_employeeCount = 3; // A-1-1-17
double employeeGrossPay[c_employeeCount]; // A-1-1-18
}; // class Payroll // A-1-1-19
int main() { // A-1-5-01
Payroll currentPayroll; // A-1-5-02 TODO
string enterKey; // A-1-5-03
cout << "\nTask 06-02, Ch04, Programmed by Andrya Newman"; // A-1-5-04
cout << "\n\nProgram Input:"; // A-1-5-05
currentPayroll.calculateCurrentPayroll(); //call object's calculate function //A-1-5-06 TODO
cout << "\nProgram Output:"; // A-1-5-07 TODO
cout << "\n\t# \tGross Pay "; // A-1-5-08 TODO
currentPayroll.displayCurrentPayroll(); //call objects public member function // A-1-5-09 TODO
fflush(stdin); // A-1-5-10 TODO
cout << "\n\nEnd of program: Press <Enter> key to exit program."; // A-1-5-11
getline(cin, enterKey); // A-1-5-12
} // function main // A-1-5-13
|