Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Department of IT & CS

Course Instructor: Rizwan Ali Course: Object Oriented Programming


Assignment: 04 Semester: Spring 2024
Student Name: Registration No:
Section: Marks: 10

QUESTION # 01 Distinguish between virtual functions and pure virtual functions.

ANSWER

Create a base class Shape with a pure virtual method area() that
returns the area of the shape. Derive three classes from Shape: Circle,
QUESTION # 02 Rectangle, and Triangle. Each derived class should implement the
area() method specific to the shape it represents. Additionally, create a
method to print the details of each shape.

CODE OF THE PROGRAM

OUTPUT OF THE PROGRAM

QUESTION # 03 Create a base class Employee with a pure virtual method


calculatePay(). Derive two classes FullTimeEmployee and
PartTimeEmployee from Employee. Implement the calculatePay()
method for each derived class. FullTimeEmployee should have a
fixed monthly salary, and PartTimeEmployee should be paid based on
an hourly wage and the number of hours worked.

Employee class should have a pure virtual method double


calculatePay() const = 0.
FullTimeEmployee class should have a constructor that takes a name
and monthly salary.
PartTimeEmployee class should have a constructor that takes a name,
hourly wage, and hours worked.
Create a function printEmployeeDetails( ) that prints the name and
calculated pay of the employee.

Answer

What are virtual functions? Describe a circumstance in which virtual


QUESTION # 04
functions would be appropriate.

Answer

You might also like