Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Time
- {
- private:
- int seconds;
- public:
- Time()
- {
- this->seconds = 0;
- }
- Time(int hour, int minute, int sec)
- {
- this-> seconds = (hour*3600) + (minute*60) + sec;
- }
- Time(int sec)
- {
- this-> seconds = sec;
- }
- void printTime()
- {
- int hour,minute,sec;
- hour = this->seconds/3600;
- minute = (this->seconds%3600)/60;
- sec = this->seconds - (hour*3600) - (minute*60);
- cout << "Time is: ";
- if(hour<10)
- {
- cout << "0";
- }
- cout << hour << ":" << minute << ":" << sec <<endl;
- }
- int getHour()
- {
- return (this->seconds/3600);
- }
- int getMin()
- {
- return (this->seconds/60);
- }
- int getSec()
- {
- return (this->seconds);
- }
- };
- int main()
- {
- Time t1, t2(5000), t3(2,20,8);
- t2.printTime();
- cout << "Total Hour for Object T2 is: " << t2.getHour() <<endl;
- cout << "Total Minutes for Object T2 is: " << t2.getMin() <<endl;
- cout << "Total Seconds for Object T3 is: " << t3.getSec()<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment