一个C++的闹钟

不是吧,不会还有人不觉得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:代码是我朋友给的,可能会撞上

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值