急求一C++倒计时程序?高手指点,要完整代码、

如题所述

#include <iostream.h>
#include <windows.h>
class Clock //定义时钟类
{
public:
void set(int h,int m,int s);
void show();
private:
int hour,minute,second;
};
void Clock::set(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
void Clock::show()
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
void clrscr() //清屏函数
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
void main() //主函数
{
Clock my;
int k,h,m,s;
cout<<"input hour:"; //以下为设置倒计时的时间长度,分别输入时分秒。
cin>>h;
cout<<"input minute:";
cin>>m;
cout<<"input second:";
cin>>s;
while(1)
{
my.set(h,m,s);
my.show();
Sleep(1000); //延迟函数,后面的数字自己设定,单位为毫秒,比如1000即为1000毫秒即1秒。
clrscr();
s--;
if(s==-1)
{
s=59;
m--;
if(m==-1)
{
m=59;
h--;
if(h==-1) //计时结束
{
cout<<"time up!"<<endl;
break;
}
}
}
}
} //有何问题请多指教!!!!!!!望采纳! 设置倒计时时间长度。 倒计时中。 计时结束!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-13
设计步骤如下:  1.运行C++ Builder系统后,先激活选单“File/New Application”,创建一个新工程。   2.激活选单“File/Save As”把窗体单元以文件名exitu.cpp存盘,然后激活选单“File/Save Project As”把工程文件以文件名exitp.bpr存盘。(注意:工程文件名与窗体单元文件名不要同名。)  3.在窗体上增加四个TButton组件Button1、Button2、Button3和Button4,分别设置它们的Caption属性为“其它身份登录”、“关机”、“重新启动”和“强制关机”。  4.分别设置Button1、Button2、Button3和Button4组件的OnClick事件响应代码如下:  void __fastcall TForm1::Button1Click(TObject Sender)  {  //其它身份登录  DWORD temp;  ExitWindowsEx(EWX_LOGOFF,temp);  }  //------------------------------  void __fastcall TForm1::Button2Click(TObject Sender)  {  //关机  DWORD temp;  ExitWindowsEx(EWX_SHUTDOWN,temp);  }   //------------------------------  void __fastcall TForm1::Button3Click(TObject Sender)  {  //重新启动  DWORD temp;  ExitWindowsEx(EWX_REBOOT,temp);  }  //------------------------------  void __fastcall TForm1::Button4Click(TObject Sender)  {  //强制关机  DWORD temp;  ExitWindowsEx(EWX_FORCE,temp);  }  5.运行程序后,分别单击四个按钮测试它们的功能。如果能完成各种设置的功能,说明你已成功了,那么就可以将本文介绍的方法运用到自己开发的C++ Builder应用程序中去控制Windows的关闭了
第2个回答  2018-10-14
#include <iostream>  
#include <windows.h>  
#include <ctime>
using namespace std;  
//定义低音  
const int a1 = 131;  
const int a2 = 147;  
const int a3 = 165;  
const int a4 = 175;  
const int a5 = 196;  
const int a6 = 220;  
const int a7 = 247;  
//定义中音  
const int b1 = 262;  
const int b2 = 296;  
const int b3 = 330;  
const int b4 = 349;  
const int b5 = 392;  
const int b6 = 440;  
const int b7 = 494;  
//定义高音  
const int c1 = 523;  
const int c2 = 587;  
const int c3 = 659;  
const int c4 = 698;  
const int c5 = 784;  
const int c6 = 880;  
const int c7 = 988;  
//定义高二度  
const int d1 = 1047;  
const int d2 = 1175;  
const int d3 = 1319;  
const int d4 = 1397;  
const int d5 = 1568;  
const int d6 = 1760;  
const int d7 = 1976;
const int d8 = 2113; 
//定义节拍  
const int j1 = 230;  
const int j2 = 350; 
const int j3 = 600; 
const int j4 = 1000;
const int j5 = 1500;
const int j0 = 100;
const int j6 = 150;
void hidden()
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=0;/*赋1为显示,赋0为隐藏*/
SetConsoleCursorInfo(hOut,&cci);
}
int m;
void djsq(int d,int m,int n,int o)
{
for(int i=d*3600*24+m*3600+n*60+o;i>=0;i--)
{printf("倒计时:\n%02d天%02d时%02d分%02d秒",i/3600/24,(i%(3600*24))/3600,(i%(3600*24)%3600)/60,(i%(3600*24)%3600)%60);
Sleep(1000);system("cls");
if(i==0)
{
printf("倒计时:\n00天00时00分00秒");
Sleep(800);
aa:
cout<<"\n\n时间到!!";
Beep(c3,j3); //蜂鸣器
Beep(c6,j3);
Beep(c7,j1);
Sleep(90);
Beep(d1,j2);
Beep(c6,j2);
Beep(d4,j2);
//Sleep(100);
Beep(d2,j2);
Beep(d3,j5);
Beep(c3,j3);
//Sleep(90);
Beep(c6,j3);
Beep(c7,j1);
Sleep(90);
Beep(d1,j2);
Beep(c6,j2);
Beep(d4,j2);
Beep(d3,j1);
Beep(d2,j5);
//Beep(c3,j5);
Sleep(700);
Beep(c3,j3);
//Sleep(90);
Beep(c6,j3);
Beep(c7,j1);
Sleep(90);
Beep(d1,j2);
Beep(c6,j2);
Beep(d4,j2);
//Sleep(100);
Beep(d3,j1);
Beep(d2,j2);
Beep(d5,j5);
Sleep(300);
Beep(c3,j1);
//Sleep(90);
Beep(c6,j3);
Beep(c7,j1);
Sleep(90);
Beep(d1,j2);
Beep(c6,j2);
Beep(d4,j2);
//Sleep(100);
Beep(d3,j2);
Beep(d2,j2);
Beep(d6,j5);
system("cls");
goto aa;
}
}
}
int main()
{
hidden();
//begin:
int set;
system("mode con cols=68 lines=22");
int a,b,c,d,m;
int i = 1; 
while(i<=20)
{
cout<<"\t\t\t倒计时器\n";
cout<<"请输入天:\n";
cin>>a;
cout<<"请输入时:\n";
cin>>b;
cout<<"请输入分:\n";
cin>>c;
cout<<"请输入秒:\n";
cin>>d;
m=a*3600*24+b*3600+c*60+d;
printf("您输入的时间为%02d天%02d时%02d分%02d秒\n",m/3600/24,(m%(3600*24))/3600,(m%(3600*24)%3600)/60,(m%(3600*24)%3600)%60);
//cout<<"您输入的时间为"<<m/3600/24<<"天"<<(m%(3600*24))/3600<<"小时"<<(m%(3600*24)%3600)/60<<"分"<<(m%(3600*24)%3600)%60<<"秒"<<endl;
cout<<"确认请按 1 ,否则请按 0 : "<<endl;
cin>>set;
if(set)
{
break;
}
system("cls");
i++;
}
djsq(a,b,c,d);
//goto begin;
return 0;
}

提示:此倒计时结束时有声音

第3个回答  2020-07-05
//精简版:
#include <cstdio>
#include <Windows.h>
#include<iostream>
using namespace std;
int main()//框架
{

double d,h,m,s,time,mt;//声明时间单位以及总时间毫秒数的变量
cout<<"欢迎使用倒计时器,本软件最高可以倒计时40天"<<endl;
for(;;)//防止退出
{
cout<<"几天?(不足一天请写0)"<<endl;cin>>d;
cout<<"几小时?(不足一小时请写0)"<<endl;cin>>h;
cout<<"几分钟?(不足一分钟请写0)"<<endl;cin>>m;
cout<<"几秒?"<<endl;cin>>s;
cout<<"倒计时铃声响铃多少秒?"<<endl;cin>>mt;//输入数值
time=d*3600000*24+h*3600000+m*60000+s*1000;//计算时间总毫秒数
cout<<"正在计时";
Sleep(time);//开始倒计时

for(int a;a!=mt;a++)//开始响铃(通过循环以达到控制响铃时间)
{
Beep(1388,250);
Beep(1046,250);
Sleep(250);
Beep(1388,250);
}
system("pause");//暂停
system("cls");//清屏
}
}
第4个回答  2013-12-13
#include "stdafx.h"#include <windows.h>
#include <iostream.h>
#include <ctime> int main(int argc, char* argv[])
{
int s = 10;
while(s>0)
{
cout<<s<<endl;
Sleep(1000);
system("cls");
s--;
} system("pause");
return 0;
}
相似回答