1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include<iostream>
using namespace std;
#include "time.h"
time::time(int h,int m,int s)
{
hour=((h>0 && h<24)? h:0);
min=((m>0 && m<60)? m:0);
sec=((s>0 && s<60)? s:0);
}
void time::setTime(int h,int m,int s)
{
hour=((h>0 && h<24)? h:0);
min=((m>0 && m<60)? m:0);
sec=((s>0 && s<60)? s:0);
}
void time::addHour(int h)
{
for(int i=0;i<h;i++)
{
hour++;
if(hour==24)
hour=0;
}
}
void time::addMin(int m)
{
for(int i=0;i<m;i++)
{
min++;
if(min==60)
{
addHour(1);
min=0;
}
}
}
void time::addSec(int s)
{
for(int i=0;i<s;i++)
{
sec++;
if(sec==60)
{
addMin(1);
sec=0;
}
}
}
ostream& operator<<(ostream& out,const time& heure)
{
out<<endl;
out<<heure.hour<<':'<<heure.min<<':'<<heure.sec;
out<<endl;
return out;
} |
Partager