Tutorial C++
Tutorial C++
Tutorial C++
Partha Pratim
Das
Module 24: Programming in C++
Objectives &
Outline
Inheritance: Part 4
Example –
Phone
Hierarchy
Partha Pratim Das
Summary
Tanwi Mallick
Srijoni Majumdar
Himadri B G S Bhuyan
Module 24
Objectives &
Outline
Example –
Phone
Hierarchy
Summary
Module 24
Module 24
Partha Pratim
Das
Class Description
Objectives &
Outline class PhoneNumber 12-digit phone number
Example – class Name Subscriber Name (as string)
Phone
Hierarchy class Photo Image & Subscriber Name as alt text
Summary class RingTone Audio & ring tone name
class Contact PhoneNumber, Name, and Photo (op-
tional) of a contact
class AddressBook List of contacts
Summary
Add Contact void Call(PhoneNumber *p);
Number void Call(const Name& n);
Name void Answer();
void ReDial();
void SetRingTone(RingTone::RINGTONE r);
void AddContact(const char *num = 0,
const char *subs = 0);
void ReDial();
void SetRingTone(RingTone::RINGTONE r);
void AddContact(const char *num = 0,
const char *subs = 0);
Module 24
Partha Pratim
Das
Objectives &
Outline
Example –
Phone
Hierarchy MobilePhone ISA LandlinePhone
Summary LandlinePhone is generalization
MobilePhone is specialization
MobilePhone inherits the properties of LandlinePhone
SmartPhone ISA MobilePhone
MobilePhone is generalization
SmartPhone is specialization
SmartPhone inherits the properties of MobilePhone
ISA is transitive
Module 24
Partha Pratim
Das
Objectives &
Outline
Example –
Phone
Hierarchy
Summary
void Call(const PhoneNumber *p); // Override void Call(const PhoneNumber *p); // Override
void Call(const Name& n); // Overload void Call(const Name& n); // Override
//void Answer(); //void Answer();
void ReDial(); void ReDial(); // Override
void SetRingTone(RingTone::RINGTONE r); //void SetRingTone(RingTone::RINGTONE r);
void AddContact(const char *num = 0, //void AddContact(const char *num = 0,
const char *subs = 0); //const char *subs = 0);
friend ostream& operator<< (ostream& os, friend ostream& operator<< (ostream& os,
const MobilePhone& p); const SmartPhone& p);
}; };
Module 24
Partha Pratim
Das
Objectives &
Outline
Example –
Phone
Hierarchy
Summary
Module 24
Example –
Phone
Hierarchy
Summary
Module 24
Partha Pratim
Das Name Mail Mobile
Objectives &
Partha Pratim Das, Instructor [email protected] 9830030880
Outline Tanwi Mallick, TA [email protected] 9674277774
Example –
Srijoni Majumdar, TA [email protected] 9674474267
Phone Himadri B G S Bhuyan, TA [email protected] 9438911655
Hierarchy
Summary