Professional Documents
Culture Documents
Asgmnt 03 Oop
Asgmnt 03 Oop
Total Marks: 04
Obtained Marks:
Object Oriented
Programming
Assignment # 03
Last date of Submission: 24 April 2019
Reg Number:
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Instructions:Copied or shown assignments will be marked zero. Late submissions are not
entertained in any case.
Question
A company pays its employees weekly. The employees are of four types:
Salaried employees are paid a fixed weekly salary regardless of the number of hours worked,
hourly employees are paid by the hour and receive overtime pay for all hours worked in
excess of 40 hours,
commission employees are paid a percentage of their sales
base-salary-plus-commission employees receive a base salary plus a percentage of their sales.
For the current pay period, the company has decided to reward base-salary-plus-commission
employees by adding 10 percent to their base salaries.
Manager works to assign the salary to Salaried employees. Assign Basic salary and per hour
wages to hourly employees. Assign percentage to commission employees and assign base salary,
commission percentage and bonus to base-salary-plus-commission employees.
1. Base class Employee is an abstract class and it should include data members representing the
name, address and social security number (SSN). It also includes virtual functions InsertData(),
PrintEmployee( ) and destructor.
2. Salaried is virtually inherited from class Employee. It has a static data member Salary(as it is
common for all the salaried employees). Include a static function SetSalary( ) to set salary value.
Override functions of InsertData() and PrintEmployee( ). In PrintEmployee( ) function Before
printing the employee data call CalculateSalary( ) function to calculate salary.
3. Hourly is virtually inherited from class Employee. It has a static data member
OvertimeSalaryPerHour and a non static data member hours. Include a static function
SetOvertimeSalary( ) to set OvertimeSalaryPerHour value. Override functions of InsertData(),
CalculateSalary( ) and PrintEmployee( ). In PrintEmployee( ) function Before printing the
employee data call CalculateSalary( ) function to calculate salary.
4. Commission is virtually inherited from class Employee. It has a static data member
CommissionRatio and a non static data member Sales. Include a static function
SetCommissionRatio( ) to set perecentage of the commission in CommissionRatio. Override
functions of InsertData(), CalculateSalary( ) and PrintEmployee( ). In PrintEmployee( ) function
Before printing the employee data call CalculateSalary( ) function to calculate salary.
5. Salary-plus-Commission is virtually inherited from class Employee. It has three static data
members Salary, CommissionRatio, BonusRatio. Initialize BonusRatio as 10. Include a non static
data member Sales as well. Include Three static functions SetCommissionRatio( ) and SetSalary( )
and SetBonusRatio( ) to set perecentage of the commission, bonus and basic salary of employee.
Override functions of InsertData(), CalculateSalary( ) and PrintEmployee( ). In PrintEmployee( )
function Before printing the employee data call CalculateSalary( ) function to calculate salary.
6. Manager is virtually inherited class from Salaried, Hourly, Commission and Salary-plus-
Commission classes. Override InsertData() function which calls all the static functions of parent
classes to set their static values. Also override PrintEmployee( ) to print static data of all the
parent classes.
#include<iostream>
#include<string>
using namespace std;
class employee
{
public:
string name;
string address;
int ssn;
virtual void insertdata()
{
cout << "Enter name, address and SSN: " << endl;
cin >> name;
cin >> address;
cin >> ssn;
}
virtual void printemployee()
{
cout << "Employee Data: \n";
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Social security number: " << ssn << endl;
}
~employee()
{
cout << "Process Ended" << endl;
Object Oriented Programming BS(SE)-2 SZABIST-ISB
Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology
}
};
class salaried :public virtual employee
{
public:
string name;
string address;
int ssn;
static int salary;
static void setsalary()
{
cout << "Enter salary:" << endl;
cin >> salary;
}
virtual void insertdata()
{
cout << "Enter name, address and SSN: " << endl;
cin >> name;
cin >> address;
cin >> ssn;
setsalary();
}
virtual void calculatesalary()
{
cout << "Salary: " << 0.3*salary << endl;
}
virtual void printemployee()
{
cout << "Employee Data: \n";
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Social security number: " << ssn << endl;
calculatesalary();
Object Oriented Programming BS(SE)-2 SZABIST-ISB
Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology
};
int salaried::salary = 0;
class hourly :public virtual employee
{
public:
string name;
string address;
int ssn;
static int overtimesalaryperhour;
int hours;
static void setovertimesalary()
{
cout << "Enter overtime salary per hour: " << endl;
cin >> overtimesalaryperhour;
}
virtual void insertdata()
{
cout << "Enter name, address and SSN: " << endl;
cin >> name;
cin >> address;
cin >> ssn;
setovertimesalary();
cout << "Enter hours: " << endl;
cin >> hours;
}
virtual void calculatesalary()
{
setcommissionratio();
}
}
static void setbonusratio()
{
bonusratio = 10;
}
virtual void insertdata()
{
cout << "Enter name, address and SSN: " << endl;
cin >> name;
cin >> address;
cin >> ssn;
setsalary();
setcommission();
setbonusratio();
}
virtual void calculatesalary()
{
cout << "Salary: " << ((salary*commissionratio*bonusratio) + sales) << endl;
}
virtual void printemployee()
{
cout << "Employee Data: \n";
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Social security number: " << ssn << endl;
calculatesalary();
}
};
float pluscommission::salary = 0;
float pluscommission::bonusratio = 0;
float pluscommission::commissionratio = 0;
class Manager : public virtual employee, public virtual salaried, public virtual hourly, public
virtual commission, public virtual pluscommission
{
public:
string name;
string address;
int ssn;
virtual void insertdata()
{
cout << "Enter name, address and SSN: " << endl;
cin >> name;
cin >> address;
cin >> ssn;
hourly::setovertimesalary();
commission::setcommissionratio();
pluscommission::setcommission();
pluscommission::setsalary();
pluscommission::setbonusratio();
}
virtual void calculatesalary()
{
cout << "Salary: " << salaried::salary << endl;
}
virtual void printemployee()
{
cout << "Employee Data: \n";
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Social security number: " << ssn << endl;
calculatesalary();
cout << "Overtime salary: " << hourly::overtimesalaryperhour << endl;
cout << "Commission Ratio: " << commission::commissionratio << endl;
{
emp = &h;
emp->insertdata();
emp->printemployee();
}
else if (choice == 4)
{
emp = &c;
emp->insertdata();
emp->printemployee();
}
else if (choice == 5)
{
emp = &spc;
emp->insertdata();
emp->printemployee();
}
else if (choice == 6)
{
emp = &m;
emp->insertdata();
emp->printemployee();
}
} while (choice != 0);
system("pause");
return 0;
}