Abdullah Farooq F2023266160 Lab Manual 14
Abdullah Farooq F2023266160 Lab Manual 14
Lab- 14 Manual
Lab Instructor: Riaz Ahmad
Department of Computer Science
Email: [email protected]
Question 1:
In this task, you have to develop a simple payroll application. In this company there are three
kinds of employees: i) salaried employee, ii) hourly employee, and iii) commissioned employee.
Derive salaried employee (have fixed monthly salary), hourly employee (salary computed on
hourly basis), and commissioned employee (salary is based on commission on each sale) from
base class Employee.
Formula to compute NetSalary: salary-taxRate
For example:
computedSalary = 35000, taxRate = 5%
35000*5/100 = 1750
NetSalary = 35000-1750= 33250
#include<iostream>
using namespace std;
class Employee {
protected:
int main() {
cout << "NAME" << " " << "Net Salary\n";
SalariedEmp sE(55000.00, "Abdullah Farooq", 5.0);
sE.calcNetSalary();
HourlyEmp hE(11, 8000, "Ali", 5.0);
hE.calcNetSalary();
CommEmp cE(17, 0.09, "Zeeshan", 5.0);
cE.calcNetSalary();
return 0;
}
Output Format:
Name Net Salary
Aamir 14250
Fakhir 7520
Fuaad 14400 ……
Question 2:
Implement a shape hierarchy in this task. You must have your super class shape and 2
subclasses two-dimensional shape and three-dimensional shape. Under two-dimensional
shape, you have other subclasses circle and square. Under the three-dimensional shape you
class Shape {
public:
virtual double getArea() {
return 0;
}
};
int main() {
Circle c(8.5);
cout << "Area of circle: " << c.getArea() << endl;
Square s(7.5);
cout << "Area of square: " << s.getArea() << endl;
Cube cb(4.7);
cout << "Area of cube: " << cb.getArea() << endl;
cout << "Volume of cube: " << cb.getVolume() << endl;
return 0;
}
Question 3:
1. ADT:NumDays
Design aclasscalled NumDays. Theclass’spurposeisto storeavaluethat
representsanumberofworkhoursandconvert it to anumberofdays.
Forexample,8 hours wouldbeconvertedto1 day, 12hours wouldbe convertedto1.5 days,and18
hours wouldbeconvertedto2.25days. The class should have a constructor that accepts a
number of hours, as well as member functions for storing and retrieving thehoursanddays.
Theclassshouldalsohavethefollowingoverloadedoperators:
Additionoperator(+):WhentwoNumDaysobjectsareaddedtogether,theoverloaded+operatorsh
ouldreturnthesumof thetwoobjects’hoursmembers.
Subtractionoperator(–):WhenoneNumDaysobjectissubtractedfromanother,theoverloaded–
operatorshouldreturnthedifferenceof thetwoobjects’hoursmembers.
Prefixandpostfixincrementoperators(+
+):Theseoperatorsshouldincrementthenumberofhoursstoredintheobject.Whenincremented,th
enumberof days should beautomaticallyrecalculated.
Prefixandpostfixdecrementoperators(--):Theseoperatorsshoulddecrementthenumberofhoursst
oredintheobject.When decremented,thenumberofdays should beautomaticallyrecalculated.
ADT:TimeOff
DesignaclassnamedTimeOff.Thepurposeoftheclassistotrackanemployee’ssickleave,vacation,
andunpaidtimeoff.Itshouldhave,asmembers,the followinginstances of theNumDaysclass:
ANumDaysobjectthatrecordsthemaximumnumberofdaysofunpaidvacationtheemployeemayt
ake.unpaidTaken ANumDaysobjectthatrecordsthenumberofdays
ofunpaidleavetheemployeehastaken.
Additionally,theclassshouldhavemembersforholdingtheemployee’snameandidentificationnu
mber.Itshouldhaveanappropriateconstructorandmemberfunctionsforstoringandretrievingdatai
nanyofthememberobjects.
InputValidation:Companypolicystatesthatanemployeemaynotaccumulatemorethan240hourso
fpaidvacation.Theclassshouldnotallow themaxVacationobjecttostoreavalue greaterthan this
amount.
PersonnelReport:ADriverProgram
WriteaprogramthatusesaninstanceoftheTimeOffclassyoudesignedaboveandperformthefollow
ing.
Theprogramshouldasktheusertoenterthenumberofmonthsanemployeehasworkedforthecompa
ny.
Itshould
thenusetheTimeOffobjecttocalculateanddisplaytheemployee’smaximumnumberofsickleavea
ndvacationdays.
Note:Employeesearn12hoursofvacationleaveand8hoursofsickleavepermonth.1
#include <iostream>
using namespace std;
class NumDays {
private:
double hours;
public:
NumDays(double h = 0.0) {
hours = h;
}
void setHours(double h) {
hours = h;
}
double getHours() {
return hours;
}
double getDays() {
return hours / 8.0;
}
NumDays operator+(NumDays &obj) {
NumDays temp;