University of Central Punjab: Object Orient Programing
University of Central Punjab: Object Orient Programing
University of Central Punjab: Object Orient Programing
OOP LAB 11
Instructions:
• Indent your code.
• Comment your code.
• Use meaningful variable names.
• Plan your code carefully on a piece of paper before you implement it.
• Use single .cpp file for graded lab.
Task 1
Write a class Person that has the attributes of id, name and address. It has a constructor to initialize, a
member function (getInfo) to input and a member function (showInfo) to display data members.
Create another class Student that inherits Person class. It has additional attributes of roll number and
marks. It also has member function(getEdu) to input and display(showEdu) its data members.
Sample Output
Suppose we have three classes Vehicle, FourWheeler, and Car. The class Vehicle is the base class, the
class FourWheeler is derived from it and the class Car is derived from the class FourWheeler. Class
Vehicle has a method 'vehicle' that prints 'I am a vehicle', class FourWheeler has a method
'fourWheeler' that prints 'I have four wheels', and class Car has a method 'car' that prints 'I am a car'.
So, as this is a multi-level inheritance; we can have access to all the other classes methods from the
object of the class Car. We invoke all the methods from a Car object and print the corresponding
outputs of the methods.
Sample Output
I am a car
I have four wheels
I am a vehicle