功能
1.显示当前时间
2.显示已用时间;
//前两项时间的输出,我选择了在同一行覆盖打印,感觉比较美观
3.到达上限时间后扬声器报警
4.运行时不影响编译运行其他程序
代码
#include <cstdio>
#include <cstring>
#include <ctime>
#include <windows.h>
// Sun Jul 28 01:30:31 2019
int main() {
const int ss = 1800;
int m=0, s=0;
for(int i=0; i<ss; i++) {
time_t rawtime;
struct tm* ptm;
time(&rawtime);
ptm = localtime(&rawtime);
s++;
if(s == 60) {
m++; s=0;
}
printf("current time: %02d:%02d:%02d",
ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
printf("\tused time: %02d:%02d\r", m, s);
Sleep(1000);
}
int a=520, n=20;
while(n--) {
for(int i=a; i<a+a; i += 20) {
Beep(i, 400);
}
Sleep(400);
}
return 0;
}