Zaheer Ul Islam FA19-BEE-015: A) Variables: Private: Width
Zaheer Ul Islam FA19-BEE-015: A) Variables: Private: Width
FA19-BEE-015
QUESTION 1
Write a class Width that has the following member variables and functions.
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:
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:
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:
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 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
• 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
• 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