Question

Design a PayRoll class that has data members for an employee’s hourly pay rate, number of...

Design a PayRoll class that has data members for an employee’s hourly pay rate, number of hours worked of type double. The default constructor will set the hours worked and pay rate to zero. The class must have a mutator function to set the pay rate for each employee and hours worked. The class should include accessors for both the hours worked and the rate of pay. The class should lastly have a getGross function that will return a double calculated by multiplying the hours worked by the rate of pay. Write a program with an array of seven PayRoll objects. The program should ask the user for the rate of pay for each employee and the number of hours each employee has worked. Be sure to include an employee claiming to work more then 60 hours per week. Print out, the array number of the employee, the hours worked, the rate of pay, and the gross pay, of all the employee's each on their own line. Set the precision for printing the doubles to two decimal places. Input Validation: Do not accept values greater than 60 for the number of hours worked, simply have the set function set number of hours worked to 60, the maximum allowed.

OUTPUT SHOULD BE Creating·7·Payroll·objects.↵ Enter·the·#·0·employee's·rate·of·pay·per·hour:12.22↵ Enter·the·#·0·employee's·hours·worked·for·the·week:22↵ Enter·the·#·1·employee's·rate·of·pay·per·hour:99.99↵ Enter·the·#·1·employee's·hours·worked·for·the·week:36↵ Enter·the·#·2·employee's·rate·of·pay·per·hour:45.67↵ Enter·the·#·2·employee's·hours·worked·for·the·week:20↵ Enter·the·#·3·employee's·rate·of·pay·per·hour:56.78↵ Enter·the·#·3·employee's·hours·worked·for·the·week:0↵ Enter·the·#·4·employee's·rate·of·pay·per·hour:40.45↵ Enter·the·#·4·employee's·hours·worked·for·the·week:5↵ Enter·the·#·5·employee's·rate·of·pay·per·hour:30.35↵ Enter·the·#·5·employee's·hours·worked·for·the·week:80↵ Enter·the·#·6·employee's·rate·of·pay·per·hour:30.33↵ Enter·the·#·6·employee's·hours·worked·for·the·week:45↵ ↵ ↵ Employee·#·0·worked·22.00·hours·at·$12.22·for·a·gross·pay·of·$268.84↵ Employee·#·1·worked·36.00·hours·at·$99.99·for·a·gross·pay·of·$3599.64↵ Employee·#·2·worked·20.00·hours·at·$45.67·for·a·gross·pay·of·$913.40↵ Employee·#·3·worked·0.00·hours·at·$56.78·for·a·gross·pay·of·$0.00↵ Employee·#·4·worked·5.00·hours·at·$40.45·for·a·gross·pay·of·$202.25↵ Employee·#·5·worked·60.00·hours·at·$30.35·for·a·gross·pay·of·$1821.00↵ Employee·#·6·worked·45.00·hours·at·$30.33·for·a·gross·pay·of·$1364.85↵

C++ only please

Homework Answers

Answer #1

Screenshot of program code:-

Screenshot of output:-

Program code to copy:-

#include <iostream>
#include <iomanip>

using namespace std;

//PayRoll class
class PayRoll
{
private:
   // Private data members
   double hourlyPayRate;
   double hoursWorked;
public:
   // Member functions prototype
   PayRoll();
   void setHourlyPayRate(double rate);
   void setHoursWorked(double hours);
   double getHourlyPayRate();
   double getHoursWorked();
   double getGross();
};

// default constructor sets the hours worked and pay rate to zero
PayRoll::PayRoll()
{
   hourlyPayRate = 0;
   hoursWorked = 0;
}

// mutator function to set the pay rate for each employee
void PayRoll::setHourlyPayRate(double rate)
{
   hourlyPayRate = rate;
}

// mutator function to set the hours worked for each employee
void PayRoll::setHoursWorked(double hours)
{
   hoursWorked = hours;
}

// accessors function returns the rate of pay
double PayRoll::getHourlyPayRate()
{
   return hourlyPayRate;
}

// accessors function returns the hours worked
double PayRoll::getHoursWorked()
{
   return hoursWorked;
}

// function returns a gross pay calculated by multiplying the hours worked by the rate of pay
double PayRoll::getGross()
{
   return hourlyPayRate*hoursWorked;
}

int main()
{
   // Declare array of seven PayRoll objects
   PayRoll payroll[7];
   // Declare varible used to hold hours worked and pay rate
   double rate, hours;
  
   cout << "Creating 7 Payroll objects." << endl;
   for(int i=0; i<7; i++)
   {
       // prompt & read the rate of pay from user
       cout << "Enter the #" << i << " employee's rate of pay per hour: ";
       cin >> rate;
       // prompt & read the hours worked from user
       cout << "Enter the #" << i << " employee's hours worked for the week: ";
       cin >> hours;
       // set the value of pay rate to data member of object
       payroll[i].setHourlyPayRate(rate);
       // set the value of hours worked to data member of object
       if(hours>60)
           payroll[i].setHoursWorked(60);
       else
           payroll[i].setHoursWorked(hours);
   }
  
   // Displying the array number of the employee, the hours worked, the rate of pay, and
   // the gross pay, of all the employee's.
   cout << fixed << setprecision(2) << endl << endl;
   for(int i=0; i<7; i++)
   {
       cout << "Employee #" << i << " worked "
       << payroll[i].getHoursWorked() << " hours at $"
           << payroll[i].getHourlyPayRate() << " for a gross pay of $"
           << payroll[i].getGross() << endl;
   }
  
   return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information in the appropriate objects. It should then call a class function, once for each object, to return...
Hourly workers are paid at their regular pay rate for their first 40 hours worked each...
Hourly workers are paid at their regular pay rate for their first 40 hours worked each week. Any hours beyond that are considered overtime, and they get paid "time-and-a-half" for those hours (1-1/2 times their regular pay rate). For example, if a worker normally makes $12.00 per hour and has worked 45 hours in the past week, the pay is computed as follows: 40 times $12 for the "regular" hours is $480. The extra 5 hours is overtime and is...
Create a C# application You are to create a class object called “Employee” which included eight...
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week. regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods:  constructor  properties  CalcPay(): Calculate the regular...
Pay Rate Hours Worked Gross Pay Deductions Net Pay Employee Number 468921 15.00 28 420.00 325.00...
Pay Rate Hours Worked Gross Pay Deductions Net Pay Employee Number 468921 15.00 28 420.00 325.00 95.00 357942 16.50 50 825.00 205.00 620.00 816543 5.00 40 200.00 45.00 245.00 963248 57.60 40 2,304.00 10.00 2,294.00 1. Calculate examples of these batch totals: hash total financial total record count Assume the following rules govern normal data: Employee numbers are five digits in length and range from 1000 through 99999. Maximum pay rate is $35, and minimum is $15. Hours worked should...
I have a 2 class code and it works everything is fine and runs as it...
I have a 2 class code and it works everything is fine and runs as it supposed too. What will the UML be for both classes. Here's the code, any help will be awsome, Thanks. import java.util.Scanner; public class PayRollDemo { public static void main(String[] args) { double payRate; int hours; PayRoll pr = new PayRoll(); Scanner keyboard = new Scanner(System.in); for (int index = 0; index < 7 ; index++ ) { System.out.println(); System.out.println("EmployeeID:" + pr.getEmployeeID(index)); System.out.println(); System.out.println("Enter the...
Calculate Payroll Breakin Away Company has three employees—a consultant, a computer programmer, and an administrator. The...
Calculate Payroll Breakin Away Company has three employees—a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $4,000 per week $60 per hour $50 per hour Overtime earnings rate* Not applicable 1.5 times hourly rate 2 times hourly rate Number of withholding allowances 2 1 2 *For hourly employees, overtime is paid for hours worked in excess of 40 hours per week. For the current pay...
Description Write a program that reads in the name, hourly rate and number of hours worked...
Description Write a program that reads in the name, hourly rate and number of hours worked for 5 people. Print the name of each person, the number of hours worked, their weekly pay based on the number of hours they worked and how much they owe in taxes. Assume that taxes take 20% of the paycheck. Don’t forget to take the taxes out of the pay check. If they work more than 40 hours they get overtime. The hourly rate...
Calculate Payroll Breakin Away Company has three employees—a consultant, a computer programmer, and an administrator. The...
Calculate Payroll Breakin Away Company has three employees—a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $4,000 per week $60 per hour $50 per hour Overtime earnings rate* Not applicable 1.5 times hourly rate 2 times hourly rate Number of withholding allowances 2 1 2 *For hourly employees, overtime is paid for hours worked in excess of 40 hours per week. For the current pay...
Calculate Payroll Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The...
Calculate Payroll Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $3,210 per week $34 per hour $48 per hour Overtime earnings rate Not applicable 1.5 times hourly rate 2 times hourly rate Number of withholding allowances 3 2 1 For the current pay period, the computer programmer worked 60 hours and the administrator worked 50 hours. The federal income...
Calculate Payroll Donohue Professional Services has three employees-a consultant, a computer programmer, and an administrator. The...
Calculate Payroll Donohue Professional Services has three employees-a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $3,010 per week $28 per hour $42 per hour Overtime earnings rate Not applicable 1.5 times hourly rate 2 times hourly rate Number of withholding allowances 3 2 1 For the current pay period, the computer programmer worked 60 hours and the administrator worked 50 hours. The federal income...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT