#include <iostream.h>
class Time {
public:
Time();
void setTime( int, int, int );
void printUniversal();
void printStandard();
private:
int hour; // 0 - 23 (24-hour clock format)
int minute; // 0 - 59
int second; // 0 - 59
}
Time::Time()
{
hour = minute = second = 0;
}
void Time::setTime( int h, int m, int s )
{
hour = ( h >= 0 && h < 24 ) ? h : 0;
minute = ( m >= 0 && m < 60 ) ? m : 0;
second = ( s >= 0 && s < 60 ) ? s : 0;
}
void Time::printUniversal()
{
cout << (hour<10 ? "0":"") << hour << ":"
<< (minute<10 ? "0":"") << minute << ":"
<< (second<10 ? "0":"") << second;
}
void Time::printStandard()
{
cout << ( ( hour == 0 || hour == 12 ) ?
12 : hour % 12 ) << ":"
<< (minute<10 ? "0":"") << minute << ":"
<< (second<10 ? "0":"") << second
<< (hour < 12 ? " AM" : " PM" );
}
int main()
{
Time t; // create Time object
t.hour = 7; // error: 'Time::hour' is not accessible
// error: 'Time::minute' is not accessible
cout << "minute = " << t.minute;
return 0;
}