Programming with Passion

Make the best out of everything.

Saturday, 15 October 2016

To make a Clock in Turbo C++

To make a Clock in Turbo C++



#include<math.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
void clock()
{
int i,m;
float pi=3.14,l=pi/180,x,y;
char *c;
setcolor(RED);
circle(320,240,150);
circle(320,240,148);
line(170,230,0,230);
line(170,228,0,228);
line(470,230,640,230);
line(470,228,640,228);
setcolor(WHITE);
circle(320,240,140);
circle(320,240,138);
line(170,240,0,240);
line(170,238,0,238);
line(470,240,640,240);
line(470,238,640,238);
setcolor(BLUE);
circle(320,240,130);
circle(320,240,128);
line(170,250,0,250);
line(170,248,0,248);
line(470,250,640,250);
line(470,248,640,248);
setcolor(WHITE);
  line (150,100,200,100);
line(155,105,193,105);
line(150,100,155,105);
line(200,100,190,150);
line(193,105,185,150);
line(185,150,190,150);
line(160,112,186,112);
line(163,117,185,117);
line(160,112,163,117);
line(186,112,185,117);
line(166,122,183,122);
line(169,127,181,127);
line(166,122,169,127);
line(183,122,181,127);

line (420,100,475,100);
line(430,105,473,105);
line(475,100,473,105);
line(420,100,445,150);
line(430,105,452,150);
line(445,150,452,150);
line(440,112,469,112);
line(443,117,465,117);
line(440,112,443,117);
line(469,112,465,117);
line(446,122,463,122);
line(449,127,461,127);
line(446,122,449,127);
line(463,122,461,127);

line(320,112,273,204);
line(273,204,183,218);
line(183,218,245,260);
line(245,260,234,350);
line(234,350,318,300);
line(318,300,404,352);
line(404,352,391,260);
line(391,260,460,218);
line(460,218,364,204);
line(364,204,320,112);

setcolor(RED);
for(i=0;i<12;++i)
{
x=110*cos(i*30*l);
x+=320;
y=110*sin(i*30*l);
y+=240;
if(i!=9)
m=(i+3)%12;
else m=12;
itoa(m,c,10);
settextstyle(10,0,4);
outtextxy(x,y,c);
}
}
void sec()
{
int r=100,Q=90,H=60,M=0;
float x,y,pi=3.14,l=pi/180,c,xh,yh,xm,ym;

while(1)
{
if(kbhit()){c=getch();
if(c=='e')exit(1); }   //key 'e'is used to exit the program...

x=((r-50)*cos(Q*l))+320;
y=((r-50)*sin(Q*l))+240;
xm=((r-40)*cos(M*l))+320;
ym=((r-40)*sin(M*l))+240;
xh=((r-50)*cos(H*l))+320;
yh=((r-50)*sin(H*l))+240;
setcolor(WHITE);
line(320,240,x,y);
line(320,240,xm,ym);
line(320,240,xh,yh);
delay(1);  //l
setcolor(BLACK);
line(320,240,x,y);
line(320,240,xm,ym);
line(320,240,xh,yh);

if(Q>360)Q=0;
else ++Q;
if(H>360)H=0;
if(M>360)M=0;
if(Q==270)++M;
if(M==270)++H;

}

}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\tc\\bgi");
clock();
sec();
getch();

}

No comments:

Post a Comment