OOP Final QP

You might also like

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

The University of Lahore

Department of Computer Science & IT


Final-Term Examination
Spring-2022
Course Title: Object Oriented Programming Course Code: CS02203 Credit Hours: 4
Course Instructors: Dr. M Atif, Dr. Abbas Khalid,
Mr. M Idrees, Mr. Aoun Aftab Program Name: BSCS
Time Allowed: 120 Minutes Maximum Marks: 40
Date: June 3, 2022 Course Mentor: Dr. Abbas Khalid
Student’s Name: Signature:
Reg. No: Section: A, B, C, D & E
****** Solve all Questions on answer sheet provided separately. ********

Question 1: [10 Marks]


Write a program of multi-level inheritance that have three classes Person, Student and ForeignStudent. Where Person
class is inherited by Student class and Student class is inherited by ForeignStudent class.
I. Person class has three protected data members, i.e., Id (Integer), name (string), gender (char).
II. Student class has two protected data members. i.e., course (string), GPA (float).
III. ForeignStudent class has two protected data members, i.e., country (string), passportNo (string).

In main (), declare an array of ten objects of ForeignStudent class. Initialize array using loop through setters. You have to
display the details of those students who are female having GPA greater than 3.0 and belong to Scotland.

Question 2: [10 Marks]


Define a class for a bank account that includes the following data members:
 Name of account holder
 Account Number
 Type of Account
 Balance amount in the account

The class also contains the following member functions:


 A constructor to assign initial values.
 Deposit function to deposit some amount. It should accept the amount as parameter.
 Withdraw function to withdraw an amount after checking the balance. It should accept the amount as parameter.
 Display function to display name and balance.
 Overload + operator that adds the balance of one account to another account.

Page 1 of 2
Question 3: [10 Marks]
Write a program of polymorphism for Employee payroll system. There are three kind of Employees in the system:
 Salaried_Employees
 Hourly_Employees
 Base_salary_plus_commission_Employees

Make Employee an abstract class. Declare Calculate_Salary() as pure virtual function in it which is used to calculate and
display salary of employee by child or concrete classes.
Salaried_Employees are paid a fixed monthly salary regardless of the number of hours worked. Salaried_Employees class
has salary data member.
Hourly_Employees are paid by their working hours and receive salary after multiplying number_of_hours with their
hour_rate. Hourly_Employees class has salary, hour_rate and number_of_hours data members.
Base_salary_plus_commission_Employees receive a base salary plus commission.
Base_salary_plus_commission_Emopoyees class has salary, No_of_item_sold and commission data members.
[Commission= No_of_item_sold *1000]

Employee

Base_salary_plus_commission
Salaried_Employees Hourly_Employees _Employees

In main(), take input in each class object and calculate the salary of each employee polymorphically.

Question 4: [10 Marks]


Write a program that create a file "Doctor.txt" inside main function and prompts the user to enter the details of a Doctor
i.e., his/her name, id, and address. Write this data into the file. Open the same file "Doctor.txt" in reading mode and
display the data on console.

Page 2 of 2

You might also like