Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When XYZ Company started two years ago, the below payroll program was written to handle the payrolls of only salaried and hourly employees. As business

When XYZ Company started two years ago, the below payroll program was written to handle the payrolls of only salaried and hourly employees. As business expands, the company finds the need to hire sales people. For each pay period, a sales persons pay includes a base pay of $500.00 plus commission, which is five percent of the total sales generated by the sales person during each pay period. Since the original program is written in C++, an OOP language that supports inheritance, the existing program can be easily extended to meet the new business need for the company. Write the extended version by creating a new derived classes named salesEmployee that contains data members basePay, totalSales, and commissionRate. The newly added class also contains a member function that computes and displays the pay check. Write the main() function to generate the payrolls of all three types of employees. For your convenience, the code for the original program that handles only salariedEmployee and hourlyEmployee is provided below:

// Base class interface

class Employee

{

public:

Employee();

Employee(string the_name, string the_ssn);

string get_name() const;

string get_ssn() const;

double get_net_pay() const;

void set_name(string new_name);

void set_ssn(string new_ssn);

void set_net_pay(double new_net_pay);

void print_check() const;

protected:

string name;

string ssn;

double net_pay;

};

// Base Class implementation:

Employee::Employee() : name("No name yet"), ssn("No number yet"), net_pay(0)

{ }

Employee::Employee(string the_name, string the_number)

: name(the_name), ssn(the_number), net_pay(0)

{ }

string Employee::get_name() const

{ return name; }

string Employee::get_ssn() const

{ return ssn; }

double Employee::get_net_pay() const

{ return net_pay; }

void Employee::set_name(string new_name)

{ name = new_name; }

void Employee::set_ssn(string new_ssn)

{ ssn = new_ssn; }

void Employee::set_net_pay(double new_net_pay)

{ net_pay = new_net_pay; }

void Employee::print_check() const

{

cout << " Cannot print a check for an uncatagorized employee!" << endl;

}

// Derived Class: HourlyEmployee Interface

class HourlyEmployee : public Employee

{

public:

HourlyEmployee();

HourlyEmployee(string the_name, string the_ssn,

double the_wage_rate, double the_hours);

void set_rate(double new_wage_rate);

double get_rate() const;

void set_hours(double hours_worked);

double get_hours() const;

void print_check();

private:

double wage_rate;

double hours;

};

//Derived Class: HourlyEmployee implementation

HourlyEmployee::HourlyEmployee() : Employee(), wage_rate(0), hours(0)

{ }

HourlyEmployee::HourlyEmployee(string the_name, string the_number, double the_wage_rate, double the_hours)

: Employee(the_name, the_number), wage_rate(the_wage_rate), hours(the_hours)

{ }

void HourlyEmployee::set_rate(double new_wage_rate)

{ wage_rate = new_wage_rate; }

double HourlyEmployee::get_rate() const

{ return wage_rate; }

void HourlyEmployee::set_hours(double hours_worked)

{ hours = hours_worked; }

double HourlyEmployee::get_hours() const

{ return hours; }

void HourlyEmployee::print_check()

{

set_net_pay(hours * wage_rate);

cout << fixed << setprecision(2);

cout << " ________________________________________________ ";

cout << "Pay to the order of " << name << endl;

cout << "The sum of " << net_pay << endl;

cout << "________________________________________________ ";

cout << "Employee Number: " << ssn << endl;

cout << "Hourly Employee. Hours worked: " << hours << endl

<< "Hourly rate: $" << wage_rate << " Pay: $" << net_pay << endl;

cout << "_________________________________________________ ";

}

// Derived Class: SalariedEmployee interface

class SalariedEmployee : public Employee

{

public:

SalariedEmployee();

SalariedEmployee(string the_name, string the_ssn, double the_weekly_salary);

double get_salary() const;

void set_salary(double new_salary);

void print_check();

private:

double salary; //weekly

};

// Derived Class: SalariedEmployeemp iementation

SalariedEmployee::SalariedEmployee() : Employee(), salary(0)

{ }

SalariedEmployee::SalariedEmployee(string the_name, string the_number, double the_weekly_salary)

: Employee(the_name, the_number), salary(the_weekly_salary)

{ }

double SalariedEmployee::get_salary() const

{ return salary; }

void SalariedEmployee::set_salary(double new_salary)

{ salary = new_salary; }

void SalariedEmployee::print_check()

{

cout << fixed << setprecision(2);

set_net_pay(salary);

cout << " __________________________________________________ ";

cout << "Pay to the order of " << name << endl;

cout << "The sum of " << net_pay << " Dollars ";

cout << "_________________________________________________ ";

cout << "Employee Number: " << ssn << endl;

cout << "Salaried Employee. Regular Pay: $" << salary << endl;

cout << "_________________________________________________ ";

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

=+2 Why did OBI create Centers of Excellence?

Answered: 1 week ago