Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Total Marks: 04

Obtained Marks:

Object Oriented
Programming
Assignment # 03
Last date of Submission: 24 April 2019

Submitted To: Muhammad Usman


______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Student Name: ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Reg Number:
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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.

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT


Write a test program in main and Apply Polymorphism using base class Employee pointer which
works dynamically (on user choice) for all types of employee(derived classes). Call InsertData()
and PrintEmployee( ) function for any type of object. Manager can only set and view all static
data members of all the classes while other employee can set their personal data and view all the
data including their calculated salary of that week. Your programs should run as long as user
wants (apply do while loop).
Solution:

#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

COMPUTER SCIENCE DEPARTMENT

}
};
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

COMPUTER SCIENCE DEPARTMENT

};
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()
{

cout << "Salary: " << overtimesalaryperhour*hours << endl;


}

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

virtual void printemployee()


{
cout << "Employee Data: \n";
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Social security number: " << ssn << endl;
calculatesalary();
}
};
int hourly::overtimesalaryperhour = 0;
class commission :public virtual employee
{
public:
string name;
string address;
int ssn;
static float commissionratio;
float sales=55;
static void setcommissionratio()
{
cout << "Enter commission ratio: " << endl;
cin >> commissionratio;
}
virtual void calculatesalary()
{
cout << "Salary: " << sales*commissionratio << endl;
}
virtual void insertdata()
{
cout << "Enter name, address and SSN: " << endl;
cin >> name;
cin >> address;
cin >> ssn;
Object Oriented Programming BS(SE)-2 SZABIST-ISB
Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

setcommissionratio();
}

virtual void printemployee()


{
cout << "Employee Data: \n";
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Social security number: " << ssn << endl;
calculatesalary();
cout << "Sales(%): " << sales << endl;
}
};
float commission::commissionratio = 0;
class pluscommission :public virtual employee
{
public:
string name;
string address;
int ssn;
static float salary;
static float commissionratio;
static float bonusratio;
float sales=58;
static void setcommission()
{
cout << "Enter commission: " << endl;
cin >> commissionratio;
}
static void setsalary()
{
cout << "Enter salary %age: " << endl;
cin >> salary;

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

}
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;

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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;

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

cout << "Bonus Ratio: " << pluscommission::bonusratio << endl;


}
};
int main()
{
int choice;
employee *emp, emp1;
salaried s;
hourly h;
commission c;
pluscommission spc;
Manager m;
cout << "==========Salary Management System==========" << endl;
do
{

cout << " \n\nChoose type:- " << endl;


cout << "1. Employees \n2. Salaried \n3. Hourly \n4. Commission \n5. Salary-
plus-Commission \n6. Manager \n0. EXIT" << endl;
cout << "Enter type: " << endl;
cin >> choice;
if (choice == 1)
{
emp1.insertdata();
emp1.printemployee();
}
else if (choice == 2)
{
emp = &s;
emp->insertdata();
emp->printemployee();
}
else if (choice == 3)

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

{
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;
}

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Object Oriented Programming BS(SE)-2 SZABIST-ISB


Shaheed Zulfiqar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Object Oriented Programming BS(SE)-2 SZABIST-ISB

You might also like