不是吧,不会还有人不觉得C++是万能的?
你说闹钟???今天我就带来一个C++的闹钟
代码如下(有亿点长):
#include<stdio.h>
#include<cstdlib>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<ctime>
using namespace std;
int d,e,f,sss=1;
string things;
void gotoxy(int y,int x)
{
COORD coord;
coord.X=x;
coord.Y=y;
HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(a,coord);
}
void hidden()
{
system("mode con cols=100 lines=50");
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
cout<<"输入目标 时 分 秒(24小时制)和干嘛(文字): ";
cin >>d>>e>>f>>things;
}
long long timenow()
{
time_t t2;
time(&t2);
return t2;
}
int main()
{
system("title 闹钟2.0");
hidden();
time_t t1;
time(&t1);
t1++;
int time,a,b,c,time1,time2;
int x,y,z;
a=t1%86400/3600+8;
b=t1%3600/60;
c=t1%60;
time1=(d-a)*3600+(e-b)*60+(f-c);
system("cls") ;
while(!(x>d||y>e&&x==d||z>f&&y==e&&x==d))
{
system ("cls");
t1=timenow();
x=t1%86400/3600+8;
y=t1%3600/60;
z=t1%60;
int A,B,C;
cout<<"现在是"<<' '<<x<<':'<<' '<<y<<':'<<' '<<z<<endl <<endl;
cout<<"时间是"<<' '<<d<<':'<<' '<<e<<':'<<' '<<f<<endl <<endl;
A=(f-z)+(e-y)*60+(d-x)*3600;
cout<<"还有"<<A/3600<<"小时 "<<A%3600/60 <<"分钟 " <<A%60 <<"秒"<<things<<endl;
Sleep (50);
if (kbhit())
if (getch()=='`')
things="关机";
}
string F=("该去"+things+"了");
string llf="快去"+things+"!";
Beep(1000,500);
if (things!="关机")
MessageBox(NULL,TEXT("还记得你定的闹钟吗\n?????????"),TEXT("闹钟"),MB_OK);
else if (MessageBox(NULL,TEXT("是否关机"),TEXT("闹钟"),MB_YESNO)!=IDNO)
system("shutdown -s -t 315359999");
else
sss=0;
while(sss)
{
system ("cls");
gotoxy(rand()%50,rand()%100);
cout <<"快去" <<things;
Beep(1000,500);
}
return 0;
}
让我们运行一下
效果看起来不错呢,好像还可以关机。
嗨森^_^
纯属原创
P.S:代码是我朋友给的,可能会撞上