Alx09

Untitled

May 6th, 2020
1,500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 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  hh,mm, ss;
  15.  
  16. };
  17.  
  18. timp::timp(int mm1, int ss1)
  19. {   timp::hh = 0;
  20.  
  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.  
  37. }
  38.  
  39. void timp::afisare()
  40. {   if(hh)
  41.     cout<<"\nTimpul convertit este = "<<setw(2)<<setfill('0')<<hh<<" ore "<<setw(2)<<setfill('0')<<mm<<" minute "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  42.   else if(mm)
  43.     cout<<"\nTimpul convertit este = "<< setw(2)<<setfill('0')<<mm<<" minute "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  44.   else if(ss)
  45.   cout<<"\nTimpul convertit este = "<<setw(2)<<setfill('0')<<ss<<" secunde" <<endl;
  46.   else
  47.     cout <<"Nu exzista nici-o unitate de timp ";
  48.  
  49.  
  50. }
  51.  
  52. int main()
  53. {
  54.     timp t1(12500,15400);
  55.  
  56.     t1.ConvToHour();
  57.     t1.afisare();
  58.  
  59.     timp t2(460,809);
  60.  
  61.     t2.ConvToHour();
  62.     t2.afisare();
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment