برنامه ساعت گرافیکی در c++
کد:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
class watch
{
public:
watch();
void set(int,int,int);
void start();
private:
float s,m,h;
void num();
void add();
};
watch::watch()
{
h=0; m=0; s=0;
num();
}
void watch::set(int ho,int mi, int se)
{
h=(ho>=0 && ho<24) ? ho : 0 ;
m=(mi>=0 && mi<60) ? mi : 0 ;
s=(se>=0 && se<60) ? se : 0 ;
if(h>=13 && h<=23)
h=h-12;
}
void watch::start()
{
while(!kbhit())
add();
}
void watch::add()
{
++s;
if(s==60)
{
s=0; ++m;
}
if(m==60)
{
m=0; ++h;
}
if(h==13) h=1;
int as,am,ah,bs,bm,bh,sx,sy,mx,my,hx,hy;
as=90*cos(3.14191*(90-(s*6))/180);
bs=90*sin(3.14191*(90-(s*6))/180);
am=75*cos(3.14191*(90-(m*6+s/10))/180);
bm=75*sin(3.14191*(90-(m*6+s/10))/180);
ah=45*cos(3.14191*(90-(h*30+m/2))/180);
bh=45*sin(3.14191*(90-(h*30+m/2))/180);
sx=320+as;
sy=240-bs;
mx=320+am;
my=240-bm;
hx=320+ah;
hy=240-bh;
setcolor(6);
fillellipse(320,240,5,5);
setcolor(WHITE);
setlinestyle(SOLID_LINE,0,1);
line(320,240,sx,sy);
setcolor(YELLOW);
setlinestyle(SOLID_LINE,0,3);
line(320,240,mx,my);
setcolor(RED);
setlinestyle(SOLID_LINE,0,3);
line(320,240,hx,hy);
delay(1000);
setcolor(BLACK);
line(320,240,sx,sy);
line(320,240,mx,my);
line(320,240,hx,hy);
}
void watch::num()
{
//---------cadr-----------
setcolor(WHITE);
rectangle(170,90,470,390);
setcolor(RED);
rectangle(175,95,465,385);
setcolor(WHITE);
rectangle(180,100,460,380);
//---------number---------
setcolor(10);
settextstyle(7,0,1);
circle(370,153,3);//1
circle(406,190,3);//2
outtextxy(415,230,"3");//3
circle(406,290,3);//4
circle(370,326,3);//5
outtextxy(315,330,"6");//6
circle(270,326,3);//7
circle(233,290,3);//8
outtextxy(215,227,"9");//9
circle(233,190,3);//10
circle(270,153,3);//11
outtextxy(310,125,"12");//12
}
int main()
{
clrscr();
int h,m,s;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
outtextxy(10,50,"::.. Current Time ..::");
outtextxy(10,450,"Press any key to end ...");
watch w;
time t;
gettime(&t);
w.set(t.ti_hour,t.ti_min,t.ti_sec);
w.start();
getch();
return 0;
}