close

//Fig. 16.2: fig16_02.cpp
//Time class.
#include

using namespace std;

//Time abstract data type (ADT) definition
class Time
{
public:
    Time();
    void setTime( int, int, int );
    void printMilitary();
    void printStandard();
private:
    int hour;
    int minute;
    int second;
};  // end class Time

// Time constructor initializes each data member to zero.
// Ensure all Time objects start in a consistent state.
Time::Time()
{
    hour = minute = second =0;
}

// Set a new Time value using military time. Perform validity
// checks on the fata values. Set invalid values to zero.
void Time::setTime( int h, int m, int s )
{
    hour = ( h >=0 && h    minute = ( m>=0 && m    second = ( s>=0 && s}   // end function setTime

//Print Time in military format
void Time::printMilitary()
{
    cout          }// end function printMilitary

// Print Time in standard format
void Time::printStandard()
{
    cout                            }// end function printStandard

// Driver to test simple class Time
int main()
{
    Time t;     // instantiate object t of class Time

    cout     t.printMilitary();
    cout     t.printStandard();

    t.setTime( 13, 27, 6 );
    cout     t.printMilitary();
    cout     t.printStandard();

    t.setTime( 99, 99, 99 );    // attempt invalid settings
    cout              t.printMilitary();
    cout     t.printStandard();
    cout     return 0;
}// end function main

全站熱搜
創作者介紹
創作者 alex2008 的頭像
alex2008

alex2008的部落格

alex2008 發表在 痞客邦 留言(1) 人氣()