C++ Please show me the sample output from your sreen. Thanks ! In this assignmen
ID: 3721470 • Letter: C
Question
C++ Please show me the sample output from your sreen. Thanks !
In this assignment, you will be developing a payroll program for a hospital. 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.
Explanation / Answer
#include <iostream>
using namespace std;
class StaffMember // abstract base class
{
private:
string name,address,phone;
public:
StaffMember(string name,string address,string phone)
{
this->name = name;
this->address = address;
this->phone = phone;
}
//get methods
string getName()
{
return name;
}
string getAddress()
{
return address;
}
string getPhone()
{
return phone;
}
//abstract methods
virtual void pay() = 0;
virtual void print() = 0;
};
//derived classes
class Volunteer : public StaffMember
{
public:
Volunteer(string name,string address,string phone):StaffMember(name,address,phone)
{
}
void pay()
{
cout<<"No Pay";
}
void print()
{
cout<<" Volunteer Name : "<<getName()<<" ";
cout<<"Address : "<<getAddress()<<" ";
cout<<"Phone : "<<getPhone()<<" ";
}
};
class Doctor : public StaffMember
{
private:
string ssn;
double payRate,surgeryCost;
int workHours,numSurgeries;
public:
Doctor(string name,string address,string phone,string ssn,double payRate,int workHours,int numSurgeries,double surgeryCost):StaffMember(name,address,phone)
{
this->ssn = ssn;
this->payRate = payRate;
this->workHours = workHours;
this->numSurgeries = numSurgeries;
this->surgeryCost = surgeryCost;
}
void pay()
{
cout<<payRate*workHours+numSurgeries*surgeryCost;
}
void print()
{
cout<<" Doctor Name : "<<getName()<<" ";
cout<<"Address : "<<getAddress()<<" ";
cout<<"Phone : "<<getPhone()<<" ";
cout<<"SSN : "<<ssn<<" ";
cout<<"Pay Rate : "<<payRate<<" ";
cout<<"Working Hours : "<<workHours<<" ";
cout<<"Number of surgeries : "<<numSurgeries<<" ";
cout<<"Cost of each Surgery : $"<<surgeryCost<<" ";
cout<<"Pay : ";
pay();
}
};
class Nurse : public StaffMember
{
private:
string ssn;
double payRate;
int workHours;
public:
Nurse(string name,string address,string phone,string ssn,double payRate,int workHours):StaffMember(name,address,phone)
{
this->ssn = ssn;
this->payRate = payRate;
this->workHours = workHours;
}
void pay()
{
cout<<payRate*workHours;
}
void print()
{
cout<<" Nurse Name : "<<getName()<<" ";
cout<<"Address : "<<getAddress()<<" ";
cout<<"Phone : "<<getPhone()<<" ";
cout<<"SSN : "<<ssn<<" ";
cout<<"Pay Rate : "<<payRate<<" ";
cout<<"Working Hours : "<<workHours<<" ";
cout<<"Pay : ";
pay();
}
};
class Executive : public StaffMember
{
private:
string ssn;
double payRate,bonus;
int workHours;
public:
Executive(string name,string address,string phone,string ssn,double payRate,int workHours,double bonus):StaffMember(name,address,phone)
{
this->ssn = ssn;
this->payRate = payRate;
this->workHours = workHours;
this->bonus = bonus;
}
void pay()
{
cout<<payRate*workHours+bonus;
}
void print()
{
cout<<" Executive Name : "<<getName()<<" ";
cout<<"Address : "<<getAddress()<<" ";
cout<<"Phone : "<<getPhone()<<" ";
cout<<"SSN : "<<ssn<<" ";
cout<<"Pay Rate : "<<payRate<<" ";
cout<<"Working Hours : "<<workHours<<" ";
cout<<"Bonus : $"<<bonus<<" ";
cout<<"Pay : ";
pay();
}
};
class Receptionist: public StaffMember
{
private:
string ssn;
double payRate;
int workHours;
public:
Receptionist(string name,string address,string phone,string ssn,double payRate,int workHours):StaffMember(name,address,phone)
{
this->ssn = ssn;
this->payRate = payRate;
this->workHours = workHours;
}
void pay()
{
cout<<payRate*workHours;
}
void print()
{
cout<<" Receptionist Name : "<<getName()<<" ";
cout<<"Address : "<<getAddress()<<" ";
cout<<"Phone : "<<getPhone()<<" ";
cout<<"SSN : "<<ssn<<" ";
cout<<"Pay Rate : "<<payRate<<" ";
cout<<"Working Hours : "<<workHours<<" ";
cout<<"Pay : ";
pay();
}
};
int main() {
StaffMember *staff[6];
staff[0] = new Volunteer("Diana","11 South Paris Hill Rd.","Phone: (984) 163-0125");
staff[1] = new Volunteer("Ryan", "625 Amerige Dr.","(750) 837-4154");
staff[2] = new Doctor("Dickson","311 Delaware Ave.","(275) 249-0721","047-86-8586", 150,160,3,10000);
staff[3] = new Nurse("Clarke","933 Honey Creek St.","(722) 521-3317","417-46-7995", 50.5,80);
staff[4] = new Nurse("Rose","99 Harvard St.","(672) 790-2499","517-42-5738",45.9,100);
staff[5] = new Receptionist("Sam","8426 Proctor St.","(301) 936-4987","365-07-9906",30,160);
staff[6] = new Executive("Anderson","6200 Seaside Dr.","(361) 956-4787","678-16-4701",130, 160,12000);
for(int i=0;i<6;i++)
{
staff[i]->print();
}
return 0;
}
Output:
Volunteer Name : Diana Address : 11 South Paris Hill Rd. Phone : 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 Working Hours : 160 Number of surgeries : 3 Cost of each Surgery : $10000 Pay : 54000
Nurse Name : Clarke Address : 933 Honey Creek St. Phone : (722) 521-3317 SSN : 417-46-7995 Pay Rate : 50.5 Working Hours : 80 Pay : 4040
Nurse Name : Rose Address : 99 Harvard St. Phone : (672) 790-2499 SSN : 517-42-5738 Pay Rate : 45.9 Working Hours : 100 Pay : 4590
Receptionist Name : Sam Address : 8426 Proctor St. Phone : (301) 936-4987 SSN : 365-07-9906 Pay Rate : 30 Working Hours : 160 Pay : 4800
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.