Advertisement
dyamondz

Rellotge - P45616

Jan 7th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. struct Rellotge {
  6.     int h; // hores (0<=h<24)
  7.     int m; // minuts (0<=m<60)
  8.     int s; // segons (0<=s<60)
  9. };
  10.  
  11. Rellotge mitja_nit(){
  12.     Rellotge r;
  13.     r.h=0;
  14.     r.m=0;
  15.     r.s=0;
  16.     return r;
  17. }
  18. void incrementa(Rellotge& r){
  19.     ++r.s;
  20.     if(r.s==60){
  21.         r.s=0;
  22.         ++r.m;
  23.         if(r.m==60){
  24.             r.m=0;
  25.             ++r.h;
  26.             if(r.h==24){
  27.                 r.h=0;
  28.             }
  29.         }
  30.     }
  31. }
  32. void escriu(const Rellotge& r){
  33.     cout<<setw(2)<<setfill('0')<<r.h<<':';
  34.     cout<<setw(2)<<setfill('0')<<r.m<<':';
  35.     cout<<setw(2)<<setfill('0')<<r.s<<endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement