There is a PayRoll Class that has data members for an employee’s hourly pay rate, number of hours worked,and total pay for the week, There is also a program with an array of four PayRoll objects; this program asks the user to input the working hours and hourly pay rate for each employee and display the amount of gross pay each has earned. Please revise this PayRoll Class and program as following: The PayRoll Class also has a member variable named ID whose datatype is integer. We use ID to hold employee’s ID. The program also asks the user to input the employee’s ID for each employee in the array. The program displays the highest amount of gross pay among the four employees and displays the employee’s ID who has this highest amount of gross pay. The program displays the average values of gross pays among the four employees and displays the number of employees whose gross pay are above this average value. Here is the original class and program #include <iostream> #include <iomanip> using namespace std; class Payroll { private: double hours; double payRate; public: // Constructor Payroll() { hours = 0; payRate = 0; } // Mutators void setHours(double h) { hours=h; } void setPayRate(double r) { payRate = r; } // Accessors double getHours() const { return hours; } double getPayrate() const { return payRate; } double getTotalPay() const { return hours * payRate; } }; // Constant for number of employees const int NUM_EMPLOYEES = 4; int main() { double hours; // Hours worked double rate; // Hourly pay rate int count; // Loop counter // Array of Payroll objects Payroll employees[NUM_EMPLOYEES]; // Get the hours worked and the pay rate // for each employee. cout << "Enter the hours worked and pay rate " << "for " << NUM_EMPLOYEES << " employees:\n"; for (count = 0; count < NUM_EMPLOYEES; count++) { // Get the employee's pay rate. cout << "\nEmployee #" << (count+1) << " pay rate: "; cin >> rate; employees[count].setPayRate(rate); // Get the employee's hours worked cout << "Employee #" << (count+1) << " hours worked: "; cin >> hours; employees[count].setHours(hours); } // Display the total pay for each employee. cout << "Total pay:\n"; cout << setprecision(2) << fixed << showpoint << right; for ( count = 0; count < NUM_EMPLOYEES; count++) { cout << "\tEmployee #" << (count+1) << ": "; cout << setw(8) << employees[count].getTotalPay() << endl; } return 0; }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
There is a PayRoll Class that has data members for an employee’s hourly pay rate, number of hours worked,and total pay for the week, There is also a
Please revise this PayRoll Class and program as following:
- The PayRoll Class also has a member variable named ID whose datatype is integer. We use ID to hold employee’s ID. The program also asks the user to input the employee’s ID for each employee in the array.
- The program displays the highest amount of gross pay among the four employees and displays the employee’s ID who has this highest amount of gross pay.
- The program displays the average values of gross pays among the four employees and displays the number of employees whose gross pay are above this average value.
Here is the original class and program
#include <iostream>
#include <iomanip>
using namespace std;
class Payroll
{
private:
double hours;
double payRate;
public:
// Constructor
Payroll()
{ hours = 0; payRate = 0; }
// Mutators
void setHours(double h)
{
hours=h;
}
void setPayRate(double r)
{ payRate = r; }
// Accessors
double getHours() const
{ return hours; }
double getPayrate() const
{ return payRate; }
double getTotalPay() const
{ return hours * payRate; }
};
// Constant for number of employees
const int NUM_EMPLOYEES = 4;
int main()
{
double hours; // Hours worked
double rate; // Hourly pay rate
int count; // Loop counter
// Array of Payroll objects
Payroll employees[NUM_EMPLOYEES];
// Get the hours worked and the pay rate
// for each employee.
cout << "Enter the hours worked and pay rate "
<< "for " << NUM_EMPLOYEES << " employees:\n";
for (count = 0; count < NUM_EMPLOYEES; count++)
{
// Get the employee's pay rate.
cout << "\nEmployee #" << (count+1) << " pay rate: ";
cin >> rate;
employees[count].setPayRate(rate);
// Get the employee's hours worked
cout << "Employee #" << (count+1) << " hours worked: ";
cin >> hours;
employees[count].setHours(hours);
}
// Display the total pay for each employee.
cout << "Total pay:\n";
cout << setprecision(2) << fixed << showpoint << right;
for ( count = 0; count < NUM_EMPLOYEES; count++)
{
cout << "\tEmployee #" << (count+1) << ": ";
cout << setw(8) << employees[count].getTotalPay() << endl;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images