『代码』··By/蜜汁炒酸奶

纯文字无音乐文件版闹铃-C++

这个的本质其实就是个简单的计时器

/*
功能:改写闹钟类
日期:2013-10-19
*/
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class Time
{
public:
   void getNow(time_t t,tm *lt)const;

public:
    int m_aYear;
	int m_aMonth;
    int m_aDay;
	int m_aHour;
	int m_aMinute;
    int m_aSecond;
    time_t t;
	tm *lt;
	string m_aName;
};
class Clock:public Time
{
public:
     void getClock(time_t t,tm *lt);
	 void setName(string name);
	 void setDay(int aYear,int aMonth,int aDay);
	 void setTime(int aHour,int aMinute,int aSecond);
};
void Time::getNow(time_t t,tm *lt)const
{

	cout<<"现在时间:"<<lt->tm_year+1900<<"-"<<lt->tm_mon+1<<"-"<<lt->tm_mday<<" "<<lt->tm_hour<<":"<<lt->tm_min<<":"<<lt->tm_sec<<endl;
}
void Clock::setName(string name)
{

	m_aName = name;
}
void Clock::setDay(int aYear,int aMonth,int aDay)
{
    m_aYear = aYear;
	m_aMonth = aMonth;
	m_aDay = aDay;
}
void Clock::setTime(int aHour,int aMinute,int aSecond)
{
   m_aHour = aHour;
   m_aMinute = aMinute;
   m_aSecond = aSecond;
}
void Clock::getClock(time_t t,tm *lt)
{

	cout<<"闹铃启动..."<<endl;
	while(1)
	{

		if (m_aYear == lt->tm_year+1900&&m_aMonth ==lt->tm_mon+1&&m_aDay == lt->tm_mday&&m_aHour ==lt->tm_hour&&m_aMinute==lt->tm_min&&m_aSecond==lt->tm_sec)
		{
            cout<<m_aName<<"开始行动啦!"<<endl;
			break;
		}
		t = time(NULL);
		lt = localtime(&t);
	}

}
int main(void)
{

	Time timea;
	Clock clock;
	string name;
	time_t t;
	tm *lt;
	int year,month,day,hour,minute,second;
	t = time(NULL);
	lt = localtime(&t);

	cout<<"欢迎使用电子闹钟,请输入您的名字:"<<endl;
	cin>>name;
	clock.setName(name);
	timea.getNow(t, lt);

    cout<<"请输入您的闹铃日期:(年、月、天使用回车隔开):"<<endl;
	cin>>year>>month>>day;
	clock.setDay(year,month,day);

	cout<<"请输入您的闹铃时间:(时、分、秒使用回车隔开):"<<endl;
    cin>>hour>>minute>>second;
	clock.setTime(hour,minute,second);

    clock.getClock(t,lt);

	system("pause");
	return 0;
}
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

预览
Loading comments...
0 条评论

暂无数据

example
预览