代码如下:
Dim n As Integer
Dim t As String
Private Sub Command1_Click()'计时开始
If Text1.Text = "" Then
Exit Sub
End If
t = Val(Text1.Text)
Timer1.Enabled = True
Label1.Caption = "剩余时间:" &t &"分钟"
End Sub
Private Sub Command2_Click() '退出程序
End
End Sub
Private Sub Timer1_Timer()
n = n + 1
Label1.Caption = "剩余时间:" &t - n &"分钟"
If n = t Then
Beep
MsgBox "时间到", vbExclamation + vbOKOnly
Timer1.Enabled = False
n = 0
End If
End Sub
Private Sub Timer2_Timer()
Label2.Caption = "现在时间:" &Time
End Sub
#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
}
}
}
}
} //有何问题请多指教!!!!!!!望采纳! 设置倒计时时间长度。 倒计时中。 计时结束!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)