Question

Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class...

Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class (which inherits from the Employee class) for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find the average net pay for a small company. To define the class, include the appropriate data members, member functions, constructors, and access modifiers. For simplicity, use a constant tax rate of 30% to compute the tax amount. Employees that work over 40 hours will receive overtime pay of one and a half of their hourly rate for overtime hours worked. The output should display the name of each employee, hours worked, hourly rate, overtime pay, regular (gross) pay, tax amount, and net pay. Create a salaried employee class (which inherits from the Employee class) which hold the annual salary of the employee. To define the class, include the appropriate data members, member functions, constructors, and access modifiers. Figure weekly pay by dividing the annual salary by 52. The output for the salaried employee should display the name, gross pay, tax amount (compute at 30%), and net pay. Write a test program with an array of 6 payroll objects: 3 hourlyEmployee objects and 3 salaried employees objects. The data for the 6 objects should be “hard-coded” into the program

Should have three files

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

//================================

//Save file as employee.h

//================================

#ifndef EMPLOYEE_H_
#define EMPLOYEE_H_
#include<iostream>
#include<string>
#define TAX_RATE 30 //30%

using namespace std;
class Employee
{
private:
string name, department, title;
public:
Employee(string n, string d, string t) : name(n), department(d), title(t){}

string getName();


string getDepartment();


string getTitle();

};

class hourlyEmployee : public Employee
{
private:
int hoursWorked;
double hourlyRate, overtime;
public:
//Constructor
hourlyEmployee(string n, string d, string t, int hours, double rate) : Employee(n, d, t), hoursWorked(hours), hourlyRate(rate), overtime(0)
{
if(hours > 40)
overtime = hoursWorked - 40;
}

//Function to get overtime pay
double getOvertimePay();

//Function to get gross pay
double getGrossPay();


//Function to get Tax amount
double getTaxAmount();


//Function to get net pay
double getNetPay();


//Function to print details of employee
void print();

};


class salariedEmployee : public Employee
{
private:
double salary;
public:
//Constructor
salariedEmployee(string n, string d, string t, double s) : Employee(n, d, t), salary(s){}

//Function to get gross pay
double getGrossPay();


//Function to get Tax amount
double getTaxAmount();


//Function to get net pay
double getNetPay();


//Function to print details of employee
void print();

};


#endif /* EMPLOYEE_H_ */

//================================

//Save file as employee.cpp

//================================

#include<iostream>
#include "employee.h"
using namespace std;
string Employee::getName()
{
return name;
}

string Employee::getDepartment()
{
return department;
}

string Employee::getTitle()
{
return title;
}
double hourlyEmployee::getOvertimePay()
{
return overtime*hourlyRate*1/3;
}
//Function to get gross pay
double hourlyEmployee::getGrossPay()
{
return (hoursWorked*hourlyRate + getOvertimePay());
}

//Function to get Tax amount
double hourlyEmployee::getTaxAmount()
{
return getGrossPay()*TAX_RATE/100;
}

//Function to get net pay
double hourlyEmployee::getNetPay()
{
return (getGrossPay() - getTaxAmount());
}

//Function to print details of employee
void hourlyEmployee::print()
{
cout<<"Name: "<<getName()<<endl;
cout<<"Hours worked: "<<hoursWorked<<", hourlyRate: $"<<hourlyRate<<", Overtime pay: $"<<getOvertimePay()<<", Gross Pay: $"<<getGrossPay()
<<", Tax amount: $"<<getTaxAmount()<<", Net Pay: $"<<getNetPay()<<endl;
}
//Function to get gross pay
double salariedEmployee::getGrossPay()
{
return salary/52;//Get weekly gross pay
}

//Function to get Tax amount
double salariedEmployee::getTaxAmount()
{
return getGrossPay()*TAX_RATE/100;
}

//Function to get net pay
double salariedEmployee::getNetPay()
{
return (getGrossPay() - getTaxAmount());
}

//Function to print details of employee
void salariedEmployee::print()
{
cout<<"Name: "<<getName()<<endl;
cout<<"Gross Pay: $"<<getGrossPay()<<", Tax amount: $"<<getTaxAmount()<<", Net Pay: $"<<getNetPay()<<endl;
}

//================================

//Save file as main.cpp

//================================

#include<iostream>
#include<string>
#include "employee.cpp"
using namespace std;

#define TAX_RATE 30 //30%


int main()
{
double avgNetPay = 0;//To calculate average net pay of the company
hourlyEmployee he[3] = { {"Jack", "Labour", "Mr. ", 35, 2.5},
{"Alice", "Labour", "Miss. ", 42, 3.25},
{"John", "Labour", "Mr. ", 61, 3.75},
};

salariedEmployee se[3] = { {"Ben", "Sales", "Mr. ", 100000},
{"Adam", "Management", "Mr. ", 125000},
{"Jack", "Sales", "Mr. ", 120000},
};
cout<<"Hourly employee details: ";
for(int i = 0; i < 3; i++)
{
he[i].print();
cout<<endl;
avgNetPay += he[i].getNetPay();
}
cout<<"Salaried employee details: ";
for(int i = 0; i < 3; i++)
{
se[i].print();
cout<<endl;
avgNetPay += se[i].getNetPay();
}

avgNetPay /= 6;

cout<<" Average net pay of the company: $"<<avgNetPay<<endl;
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...

    Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee...

    Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee number, employee name, hourly pay rate, regular hours worked and overtime hours worked. The company pays its employees weekly, according to the following rules: regular pay = regular hours worked × hourly rate of pay overtime pay = overtime hours worked × hourly rate of pay × 1.5 total pay = regular pay + overtime pay Your program is to read the input data...

  • C# visual studio This project tests your skills at building an Object-Oriented Programming project. The purpose...

    C# visual studio This project tests your skills at building an Object-Oriented Programming project. The purpose is to calculate pay for various types of employees. Use your same file for your [Your Name] Review.cs that contains your 2D Shape classes. Submit only your [Your Name] Review.cs file. The classes will contain: Employee Abstract class with the following properties: EmployeeId int FirstName string LastName string Pay (abstract, read only) double Sales Concrete class inherits Employee. Contains the following properties: Draw double...

  • C++ HELP! Create a class and name it Payslip. This class should have the following attributes...

    C++ HELP! Create a class and name it Payslip. This class should have the following attributes or properties: name, pay grade, basic salary, overtime hours, overtime pay, gross pay, net pay and withholding tax. Define the accessors and mutators of the Payslip class based on its attributes or properties. This class should also have the following methods: determinePayGradeAndTaxRate and computePay. Create another class and name it Employee. This class will contain the main method. In the main method, instantiate an...

  • Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate...

    Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate the weekly paycheck for both Salaried and Hourly employees. Salaried employees will be paid 1/52 of their annual pay minus 18% withheld for federal and state taxes, as well as 4% for retirement pension. Salaried employees do not collect overtime pay. There are two types of Hourly employees; permanent employees and temporary weekly employees. •Permanent weekly employees will be paid their hourly rate minus...

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

  • Questions:(to be answered within the video) Write a C++ program with the following specifications: 1. Create...

    Questions:(to be answered within the video) Write a C++ program with the following specifications: 1. Create a class and name it Payslip. This class should have the following attributes or properties: name,pay grade, basic salary, overtime hours, overtime pay, gross pay, net pay and withholding tax. 2. Define the accessors and mutators of the Payslip class based on its attributes or properties.  This class should also have the following methods: determinePayGradeAndTaxRate and computePay. 3. Create another class and name it Employee.  This...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT