0% found this document useful (0 votes)
71 views8 pages

Zaheer Ul Islam FA19-BEE-015: A) Variables: Private: Width

The document describes three programming questions that involve object-oriented concepts like classes, inheritance, polymorphism, and virtual functions. For question 1, it asks to create classes for Width, Length, and Height with private member variables and constructors, and a function to calculate volume using objects of these classes. Question 2 involves creating an Employee class with name, number, and hire date, a ProductionWorker class derived from Employee with additional data, and a TeamLeader class derived from ProductionWorker with extra functions like calculating salary and bonuses. Question 3 asks to create a base Ship class with name and year, derive CruiseShip and CargoShip classes from it with additional data, and demonstrate polymorphism using a

Uploaded by

Umar Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views8 pages

Zaheer Ul Islam FA19-BEE-015: A) Variables: Private: Width

The document describes three programming questions that involve object-oriented concepts like classes, inheritance, polymorphism, and virtual functions. For question 1, it asks to create classes for Width, Length, and Height with private member variables and constructors, and a function to calculate volume using objects of these classes. Question 2 involves creating an Employee class with name, number, and hire date, a ProductionWorker class derived from Employee with additional data, and a TeamLeader class derived from ProductionWorker with extra functions like calculating salary and bonuses. Question 3 asks to create a base Ship class with name and year, derive CruiseShip and CargoShip classes from it with additional data, and demonstrate polymorphism using a

Uploaded by

Umar Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

ZAHEER UL ISLAM

FA19-BEE-015
QUESTION 1
Write a class Width that has the following member variables and functions.

a) Variables: private: width;


Functions: A constructor to initialize the variables.

Similarly write a class Length and class Height that have private member variables length
and height respectively and constructor to initialize length and height.

Write a stand alone function Volume ( ) that will receive three objects of type Width, Length
and Height and will find out the volume by returning the product of private members of
these three objects.

PROGRAM
QUESTION 2
Design a class named Employee . The class should keep the following information in

• Employee name

• Employee number

• Hire date

Write one or more constructors and the appropriate accessor and mutator functions for the class.

Next, write a class named ProductionWorker that is derived from the Employee class. The
ProductionWorker class should have member variables to hold the following information:

• Shift (an integer)

• Hourly pay rate (a double )

The workday is divided into two shifts: day and night. The shift variable will hold an integer value
representing the shift that the employee works. The day shift is shift 1, and the night shift is shift 2.
Write one or more constructors and the appropriate accessor and mutator functions for the class.

Member function Calculate_salary() will calculate the salary. Ask the user to enter hours worked and
then find the salary as follows:

Shift 1: salary = hourly pay rate* hours;


Shift 2: salary = (hourly pay rate + 50% of hourly pay rate) * hours;

TeamLeader Class

In a particular factory, a team leader is an hourly paid production worker who leads a small team. In
addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a
minimum number of hours of training per year. Design a TeamLeader class that extends the
ProductionWorker class The TeamLeader class should have member variables for the monthly
bonus amount, the required number of training hours (15), and the number of training hours that
the team leader has attended. Write one or more constructors and the appropriate accessor and
mutator functions for the class.

Member function Monthly_bonus() will ask the user for number of training hours attended and
then calculate the monthly bonus as follows:

If (training hourse attended>=training hours) then monthly bonus = salary * 15%

Else monthly bonus = 0;

Member function Net_salary() will calculate the net salary as follows:

Salary = salary + monthly bonus

Note: salary is calculated using Calculate_salary() function defined in Productionworker class.

Demonstrate the class by writing a program that uses a TeamLeader object. Declare and initialize 5
objects of type TeamLeader. Then calculate monthly bonus for each object. Finally, calculate the
net salary for each object.

Write a main function that declares an array of Employee pointers having size 3. The array elements
should be initialized using constructor with the addresses of dynamically allocated
Productionworker and TeamLeader class .objects as discussed in program 15-14 on slide 37 of
lecture “polymorphism_virtual functions”. The program should then step through the array, calculates
the salary of each object and displays it.

PROGRAM
QUESTION 3
Design a Ship class that has the following members:
• A member variable for the name of the ship (a string)

• A member variable for the year that the ship was built (a string)

• A constructor and appropriate accessors and mutators

• A virtual print function that displays the ship’s name and the year it was built.

Design a CruiseShip class that is derived from the Ship class. The CruiseShip class

should have the following members:

• A member variable for the maximum number of passengers (an int )

• A constructor and appropriate accessors and mutators

• A print function that overrides the print function in the base class. The CruiseShip

class’s print function should display only the ship’s name and the maximum number

of passengers.

Design a CargoShip class that is derived from the Ship class. The CargoShip class

should have the following members:

• A member variable for the cargo capacity in tonnage (an int ).

• A constructor and appropriate accessors and mutators.

• A print function that overrides the print function in the base class. The CargoShip

class’s print function should display only the ship’s name and cargo capacity in tonnage.

Write a main function that declares an array of Ship pointers having size 3. The array elements
should be initialized using constructor with the addresses of dynamically allocated Ship ,
CruiseShip , and CargoShip objects as discussed in program 15-14 on slide 37 of lecture
“polymorphism_virtual functions”. The program should then step through the array, calling each
object’s print function.

PROGRAM

You might also like