| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 664 人关注过本帖
标题:C++时钟
只看楼主 加入收藏
RobinWang
Rank: 3Rank: 3
来 自:北京
等 级:论坛游侠
帖 子:69
专家分:121
注 册:2013-5-31
结帖率:50%
收藏
已结贴  问题点数:5 回复次数:3 
C++时钟
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>
#include<windows.h>
#include<iostream.h>
#define PI 3.1415926
void Draw(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;
int x_hour1,y_hour1,x_min1,y_min1,x_sec1,y_sec1;
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 = 320 +(int)(115 * sin(a_sec));
y_sec = 240 -(int)(115 * cos(a_sec));
x_min = 320 + (int)(100 * sin(a_min));
y_min = 240 - (int)(100 * cos(a_min));
x_hour= 320 + (int)(70 * sin(a_hour));
y_hour= 240 - (int)(70 * cos(a_hour));
/*------------------------------------------------------*/
x_sec1 = 320 +(int)(30 * sin(a_sec));
y_sec1 = 240 -(int)(30 * cos(a_sec));
x_min1 = 320 + (int)(20 * sin(a_min));
y_min1 = 240 - (int)(20 * cos(a_min));
x_hour1= 320 + (int)(20 * sin(a_hour));
y_hour1= 240 - (int)(20 * cos(a_hour));
setlinestyle(PS_SOLID,NULL,6);
setcolor(WHITE);
line(320,240,x_hour,y_hour);
line(320, 240, 640-x_hour1,480-y_hour1 );
setlinestyle(PS_SOLID, NULL, 4);
setcolor(LIGHTGRAY);
line(320, 240, x_min, y_min);
line(320, 240, 640-x_min1,480-y_min1 );
setlinestyle(PS_SOLID, NULL, 2);
setcolor(RED);
line(320, 240, x_sec, y_sec);
//line(320, 240, x_sec1, y_sec1);
line(320, 240, 640-x_sec1,480-y_sec1 );
}
void main(void)
{
initgraph(640,480);
/*----------------------------------------------------------------*/
circle(320,240,4);
circle(320,240,115);
circle(320,240,120);
rectangle(300,360,340,400);
rectangle(250,400,390,440);
circle(200,120,50);
circle(200,120,45);

circle(440,120,50);
circle(440,120,45);
outtextxy(210,235,'9');
outtextxy(425,235,'3');
outtextxy(315,130,"12");
outtextxy(315,339,'6');
outtextxy(262,322,'7');
outtextxy(260,145,"11");

outtextxy(370,322,'5');
outtextxy(370,145,'1');
outtextxy(225,287,'8');
outtextxy(408,287,'4');
outtextxy(222,185,"10");
outtextxy(410,181,'2');
outtextxy(180,110,"月");
outtextxy(220,110,"日");
outtextxy(410,110,"星期");
/*----------------------------------------------------------------*/
setwritemode(R2_XORPEN);
SYSTEMTIME ti; // SYSTEMTIME是一个结构体 //
char Second_R[1],Second_L[1];
char Minute_R[1],Minute_L[1];
char Hour_R[1],Hour_L[1];
while(!kbhit())
{
GetLocalTime(&ti);
// 把当前的时间给结构体变量ti,让它保存数据,用&ti作为实参是因为形参是指针,指针进行操作,直接改变原来的数据 //
/*----------------------------------------------------------------*/
switch(ti.wDayOfWeek)
{
case 0: setcolor(LIGHTRED);
outtextxy(450,110,"日");
break;
case 1: setcolor(YELLOW);
outtextxy(450,110,"一");
break;
case 2: setcolor(LIGHTCYAN);
outtextxy(450,110,"二");
break;
case 3: setcolor(LIGHTBLUE);
outtextxy(450,110,"三");
break;
case 4: setcolor(LIGHTGREEN);
outtextxy(450,110,"四");
break;
case 5: setcolor(LIGHTMAGENTA);
outtextxy(450,110,"五");
break;
case 6: setcolor(RGB(255,128,0));
outtextxy(450,110,"六");
break;
}
/*----------------------------------------------------------------*/

char Day[2],Month[2],Year[4];
setcolor(CYAN);
sprintf(Month,"%d",ti.wMonth);
outtextxy(160,110,Month);
sprintf(Day,"%d",ti.wDay);
outtextxy(205,110,Day);

setcolor(LIGHTMAGENTA);
sprintf(Year,"%d",ti.wYear);
outtextxy(305,370,Year);
/*----------------------------------------------------------------*/
Draw(ti.wHour,ti.wMinute,ti.wSecond);
/*----------------------------------------------------------------*/ sprintf(Hour_R, "%d", ti.wHour %10);
sprintf(Hour_L,"%d", (int)ti.wHour /10);
outtextxy(272,420,Hour_L);
outtextxy(280,420,Hour_R);
outtextxy(300,420,':');

sprintf(Minute_R, "%d", ti.wMinute %10);
sprintf(Minute_L,"%d", (int)ti.wMinute /10);
outtextxy(312,420,Minute_L);
outtextxy(320,420,Minute_R);
outtextxy(340,420,':');

sprintf(Second_R, "%d", ti.wSecond %10);
sprintf(Second_L,"%d", (int)ti.wSecond /10);
outtextxy(352,420,Second_L);
outtextxy(360,420,Second_R);
Sleep(1000);
Draw(ti.wHour,ti.wMinute,ti.wSecond);
}

/*----------------------------------------------------------------*/

getch();
closegraph();
}
搜索更多相关主题的帖子: minute double include 
2013-05-31 11:22
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:3 
晒代码?

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-05-31 12:27
新手坑
Rank: 2
等 级:论坛游民
帖 子:6
专家分:12
注 册:2013-5-30
收藏
得分:3 
复杂粘贴的作品。。。。鉴定完毕
2013-06-01 18:53
重邮肖冬冬
Rank: 1
等 级:新手上路
帖 子:6
专家分:2
注 册:2013-10-25
收藏
得分:0 
VC上运行不了吧
2013-10-25 23:03
快速回复:C++时钟
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.082580 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved