0% found this document useful (0 votes)
22 views2 pages

OOP Assignment 03

Oop course

Uploaded by

Ayan Rajpoot
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
22 views2 pages

OOP Assignment 03

Oop course

Uploaded by

Ayan Rajpoot
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

University of Management and Technology

School of Systems and Technology, Department of Computer Science


Assignment 03– Spring 2023
Course Title: Object Oriented Programming Course Code: CC1022 Credit Hours: 4(3,1)
Course Instructor: Mr. Muhammad Owais Khan Program Name: BSCS
Semester: 2nd Batch: FA22-BCS Section: Date: 03-07-2023
Due Date: 05-07-2023, Wednesday Maximum Marks: 20
Student’s Name: Reg. No.

Important Instructions (To be followed very strictly)


 This is an individual assignment
 Attempt all questions
 Assignment must be handwritten you have to upload pdf on LMS before deadline with .cpp code file.
 The assignment must include all steps involved to solve given questions.
 Dry run each question.
 No submission is allowed after the aforementioned deadline.

Question No 1. [CLO-3] <Bloom Taxonomy – C2: Apply> Marks [20]

Model a solution for a given problem using object-oriented principles in C++.

Problem 1: Inheritance and Polymorphism (8 marks)

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.

Problem 2: Abstraction (7 marks)

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.

You might also like