Alx09

Untitled

May 6th, 2020
1,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3.  
  4. using namespace std;
  5.  
  6. class timp
  7. {
  8. public:
  9.     timp(int mm1, int ss1);
  10.     void ConvToHour();
  11.     void afisare();
  12.  
  13. private:
  14.     int  days, hh,mm, ss;
  15.  
  16. };
  17.  
  18. timp::timp(int mm1, int ss1)
  19. {   timp::hh = 0;
  20.     timp::days = 0;
  21.     timp::mm=mm1;
  22.     timp::ss=ss1;
  23.  
  24. }
  25.  
  26. void timp::ConvToHour()
  27. {
  28.    if(ss >= 60){
  29.      mm = mm + ss/ 60;
  30.      ss = ss % 60;
  31.    }
  32.    if(mm >= 60){
  33.     hh = hh + mm/60;
  34.     mm = mm % 60;
  35.    }
  36.    if(hh >= 24)
  37.    {
  38.        days = days + hh/24;
  39.        hh = hh %24;
  40.    }
  41. }
  42.  
  43. void timp::afisare()
  44. {  if(days)
  45.     cout<<"\nTimpul convertit este = "<<setw(2)<<setfill('0')<<days << " zile "<<setw(2)<<setfill('0')<<hh<<" ore "<<setw(2)<<setfill('0')<<mm<<" minute "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  46.    else if(hh)
  47.     cout<<"\nTimpul convertit este = "<<setw(2)<<setfill('0')<<hh<<" ore "<<setw(2)<<setfill('0')<<mm<<" minute "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  48.   else if(mm)
  49.     cout<<"\nTimpul convertit este = "<< setw(2)<<setfill('0')<<mm<<" minute "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  50.   else if(ss)
  51.   cout<<"\nTimpul convertit este = "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  52.   else
  53.     cout <<"Nu exzista nici-o unitate de timp ";
  54.  
  55.  
  56. }
  57.  
  58. int main()
  59. {
  60.     timp t1(4000000,59000);
  61.  
  62.     t1.ConvToHour();
  63.     t1.afisare();
  64.  
  65.     timp t2(4700,801);
  66.  
  67.     t2.ConvToHour();
  68.     t2.afisare();
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment