OOP Assignment 03
OOP Assignment 03
a) Create a base class called Person with protected member variables name and age. Provide a constructor to initialize
these variables and a virtual function displayDetails() to display the name and age.
b) Derive two classes, Student and Teacher, from Person. Add a private member variable studentId in the Student
class and teacherId in the Teacher class. Implement the displayDetails() function in each derived class to display the
additional information along with the name and age.
c) Create objects of Student and Teacher and demonstrate polymorphism by calling the displayDetails() function on
each object.
a) Create an abstract class called Shape with a pure virtual function calculateArea(). Derive two classes, Rectangle
and Circle, from Shape. Implement the calculateArea() function in each derived class to calculate and return the area
of the shape.
b) Create objects of Rectangle and Circle and demonstrate the abstraction and resizing functionality by calling the
calculateArea() function and the resize() function on each object.
Question 3: Encapsulation and Access Modifiers (5 marks)
a) Create a class called BankAccount with private member variables accountNumber (integer), balance (double), and
pin (string). Provide appropriate accessor and mutator functions to access and modify these variables.
b) Implement a public member function withdraw(double amount) in the BankAccount class to withdraw money from
the account. Apply appropriate encapsulation techniques to ensure that the withdrawal is only allowed if the correct
pin is provided and if the account has sufficient balance.
c) Create an object of BankAccount and demonstrate the encapsulation and withdrawal functionality by calling the
appropriate functions.
Guidelines:
Submit a pdf file that will have your code along with the output screens.
Provide a brief explanation of your approach for each question.
Give your .cpp source files too.