clock.h
By: timebs | Date: Oct 2 2007 02:19 | Format: C++ | Expires: never | Size: 2.06 KB | Hits: 1263
- #include <iostream>
- using namespace std;
- class clockType
- {
- public:
- void setTime(int hours, int minutes, int seconds);
- void getTime(int& hours, int& minutes, int& seconds);
- void printTime() const;
- void incrementSeconds();
- void incrementMinutes();
- void incrementHours();
- bool equalTime(const clockType& otherClock) const;
- clockType(int hours, int minutes, int seconds);
- clockType();
- private:
- int hr;
- int min;
- int sec;
- };
- void clockType::setTime(int hours, int minutes, int seconds)
- {
- if(0 <= hours && hours < 24)
- hr = hours;
- else
- hr = 0;
- if(0 <= minutes && minutes < 60)
- min = minutes;
- else
- min = 0;
- if(0 <= seconds && seconds < 60)
- sec = seconds;
- else
- sec = 0;
- }
- void clockType::getTime(int& hours, int& minutes, int& seconds)
- {
- hours = hr;
- minutes = min;
- seconds = sec;
- }
- void clockType::printTime() const
- {
- if(hr < 10)
- cout<<"0";
- cout<<hr<<":";
- if(min < 10)
- cout<<"0";
- cout<<min<<":";
- if(sec < 10)
- cout<<"0";
- cout<<sec;
- }
- void clockType::incrementHours()
- {
- hr++;
- if(hr > 23)
- hr = 0;
- }
- void clockType::incrementMinutes()
- {
- min++;
- if(min > 59)
- {
- min = 0;
- incrementHours();
- }
- }
- void clockType::incrementSeconds()
- {
- sec++;
- if(sec > 59)
- {
- sec = 0;
- incrementMinutes();
- }
- }
- bool clockType::equalTime(const clockType& otherClock) const
- {
- return(hr == otherClock.hr
- && min == otherClock.min
- && sec == otherClock.sec);
- }
- clockType::clockType(int hours, int minutes, int seconds)
- {
- setTime(hours, minutes, seconds);
- }
- clockType::clockType()
- {
- setTime(0, 0, 0);
- }
- class extClockType: public clockType
- {
- public:
- int getTimeZone();
- void setTimeZone(char t);
- void setTime(int hours, int minutes, int seconds, char t);
- void getTime(int& hours, int& minutes, int& seconds, char& t);
- void printTime();
- extClockType();
- extClockType(int hours, int minutes, int seconds, char t);
- private:
- char timeZone;
- };
Latest pastes
58 minutes ago
10 hours ago
1 days ago
2 days ago
2 days ago