0% found this document useful (0 votes)
102 views

Object Oriented Programming Lab

The document provides instructions for an object oriented programming lab assignment with multiple tasks. The tasks involve: 1) Creating an Employee class with name data and a print method, and inheriting from it a HourlyWorker class with wage and hours data and a pay calculation method. 2) Implementing an animal inheritance hierarchy with classes for Animal, Reptile, Bird, Mammal, Snake, Parrot and Horse, with id data and methods like getFamily and tellAboutSelf. 3) Overriding methods like speak in the subclasses and calling object methods in a main method.

Uploaded by

Haris Hassan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Object Oriented Programming Lab

The document provides instructions for an object oriented programming lab assignment with multiple tasks. The tasks involve: 1) Creating an Employee class with name data and a print method, and inheriting from it a HourlyWorker class with wage and hours data and a pay calculation method. 2) Implementing an animal inheritance hierarchy with classes for Animal, Reptile, Bird, Mammal, Snake, Parrot and Horse, with id data and methods like getFamily and tellAboutSelf. 3) Overriding methods like speak in the subclasses and calling object methods in a main method.

Uploaded by

Haris Hassan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Object Oriented Programming Lab Lab 09

O b j e c t O r i e n t e Lab
d MidPTask02
r o gr a m m i n g L a b
Lab 09 Marks 10
Instructions
Work on this lab individually. You can use your books, notes, handouts etc. but you are not allowed to borrow anything from your
peer student.
Marking Criteria
Show your work to the instructor before leaving the lab to get some or full credit.
What you have to do
Program the following tasks in your Microsoft C++ compiler and then compile and execute them. The name of your files will be
according to the task given in this lab.
Taske 01: Employee Inheritance
Task_A
Create a class Employee with following constraints in mind;
 Declare two data members named firstName and lastName of string type.
 Implement a parameterized constructor, which will take firstName and lastName of an employee and initialized the
respective data members.
 Implement a print function that displays the complete name (firstName lastName) of an Employee.
Task_B
Test the working of your created Employee class with the help of a main program.
Task_C
Create a class HourlyWorker which inherits from Employee class publically with following constraints in mind;
 Declare two data members named wage and hours of double type with private access.
 Implement a parameterized constructor, which initializes all the data members of HourlyWorker class.
 Implement a getPay function that calculate and return the salary (hours * wage) of particular HourlyWorker employee.
 Implement a print function that displays the complete name and salary of a particular employee.
Task_D
Test the working of your created HourlyWorker class with the help of a main program.

Task 02: Animal Inheritance


Implement the following class hierarchy, the inheritance access level should be public for all the descendent classes.

Task _A
Add a protected data member named id of integer type to Animal class.
Task_B
Add get/set methods for id data member in Animal class with public access.
Task_C
Add a default constructor to each of the above created class. The constructor should initialize the id data member of Animal,
Reptile, Bird and Mammal, to 0, 1, 2 and 3 respectively also it display a message “(class Name)’s default constructor”.

Umair Babar, PUCIT – PU. Lahore. Page 1 of 2


Object Oriented Programming Lab Lab 09

Task_D
Add a parameterized constructor to each of the above created class. The constructor should initialize the id data member of
Animal, Reptile, Bird and Mammal, to the specified id passed to the constructor also it display a message “(class Name)’s default
constructor”. The parameterized constructor should call its base class parameterized constructor to initialize any data member
inherited from the base class.
Task_E
Add a destructor to each of the above created class. The destructor should display a message “(class Name)’s default destructor”.

Task_F
Add a getFamily method to Snake, Parrot and Horse classes, this method must return the id of a particular animal’s family where
it belongs to.
Task_G
Add a tellAboutSelf method to Animal class with public access. The method displays the name of each objects class where it
belongs to.
Task_H
Override the tellAboutSelf in all the sub-leaving classes of Animal with the same functionality as in Animal class.
Task_I
Add a speak method to Animal class and override it in each of the sub-leaving classes. The Animal, Reptile, Bird, Mammal, Snake,
Parrot and Horse can speak by printing a message “I am Animal, I can’t speak…”, “Family of Reptiles…” “Family of Birds…”, “Family
of Mammals…”, “Shhh….”, “Trrrr….” and “Hurrrrr…” respectively.
Task_J
Write down your main method and instantiate object of each class created above, call tellAboutSelf, speak and getFamily
methods for each of the created object.

Note the mechanism in which constructors and destructors are called.

☺ ☺ ☺ BEST OF LUCK ☺ ☺ ☺

Umair Babar, PUCIT – PU. Lahore. Page 2 of 2

You might also like