//PURPOSE: This program inputs information about an employee and calculates the
ID: 3655749 • Letter: #
Question
//PURPOSE: This program inputs information about an employee and calculates the employee's pay. // This process is continued until the user indicates that he/she desires to quit. #include #include using namespace std; // Function Prototypes: void Asterisks(int howMany); //print asterisks int GetHours(); //get hours worked float GetRate(); //get rate of pay void PrintPay(float hourRate, int numberHours, float pay, int id); //print pay char PromptForMore(); //get more? int main () { //local variables char reply; // ='y'-repeat process; ='n'-stop float rateOfPay; //rate of pay per hour int hoursWorked; //hours worked int idNumber; //ID of the employee float overTimePay; //employee overtime float payAmount; //employee pay //process employees while the user says there are more do { Asterisks(30); // print a line with 30 asterisks // get the employee's data hoursWorked = GetHours(); rateOfPay = GetRate(); cout << "Please enter your ID number: "; cin >> idNumber; //calculate the pay if (hoursWorked <= 40) payAmount = rateOfPay * hoursWorked; else { overTimePay = (hoursWorked - 40) * rateOfPay * 1.5; payAmount = 40 * rateOfPay + overTimePay; } PrintPay(rateOfPay, hoursWorked, payAmount, idNumber); reply = PromptForMore(); } while (reply =='y'); return 0; } //FUNCTION: Asterisks //TASK: Prints a line of asterisks. The parameter, howMany, indicates how many asterisks to print. void Asterisks(int howMany) { //complete this for loop for (initialize; test; update) { cout << "*"; } cout << endl; return; } //FUNCTION: GetHours //TASK: Reads in the hours worked by an employee. Only positive values are accepted for the hours worked. //BE CAREFUL WITH THIS ONE!! Is this function doing what this description says it should? int GetHours() { //variable declarations int hours; // the number of hours worked // get the number of hours worked do { cout << "Please enter the hours worked:(hour should be positive) "; cin >> hours; } while hours > 0; return hours; } //FUNCTION: GetRate //TASK: This function reads in the rate of pay of an employee. Only positive values are accepted for the rate. // BE CAREFUL WITH THIS ONE!! Is this function doing what this description says it should? float GetRate() { //variable declarations float rate = -1; //rate of pay per hour //get the rate of pay per hour do while (rate < 0) { cout << "Please enter the pay rate per hour: "; cin >> rate; }end of do while statement return rate; } //FUNCTION: PrintPay //TASK: This function prints an employee's pay check. Input parameters include the rate of pay per hour, // the number of hours worked, the employee id, and the pay. void PrintPay(float hourRate, int numberHours, float pay, int id) { Asterisks(10); Asterisks(10); cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint); cout << setprecision(2); cout << "EMPLOYEE #: " << id << endl; cout << "PAY AMOUNT: $" << pay << endl; cout << "RATE OF PAY:$" << hourRate << endl; cout << "HOURS WORKED: " << numberHours << endl; } //FUNCTION: PromptForMore //TASK: This program asks the user whether there to continue or not. Only a 'y' or 'n' // answer is accepted as valid input. The user's response is returned to the calling program. char PromptForMore() { //declare local variables char answer; //the user's response do { cout << "Do you wish to continue, y or n? "; cin >> answer; cout << endl; } end of do while (answer != 'y') && (answer != 'n'); return answer; }Explanation / Answer
//Class Employee - #ifndef EMPLOYEE_H #define COURSE_H #include using namespace std; const unsigned LastNameSize = 30; class Employee { public: Employee(); Employee( long idVal, const char *lastNameVal, float payRateVal, float hoursVal ); //Construct an //employee file from an I.D., last name, pay rate, and number of hours. long const GetId(); //Get/return employee I.D. number. char const GetLastName(); //Get/return employee's last name. float const GetPayRate() const; //Get/return employee's pay rate. float const GetHours(); //Get/return employee's hours. float CalcGrossPay( float hours, float payRate); //Calculate and return gross pay. float CalcWeekPay( float hours, float payRate); void SetHours( float hoursVal ); //Set the number of hours. void SetPayRate( float payRateVal ); //Set the pay rate. void Display() const; friend istream & operator >>( istream & input, Employee & E); friend ostream & operator > E.id >> E.name >> E.payRate >> E.hours; return input; } ostream & operatorRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.