Question

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 the employee’s
gross pay, so this information can be displayed. Sample data to test this program can be
found in the payroll.dat file.

To create the payroll.dat file, please open notepad, copy/paste the following data and save the file as payroll.dat file. Please make sure to save the file in a place where your program file is located. In otherwords, please do not hard code the path for the payroll.dat .

40.0 10.00
38.5 9.50
16.0 7.50
22.5 9.50
40.0 8.00
38.0 8.00
40.0 9.00

sample output.

Employee 1: 400.00

Employee 2: 365.75

Employee 3: 120.00

Employee 4: 213.75

Employee 5: 320.00

Employee 6: 304.00

Employee 7: 360.00

Homework Answers

Answer #1

Answer code with explanation in comments:

#include <iostream>

using namespace std;

// Payroll class
class Payroll {
public:
// Instance variables.
double hourlyPayRate;   
double hoursWorked;
  
// Constructor.
Payroll(double hourlyPayRate, double hoursWorked)
{
this->hourlyPayRate = hourlyPayRate;
this->hoursWorked = hoursWorked;
}
  
// getGrossPay() method to return Gross Pay of the Employee.
double getGrossPay()
{
return (this->hourlyPayRate)*(this->hoursWorked);
}
  
// Empty Constructor.
Payroll()
{}
};

// main function.
int main()
{
// variables to read from the file.
char hourlyPayRate[100];
char hoursWorked[100];
  
// Declaring 7 Payroll objects.
Payroll* payroll = new Payroll[7];
  
// Opening the file in read mode.
FILE* ptr = fopen("payroll.dat","r");
int i=0;
// Reading the file line by line and initializing each payroll object.
while (fscanf(ptr, "%s %s", hourlyPayRate, hoursWorked)==2)
{
payroll[i] = Payroll(stod(hourlyPayRate), stod(hoursWorked));
i++;
}
  
// Printing the gross pay for each Employee in format as required.
for(int i=0; i<7; i++)
printf("Employee %d: %0.2lf\n", i+1, payroll[i].getGrossPay());
  
return 0;
}

Screenshots:

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
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...
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Write a C program Design a program that uses an array to store 10 randomly generated...
Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...
Payroll Management System C++ The project has multiple classes and sub-classes with numerous features within them....
Payroll Management System C++ The project has multiple classes and sub-classes with numerous features within them. Basic operations users can perform via this program project that are based on file handling are adding new employee record, modifying employee record and deleting record, displaying one or all employee’s record. Besides these, payroll management also allows users to print the salary slip for a particular employee. Features: 1. Addition of New Employee: You can find this feature under the public category of...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT