Using C++ programming, In this assignment, you will be developing a payroll prog
ID: 3718758 • Letter: U
Question
Using C++ programming,
In this assignment, you will be developing a payroll program for a hospital using polymorphism and inheritence. The program calculates the salaries for employees and volunteers. The program uses the following classes to achieve this goal:
- The StaffMember class: an abstract class that does not represent a particular type of employee or volunteer.
- The Volunteer class: Volunteers work on special events and they are not paid. So, this class represents a person who is not compensated monetarily for his or her work. It keeps track of only the basic information of a volunteer.
- The Employee class: represents an employee who gets paid at a particular rate each pay period.
- The Doctor class: represents an employee who earns 10% of the total costs of each surgery he or she may perform in addition to the normal pay rate. - The Nurse class: represents an employee who is paid on hourly basis.
- The Executive class: represents an employee who may earn a bonus in addition to his or her normal pay rate.
- The Receptionist class: represents an employee who is paid a normal pay rate only.
- The driver program mainHospital.cpp (main()) creates a staff of employees and calls the pay() function to pay them. When the program is run, it should display the information about each employee and how much he/she should be paid. Also, the program will create volunteers. Create the following StaffMember objects in order to find their pay rates:
Volunteer: Name: Diana, Address: 11 South Paris Hill Rd., Phone: (984) 163-0125.
Volunteer: Name: Ryan, Address: 625 Amerige Dr., Phone: (750) 837-4154.
Doctor: Name: Dickson, Address: 311 Delaware Ave., Phone: (275) 249-0721, SSN: 047-86-8586, Pay Rate: $150/hr, Number of working hours: 160, Surgeries: 3, Cost of each surgery: $10,000.
Nurse: Name: Clarke, Address: 933 Honey Creek St., Phone: (722) 521-3317, SSN: 417-46-7995, Pay Rate: $50.5/hr, Number of working hours: 80.
Nurse: Name: Rose, Address: 99 Harvard St., Phone: (672) 790-2499, SSN: 517-42-5738, Pay Rate: $45.9/hr, Number of working hours: 100.
Receptionist: Name: Sam, Address: 8426 Proctor St., Phone: (301) 936-4987, SSN: 365-07-9906, Pay Rate: $30/hr, Number of working hours: 160.
Executive: Name: Anderson, Address: 6200 Seaside Dr., Phone: (361) 956-4787, SSN: 678-16-4701, Pay Rate: $130/hr, Number of working hours: 160, Bonus: $12,000.
Be sure to create your make file as well!
Explanation / Answer
Solution:
code:
//Staffmember.H
#ifndef STAFFMEMBER_H
#define STAFFMEMBER_H
#include<iostream>
#include<conio.h>
#include<string.h>
#include<string>
using namespace std;
class StaffMember
{
string name;
string address;
string phoneNumber;
public :
virtual void Pay() = 0; // pure virtual function
void Display() // function to display info
{
cout<< " Name : " << name << " ";
cout<< " Address : " << address << " ";
cout<< " Phone Number : " << phoneNumber << " ";
}
StaffMember()
{
}
StaffMember(string a,string b, string c) // constructors
{
name = a;
address = b;
phoneNumber = c;
}
string getName()
{
return name;
}
void setName(string n)
{
name = n;
}
string getaddress()
{
return address;
}
void setaddress(string n)
{
address = n;
}
string getphoneNumber()
{
return phoneNumber;
}
void setphoneNumber(string n)
{
phoneNumber = n;
}
};
class Volunteer : public StaffMember
{
public:
Volunteer() : StaffMember() {}
Volunteer(string n, string a, string p) : StaffMember(n,a,p) {}
void Pay()
{
cout<<" Pay : No salary info ";
}
};
class Employee : public StaffMember
{
private:
double payRate;
int numberofHours;
string ssn;
public:
Employee() : StaffMember() {}
Employee(string n, string a, string p, double r, int h, string s) : StaffMember(n,a,p) { payRate = r; numberofHours = h; ssn =s;}
void Pay()
{
cout<<" Pay : " << payRate * numberofHours << " ";
}
double salary()
{
return payRate * numberofHours;
}
void DisplaySSN()
{
cout<< " SSN : " << ssn << " ";
}
};
class Doctor : public Employee
{
int surgeries;
double costOfSurgery;
public:
Doctor() : Employee() {}
Doctor(string n, string a, string p, double r, int h, int s, double c, string ssn) : Employee(n,a,p,r,h,ssn) {surgeries = s; costOfSurgery= c;}
void Pay()
{
DisplaySSN();
double totalPay = salary() + ((surgeries * costOfSurgery) * 10) / 100 ;
cout <<" Pay : " << totalPay << " ";
}
};
class Nurse : public Employee
{
public:
Nurse() : Employee() {}
Nurse(string n, string a, string p, double r, int h, string ssn) : Employee(n,a,p,r,h,ssn) {}
void Pay()
{
DisplaySSN();
double totalPay = salary();
cout <<" Pay : " << totalPay << " ";
}
};
class Executive : public Employee
{
double bonus;
public:
Executive() : Employee() {}
Executive(string n, string a, string p, double r, int h, double b, string ssn) : Employee(n,a,p,r,h,ssn) {bonus = b;}
void Pay()
{
DisplaySSN();
double totalPay = salary() + bonus;
cout <<" Pay : " << totalPay << " ";
}
};
class Receptionist : public Employee
{
public:
Receptionist() : Employee() {}
Receptionist(string n, string a, string p, double r, int h, string ssn) : Employee(n,a,p,r,h,ssn) {}
void Pay()
{
DisplaySSN();
double totalPay = salary();
cout <<" Pay : " << totalPay << " ";
}
};
#endif
// Main Program
// Hospital.cpp
#include<iostream>
#include<conio.h>
#include<string.h>
#include<string>
#include "StaffMember.h" // all class declarations are defined in header file
using namespace std;
int main()
{
StaffMember *v = new Volunteer(); // create a staff object of Volunteer
v->setName("Diana");
v->setaddress("11 South Paris Hill Rd.");
v->setphoneNumber("(984) 163-0125");
v->Display();
v->Pay();
cout<<" ";
StaffMember *v1 = new Volunteer(); // create a staff object of Volunteer
v1->setName("Ryan");
v1->setaddress("625 Amerige Dr.");
v1->setphoneNumber("(750) 837-4154");
v1->Display();
v1->Pay();
cout<<" ";
StaffMember *d = new Doctor("Gene","311 Delaware Ave.","(275) 249-0721",150.0,160,3,10000,"047-86-8586"); // create a staff object of doctor
d->Display();
d->Pay();
cout<<" ";
StaffMember *n1 = new Nurse("Raye","933 Honey Creek St.","(722) 521-3317",50.5,80,"417-46-7995"); // create a staff object of nurse
n1->Display();
n1->Pay();
cout<<" ";
StaffMember *n2 = new Nurse("Kristopher","99 Harvard St.","(672) 790-2499",45.9,100,"517-42-5738"); // create a staff object of nurse
n2->Display();
n2->Pay();
cout<<" ";
StaffMember *r = new Receptionist("Sam","8426 Proctor St.","(275) 249-0721",30,160,"365-07-9906"); // create a staff object of Receptionist
r->Display();
r->Pay();
cout<<" ";
StaffMember *e = new Executive("Sean","6200 Seaside Dr.","(361) 956-4787",130,160,12000,"678-16-4701"); // create a staff object of Executive
e->Display();
e->Pay();
cout<<" ";
return 0;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.