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

Object Oriented Programming

CSC2071
Lecture No. 26
Muhammad Shahid
Department of Computer Science
National Textile University

shahid.abdullah@hotmail.com

Recap

 Interfaces
− What are Interfaces and why need them?
− Characteristics of Interfaces
 Implementation of Interfaces
− Single Interfaces
− Multiple Interfaces
− Handling Ambiguity while Implementing Interfaces
 Abstract Class vs. Interface

2 Object Oriented Programming – CSC2071

1
What Will You Learn Today?

 Mid Exam Solution

3 Object Oriented Programming – CSC2071

Mid Exam Solution

4 Object Oriented Programming – CSC2071

2
Question No. 1

1) Which Object-Oriented principle the given class is violating? Modify


the class such that the violation can be removed.

2) Write properties for all instance variables of this class with the
conditions that name, and diagnosis cannot be empty, and age
cannot be in negative and cannot be more than 130 years.

3) Complete the missing lines of codes for the given parameterized


constructor, IsSeniorCitizen() method and ToString() method.

4) The hospital need to know how many patients have they admitted,
so you have to write a method named GetNumberOfPatients() to
return number of patients admitted yet.

5) Write copy constructor for the class Patient such that deep copy
can be generated. What problem(s) may occur when we copy
objects without using deep copy constructor?
5 Object Oriented Programming – CSC2071

Question No. 2

 Our client Pakistan International Airline (PIA) wants to develop Seat


Reservation System (SRS) for the flights. PIA handles three types of
customers; retails customers with passport number, name, address,
cell number, email and credit card number; corporate customers with
passport number, name, address, cell number, email, and company
name; and gold customers with passport number, name, address,
cell number, email, and frequency of travelling.

 The price of the ticket is calculated depending upon the type of


customer. For the retail customers, the price is calculated by giving
5% discount; for the corporate customers, the price is calculated by
giving 15% discount, for gold customers, the price is calculated by
giving 25% discount, if the frequency of travelling is between 10000
km to 20000 km (inclusive) and the price is calculated by giving 35%
discount, if the frequency of travelling is greater than 20000 km.

6 Object Oriented Programming – CSC2071

3
Question No. 2

1) Draw class diagram of the above scenario.

2) Implement (Code) the class Implement (Code) the class diagram


and test the code by writing Main() method.

3) Calculate the price of ticket for all customers using polymorphism.

7 Object Oriented Programming – CSC2071

Question No. 2

 Our client Pakistan International Airline (PIA) wants to develop Seat


Reservation System (SRS) for the flights. PIA handles three types of
customers; retails customers with passport number, name, address,
cell number, email and credit card number; corporate customers with
passport number, name, address, cell number, email, and company
name; and gold customers with passport number, name, address,
cell number, email, and frequency of travelling.

 The price of the ticket is calculated depending upon the type of


customer. For the retail customers, the price is calculated by giving
5% discount; for the corporate customers, the price is calculated by
giving 15% discount, for gold customers, the price is calculated by
giving 25% discount, if the frequency of travelling is between 10000
km to 20000 km (inclusive) and the price is calculated by giving 35%
discount, if the frequency of travelling is greater than 20000 km.

8 Object Oriented Programming – CSC2071

4
Question No. 2

 Our client Pakistan International Airline (PIA) wants to develop Seat


Reservation System (SRS) for the flights. PIA handles three types of
customers; retails customers with passport number, name, address,
cell number, email and credit card number; corporate customers with
passport number, name, address, cell number, email, and company
name; and gold customers with passport number, name, address,
cell number, email, and frequency of travelling.

 The price of the ticket is calculated depending upon the type of


customer. For the retail customers, the price is calculated by giving
5% discount; for the corporate customers, the price is calculated by
giving 15% discount, for gold customers, the price is calculated by
giving 25% discount, if the frequency of travelling is between 10000
km to 20000 km (inclusive) and the price is calculated by giving 35%
discount, if the frequency of travelling is greater than 20000 km.

9 Object Oriented Programming – CSC2071

Questions

Object Oriented Programming – CSC2071

You might also like