1 / 45

Inheritance and Polymorphism

Inheritance and Polymorphism. Syllabus. Multipath hybrid inheritance Dynamic polymorphism – virtual functions Dynamic polymorphism – pure virtual functions. 2. Problem.

siegrist
Download Presentation

Inheritance and Polymorphism

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inheritance and Polymorphism

  2. Syllabus Multipath hybrid inheritance Dynamic polymorphism – virtual functions Dynamic polymorphism – pure virtual functions 2

  3. Problem Given the details about a railway employee, do OOP design and compute the fare to be paid by a railway employee. The railway employee is treated as the privileged passenger. The discount offered vary based on their cadre of employment

  4. Loan Application Problem

  5. Inheritance

  6. Case Study Railway Reservation System Privileged Passenger – a passenger who is an employee of the Indian railways system He is given a discount in travel ticket Privileged Passenger is a passenger as well as an employee of railways system Both of them are basically person with basic details like name age etc 6

  7. Multi Level Inheritance

  8. Multi level Inheritance

  9. Multiple Inheritance

  10. Multipath Inheritance

  11. COMPILATION ERROR Problem in multipath inheritance Privileged passenger has datamembers from both regular employee as well as passenger Regular employee and passenger are inherited from person class So duplicate members Compiler gives ERROR ! Also called Diamond Problem

  12. Simple Example

  13. Virtual Functions

  14. Base class vs Derived class Pointers Base class pointer can hold address of a derived class object but not vice versa Pointer of animal class can hold address of an object of either class lion or tiger and even address of object of liger

  15. Base class pointer ‘a’ has address of derived class liger but invokes member functions in base class • Due to static binding – Done during compilation • Similar to connecting to a call for a landline connection – routing is always same and done during installation • But we need dynamic binding • Similar to routing a call for a mobile phone – routing is done at the call time based on the location of phone

  16. Job Scheduling Problem A number of jobs may be submitted to an Operating System (OS). Assume that the OS follows shortest job first scheduling that is when a number of jobs namely j1, j2, j3 are submitted at the same time, the job which requires minimum time to complete is served first. Similar to case when three customers enter a shop at the same time, customer who is getting least number of items is served first. An OS named as OS1_X supports two types of scheduling. Based on time required to complete job Based on memory required to complete job Design an OOP model and implement the same in C++ to perform the scheduling. Assume that all the jobs are submitted at the same timeGive the solution, based on the choice of scheduling opted by the user.

  17. Job Scheduling Problem

More Related