Programming in C++ Deriving One Class from Another class Time Specification I SPECIFICATION FILE (time. h) class Time public: void Set int hours, int minutes, int seconds VOId Incremento void Write(const Time(int initHrs, int initMins, int initSecs );//constructor Time; ∥/ default constructor private int hrs i int mins int secs
11 class Time Specification // SPECIFICATION FILE ( time.h ) class Time { public : void Set ( int hours , int minutes , int seconds ) ; void Increment ( ) ; void Write ( ) const ; Time ( int initHrs, int initMins, int initSecs ) ; // constructor Time ( ) ; // default constructor private : int hrs ; int mins ; int secs ; } ; Deriving One Class from Another
Programming in C++ Class Interface Diagram Time class Set Private data ncrement hrs Write mIns Time secs Time 12
12 Class Interface Diagram Private data: hrs mins secs Set Increment Write Time Time Time class
Programming in C++ Using Inheritance to Add Features ∥/SPEc|F| CATION FILE (exttime. h) # include“ time, h enum ZoneType [EST, CST, MST, PST, EDT, CDT, MDT, PDT); class ExtTime: public Time ∥ Time is the base class public: void Set (int hours, int minutes, int seconds ZoneType timeZone); void Write(const ExtTime(int initHrs, int initMins, int initsecs Zone Type ini忆zone); ∥ constructor ExtTime o l/default constructor private: Zone Type zone; ∥/ added data member 13
13 Using Inheritance to Add Features // SPECIFICATION FILE ( exttime.h) #include “time.h” enum ZoneType {EST, CST, MST, PST, EDT, CDT, MDT, PDT } ; class ExtTime : public Time // Time is the base class { public : void Set ( int hours, int minutes, int seconds , ZoneType timeZone ) ; void Write ( ) const ; ExtTime ( int initHrs , int initMins , int initSecs , ZoneType initZone ) ; // constructor ExtTime ( ) ; // default constructor private : ZoneType zone ; // added data member } ;