CS333 - Problem Solving and Object Oriented Programming in
C++
[ Home | Schedule
| Personal
Progress | Search | Glossary | Help
]
Inheritance
class Time { public: Time( int = 0, int = 0, int = 0 ); // default constructor // set functions void setTime( int, int, int ); // set time void setHour( int ); // set hour void setMinute( int ); // set minute void setSecond( int ); // set second // get functions (normally declared const) int getHour() const; // return hour int getMinute() const; // return minute int getSecond() const; // return second // print functions (normally declared const) void printMilitary() const; // print military time void printStandard() const; // print standard time private: int hour; // 0 - 23 int minute; // 0 - 59 int second; // 0 - 59 }; //This examples adds an alarm feature to the "Time" class in figure 7.1 // Here is the header file (see also this topic) class AlarmClock : public Time { public: AlarmClock(int hour = 0, int minute = 0, int second = 0); AlarmClock(int hour, int minute, int second, int alarmHour, int alarmMinute, bool alarmSet); void setAlarmTime(int hour, int minute); int getAlarmHour( ) const; int getAlarmMinute( ) const; void setAlarm(bool state); bool getAlarm( ) const; private: int alarmHour; int alarmMinute; bool alarmState; }; AlarmClock myAlarm; |