SabirSazzad

Time class (minute,second convartion)

Feb 23rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Time
  5. {
  6. private:
  7.     int seconds;
  8. public:
  9.     Time()
  10.     {
  11.         this->seconds = 0;
  12.     }
  13.     Time(int hour, int minute, int sec)
  14.     {
  15.         this-> seconds = (hour*3600) + (minute*60) + sec;
  16.     }
  17.     Time(int sec)
  18.     {
  19.         this-> seconds = sec;
  20.     }
  21.     void printTime()
  22.     {
  23.         int hour,minute,sec;
  24.         hour = this->seconds/3600;
  25.         minute = (this->seconds%3600)/60;
  26.         sec = this->seconds - (hour*3600) - (minute*60);
  27.         cout << "Time is: ";
  28.         if(hour<10)
  29.         {
  30.             cout << "0";
  31.         }
  32.         cout << hour << ":" << minute << ":" << sec <<endl;
  33.     }
  34.     int getHour()
  35.     {
  36.         return (this->seconds/3600);
  37.     }
  38.     int getMin()
  39.     {
  40.         return (this->seconds/60);
  41.     }
  42.     int getSec()
  43.     {
  44.         return (this->seconds);
  45.     }
  46. };
  47.  
  48. int main()
  49. {
  50.     Time t1, t2(5000), t3(2,20,8);
  51.     t2.printTime();
  52.     cout << "Total Hour for Object T2 is: " << t2.getHour() <<endl;
  53.     cout << "Total Minutes for Object T2 is: " << t2.getMin() <<endl;
  54.     cout << "Total Seconds for Object T3 is: " << t3.getSec()<< endl;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment