#include"stdioh"
struct clock
{
int hour;
int minute;
int second;
};
typedef struct clock CLOCK;
void update (CLOCK t)
{
t->second++;
if(t->second==60)
{
t->second=0;
t->minute++;
}
if(t->minute==60)
{
t->minute=0;
t->hour++;
}
if(t->hour==24)
t->hour=0;
}
void display(CLOCK t)
{
printf("%02d:%02d:%02d\r",t->hour,t->minute,t->second);
}
void deplay()
{
int t;
for(t=0;t<10000;t++);
}
main()
{
CLOCK a;
CLOCK time=&a;
time->hour=time->minute=time->second=0;
for(;;)
{
update(time);
display(time);
deplay();
}
} #include"graphicsh"
#define PI 31416
#include"mathh"
#include"dosh"
main()
{
int x0=320,y0=240,r0=150;
void init_sceen();
void sec();
init_sceen(x0,y0,r0);
sec();
closegraph();
}
void init_sceen(int x0,int y0,int r0)//
{
int i,x,y,graphdriver,graphmode;
char s[10];
float alpha,a0=90;
graphdriver=DETECT;
initgraph(&graphdriver,&graphmode,"");
setbkcolor(3);
setcolor(2);
circle(x0,y0,r0);
circle(x0,y0,r0+30);
setfillstyle(SOLID_FILL,10);
floodfill(x0-r0-10,y0,2);
/please input the time/
for(i=12;i>=1;i--)
{
alpha=(a0+30(11-i)PI/180);
x=x0+cos(alpha)r0-16;
y=y0-sin(alpha)r0;
sprintf(s,"%2d",i);
setcolor(4);
settextstyle(0,0,2);
outtextxy(x,y,s);
}
/input second/
for(i=60;i>=1;i--)
{
alpha=(a0+6(60-i)PI/180);
x=x0+cos(alpha)(r0-20);
y=y0-sin(alpha)(r0-20);
setcolor(14);
if(i%5==0)
circle(x,y,5);
else circle(x,y,2);
floodfill(x,y,14);
}
setlinestyle(0,0,3);
}
void sec(void) //
{
int x,y,i,j,k,xj,yj,xk,yk,xi,yi,x0=320,y0=240,r0=150;
union REGS r;
unsigned char shijie="";
unsigned char daa="";
struct time tim;
struct date dat;
float alphai,alphak,alphaj,a0=90;
xi=x0;yi=y0;xj=x0;yj=y0;xk=x0;yk=y0;
do
{
/intput the time/
x=38;y=12;
gettime(&tim);
sprintf(shijie,"%02d:%02d:%02d",timti_hour,timti_min,timti_sec);
setfillstyle(SOLID_FILL,0);
bar(245,190,375,210);
setcolor(15);
outtextxy(245,190,shijie);
/input the date/ //
getdate(&dat);
sprintf(daa,"%02d--%02d--%02d",datda_year,datda_mon,datda_day);
/setfillstyle(SOLID_FILL,3);/
bar(225,290,395,310);
setcolor(BLUE);
outtextxy(225,290,daa);
x=190;y=430;
setcolor(BLUE);
outtextxy(x-26,y,"Designed by Xing Lei");
setcolor(LIGHTRED);
outtextxy(x+60,y0+20,"xing loving");
setlinestyle(0,0,3);
k=timti_hour;
j=timti_min;
i=timti_sec;
alphak=(a0+30(12-k)-j5/606)PI/180;
alphaj=(a0-6j)PI/180;
/write second hand/
alphai=(a0+6(60-i))PI/180;
x=x0+cos(alphai)(r0-32);
y=y0-sin(alphai)(r0-32);
setcolor(BLACK);
line(x0,y0,xi,yi);
setcolor(YELLOW);
line(x0,y0,x,y);
xi=x;
yi=y;
/write minute hand/
x=x0+cos(alphaj)(r0-60);
y=y0-sin(alphaj)(r0-60);
setcolor(BLACK);
line(x0,y0,xj,yj);
setcolor(BLUE);
line(x0,y0,x,y);
xj=x;
yj=y;
/write hour hand/
x=x0+cos(alphak)(r0-99);
y=y0-sin(alphak)(r0-99);
setcolor(BLACK);
line(x0,y0,xk,yk);
setcolor(RED);
line(x0,y0,x,y);
xk=x;
yk=y;
delay(10000);
}
while(!kbhit());
}
/开发环境:turbo c 20模拟时钟转动程序代码/
#include"graphicsh"
#include"mathh"
#include"dosh"
#define pi 31415926
#define X(a,b,c) x=acos(bcpi/180-pi/2)+300
#define Y(a,b,c) y=asin(bcpi/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=0;i<60;i++) /划钟点上的短线/
{
if(i%5==0)
l=15;
else
l=5;
x1=200sin(i6pi/180)+300;
y1=200cos(i6pi/180)+240;
x2=(200-l)sin(i6pi/180)+300;
y2=(200-l)cos(i6pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y,i,k=1;
int gdriver=9,gmode=2;
unsigned char h,m,s;
int o,p,q;
float n;
struct time t[1];
struct date d[1];
initgraph(&gdriver,&gmode,"c:\\tc");
initgraph(&gdriver,&gmode,"c:\\tc");
for(i=0;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i); /控制输出字符的字体,方向,大小/
cleardevice();
settextjustify(1,1); /在指定坐标上输出字符串/
outtextxy(300,80,"12") ;
outtextxy(300,390,"6");
outtextxy(140,230,"9");
outtextxy(460,230,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(220,370,"7");
outtextxy(160,160,"10");
outtextxy(160,310,"8");
}
init();
setwritemode(1); /设置画线的输出模式/
if(k!=0)
{
getdate(d); /获得系统日期函数/
o=d[0]da_year;
p=d[0]da_mon;
q=d[0]da_day;
gettime(t); /获得系统时间函数/
h=t[0]ti_hour;
m=t[0]ti_min;
s=t[0]ti_sec;
}
setcolor(7); /设置时针颜色/
n=(float)h+(float)m/60;
d(150,n,30); /画出时针/
setcolor(14); /设置分针颜色/
d(170,m,6); /画出分针/
setcolor(4); /设置秒针颜色/
d(190,s,6); /画出秒针/
while(!kbhit()) /控制程序按下任意键退出/
{
while(t[0]ti_sec==s)
gettime(t);
gotoxy(44,18); /使光标移动到指定坐标/
printf("\b\b\b\b\b\b\b\b\b"); /退格,使表示时间的字符串不断变化/
sound(400); /按给定的频率打开PC扬声器/
delay(70); /中断程序的执行,时间为70毫秒/
sound(200);
delay(30);
nosound(); /按给定的频率关闭PC扬声器/
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();
}
if(s<10) /用字符的形式输出时间/
{ if(m<10)
printf("%u:0%u:0%u",h,m,s);
else
printf("%u:%u:0%u",h,m,s);
}
else
{ if(m<10)
printf("%u:0%u:%u",h,m,s);
else
printf("%u:%u:%u",h,m,s);
}
gotoxy(34,19); /在指定坐标上输出日期/
printf("%d年%d月%d日",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph();
}
////////////////////////////////////////////
// 程序名称:钟表模拟程序(表针形式)
// 编译环境:Visual C++ 60,EasyX 2011惊蛰版
// 程序编写:BestAns <BestAns@qqcom>
// 最后更新:2010-10-30
//
#include
<graphicsh>
#include
<conioh>
#include
<mathh>
#define
PI
31415926536
void
DrawHand
(
int
hour
,
int
minute
,
int
second
)
{
double
a_hour
,
a_min
,
a_sec
;
// 时、分、秒针的弧度值
int
x_hour
,
y_hour
,
x_min
,
y_min
,
x_sec
,
y_sec
;
// 时、分、秒针的末端位置
// 计算时、分、秒针的弧度值
a_sec
=
second
2
PI
/
60
;
a_min
=
minute
2
PI
/
60
+
a_sec
/
60
;
a_hour
=
hour
2
PI
/
12
+
a_min
/
12
;
// 计算时、分、秒针的末端位置
x_sec
=
int
(
120
sin
(
a_sec
));
y_sec
=
int
(
120
cos
(
a_sec
));
x_min
=
int
(
100
sin
(
a_min
));
y_min
=
int
(
100
cos
(
a_min
));
x_hour
=
int
(
70
sin
(
a_hour
));
y_hour
=
int
(
70
cos
(
a_hour
));
// 画时针
setlinestyle
(
PS_SOLID
,
NULL
,
10
);
setcolor
(
WHITE
);
line
(
320
+
x_hour
,
240
-
y_hour
,
320
-
x_hour
/
7
,
240
+
y_hour
/
7
);
// 画分针
setlinestyle
(
PS_SOLID
,
NULL
,
6
);
setcolor
(
LIGHTGRAY
);
line
(
320
+
x_min
,
240
-
y_min
,
320
-
x_min
/
5
,
240
+
y_min
/
5
);
// 画秒针
setlinestyle
(
PS_SOLID
,
NULL
,
2
);
setcolor
(
RED
);
line
(
320
+
x_sec
,
240
-
y_sec
,
320
-
x_sec
/
3
,
240
+
y_sec
/
3
);
}
void
DrawDial
()
{
// 绘制一个简单的表盘
circle
(
320
,
240
,
2
);
circle
(
320
,
240
,
60
);
circle
(
320
,
240
,
160
);
outtextxy
(
296
,
310
,
"BestAns"
);
// 绘制刻度
int
x
,
y
;
for
(
int
i
=
0
;
i
<
60
;
i
++)
{
x
=
320
+
int
(
145
sin
(
PI
2
i
/
60
));
y
=
240
+
int
(
145
cos
(
PI
2
i
/
60
));
if
(
i
%
15
==
0
)
bar
(
x
-
5
,
y
-
5
,
x
+
5
,
y
+
5
);
else
if
(
i
%
5
==
0
)
circle
(
x
,
y
,
3
);
else
putpixel
(
x
,
y
,
WHITE
);
}
}
void
main
()
{
initgraph
(
640
,
480
);
// 初始化 640 x 480 的绘图窗口
DrawDial
();
// 绘制表盘
setwritemode
(
R2_XORPEN
);
// 设置 XOR 绘图模式
// 绘制表针
SYSTEMTIME
ti
;
// 定义变量保存当前时间
while
(!
kbhit
())
// 按任意键退出钟表程序
{
GetLocalTime
(&
ti
);
// 获取当前时间
DrawHand
(
ti
wHour
,
ti
wMinute
,
ti
wSecond
);
// 画表针
Sleep
(
1000
);
// 延时 1 秒
DrawHand
(
ti
wHour
,
ti
wMinute
,
ti
wSecond
);
// 擦表针(擦表针和画表针的过程是一样的)
}
closegraph
();
// 关闭绘图窗口
}
其了就是用了easyx
以上就是关于可以用C++编写钟表程序吗每隔一秒自动走的那种,要代码!!!全部的内容,包括:可以用C++编写钟表程序吗每隔一秒自动走的那种,要代码!!!、C语言程序设计题:模拟时钟转动的程序、跪求C语言编写的时钟(能修改时钟时间,且时钟是指针式的 只编写修改时间的部分也行)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)