-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path140.cpp
More file actions
58 lines (55 loc) · 1.05 KB
/
140.cpp
File metadata and controls
58 lines (55 loc) · 1.05 KB
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
#include <iostream>
using namespace std;
class Clock{
public:
Clock(int h,int m, int s);
void SetAlarm(int h,int m,int s);
void run();
void ShowTime(){
cout<<"Now:"<<hour<<":"<<minute<<":"<<second<<endl;
}
private:
int hour; //时
int minute; //分
int second; //秒
int Ahour; //时(闹钟)
int Aminute; //分(闹钟)
int Asecond; //秒(闹钟)
};
void ck(int &x,const int mx){
if(x>=mx)x=0;
if(x<=0)x=0;
};
Clock::Clock(int h,int m, int s)
{
ck(h,24),ck(m,60),ck(s,60);
hour=h;
minute=m;
second=s;
Asecond=-1;
}
void Clock::SetAlarm(int h,int m, int s){
if(h>=24)h=0;
if(m>=60)m=0;
if(s>=60)s=0;
Ahour=h,Aminute=m,Asecond=s;
}
void Clock::run(){
second++;
if(second==60){
second=0;
minute++;
if(minute==60){
minute=0;
hour++;
if(hour==24)hour=0;
}
}
if(second==Asecond&&minute==Aminute&&hour==Ahour){
cout<<"Plink!plink!plink!.."<<endl;
}
}
int main(){
Clock c(25,61,-1);
c.ShowTime();
}