#include<math.h> /* 引入math.h */
#include<dos.h> /* 引入dos.h */
#define pi 3.1415926 /*定义pi=3.14159*/
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240
#define d(a,b,c) X(a,b,c)Y(a,b,c)line(300,240,x,y) /*定义……*/
void init() /*初始化程序*/
{int i,l,x1,x2,y1,y2/*定义……*/
setbkcolor(1)/*设置颜色*/
circle(300,240,200)/*作园*/
circle(300,240,205)
circle(300,240,5)
for(i=0i<60i++) /*循环(算时间)*/
{if(i%5==0) l=15
else l=5
x1=200*cos(i*6*pi/180)+300
y1=200*sin(i*6*pi/180)+240
x2=(200-l)*cos(i*6*pi/180)+300
y2=(200-l)*sin(i*6*pi/180)+240
line(x1,y1,x2,y2)
}
}
main()
{
int x,y
int gd=VGA,gm=2
unsigned char h,m,s/*定义*/
struct time t[1]
initgraph(&gd,&gm,"d:\\tc")
init()
setwritemode(1)
gettime(t)
h=t[0].ti_hour
m=t[0].ti_min
s=t[0].ti_sec/*定义时分秒*/
setcolor(7)/*设置颜色*/
d(150,h,30)
setcolor(14)
d(170,m,6)
setcolor(4)
d(190,s,6)
while(!kbhit()) /*获取键盘相应*/
{while(t[0].ti_sec==s)
gettime(t)/*C语言中得到时间的函数*/
sound(400)/*计算时间……*/
delay(70)
sound(200)
delay(30)
nosound()
setcolor(4)
d(190,s,6)
s=t[0].ti_sec
d(190,s,6)
if (t[0].ti_min!=m)
{
setcolor(14)
d(170,m,6)
m=t[0].ti_min
d(170,m,6)
}
if (t[0].ti_hour!=h)
{ setcolor(7)
d(150,h,30)
h=t[0].ti_hour
d(150,h,30)
sound(1000)
delay(240)
nosound()
delay(140)
sound(2000)
delay(240)
nosound()
}
}
getch()/*设置空格后退出*/
closegraph()
}
http://zhidao.baidu.com/question/121241211.html
#include “windows.h”#include "iostream.h"
class MyTimer
{ private:
int hour
int minute
int sec
public:
MyTimer():hour(0),minute(0),sec(0){}
MyTimer(int h, int m, int s)
{ hour = h
minute = m
sec = s
}
void setTime(int h, int m, int s)
{ hour = h
minute = m
sec = s
}
void showTime()
{ while(1)
{ system("cls")
if(sec>=60)
{ sec = sec-60
minute +=1
}
if(minute>=60)
{ minute = minute-60
hour +=1
}
if(hour >=24)
{
hour = hour-24
}
cout<<hour<<":"<<minute<<":"<<sec<<endl
Sleep(1000)
sec++
}
}
}
在主函数创建一个MyTimer对象后调用showTime就行了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)