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 employeesconst 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;}

Question
Asked Mar 9, 2020
5 views

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;

}

check_circle

Expert Answer

Step 1

Programming instructions for the revised version of program and PayRoll:

  • Declare a variable named ID of type int.
  • Create an accessor and mutator for ID.
  • Declare a variable maxSal of type double and initialize it to gross pay earned by the first employee in the array. 
  • Declare a variable maxId of type int and initialize it to the id of the first employee in the array.
  • Declare a variable sum of type double and initialize it to gross pay earned by the first employee in the array. 
  • By using a for loop iterate through the array employees and keep updating the value of maxSal and maxId whenever an employee with greater gross pay earned is encountered.
  • By using the aforementioned for loop also add and store the total pay earned by all the employees to the variable sum.
  • Declare a variable avg of type double to store the average pay earned.
  • Divide the value in sum by NUM_EMPLOYEES to get the average and store the result in variable avg.
  • Declare a variable aboveAvg of type int to store the number of employees earning more than average. 
  • By using a for loop, compare the value of gross pay of every employee with the average pay and update the aboveAvg count whenever an employee with greater pay is encountered.  
  • Print the highest pay earned among all employees to console using the value of maxSal
  • Print the id of the employee who earned the highest pay to console using the value of maxId .
  • Print the average pay earned to console using the value of avg .
  • Print the number of employees earning above-average pay to console using the value of aboveAvg .
Step 2

#include <iostream>

#include <iomanip>

using namespace std;

 

class Payroll

{

private:

       double hours;

       double payRate;

       int ID;

public:

       // Constructor

       Payroll()

          { hours = 0; payRate = 0; }

      

       // Mutators

       void setHours(double h)

       {
            hours=h;
       }

       void setPayRate(double r)

       {
           payRate = r;
       }

      
       void setID(int id)
       {
           ID = id; 
       }

       // Accessors

       double getHours() const

             { return hours; }

 

       double getPayrate() const

             { return payRate; }
             
             
        int getID() const
            {
                return ID;
            }

 

       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 id;        // Employee id

   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, pay rate and employee id "

       << "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);
  &nbs...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What is the difference between the Screen and Overlay blending mode effect in Photoshop?

A: Difference between Screen and Overlay blending mode Screen blending mode is Photoshop’s most popular...

question_answer

Q: 2. Design a flowchart and a program for the following algorithm: input from the clerk the name of th...

A: Answer: 2. 2. a. Flowchart:  

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Program code: //import the required packagesimport java.util.Scanner; //define a class AtmSimDoLoopp...

question_answer

Q: How is the access control list in Unix handled?

A: Access Control List (ACL): An access control list is a list for each object consisting of the domain...

question_answer

Q: Create a python program for the attached flowchart:

A: #get the input from the user name=input("Enter the name:") debt1=int(input("Enter the value of debt1...

question_answer

Q: How to write a program in java that can read numbers from a text file into an array then output thes...

A: Use the object of scanner class to open the file and take integers from it to store in the array. Ca...

question_answer

Q: What is the difference between a Microsoft access database and an Excel spreadsheet by comparing the...

A: Difference between a Microsoft Access and an Excel Spreadsheet Microsoft Access and an Excel Spread...

question_answer

Q: write a java program which creates A magic square is an n x n matrix which, if filled with numbers, ...

A: //import the required packages import java.io.*; import java.util.Scanner; //Create a main class pub...

question_answer

Q: Find the theta notation for the number of times "x = x + 1" is executed.

A: Theta (Big Θ) notation:   Time complexity of an algorithm can be represented by the big theta notat...