Friday, May 9, 2008

Analog Clock in C++ - Good Programme for Intermediates




Note: include the following header files : "iostream.h, conio.h, math.h, string.h, iomanip.h, stdlib.h, process.h, stdio.h, ctype.h, dos.h, graphics.h, alloc.h, errno.h, locale.h, setjmp.h, strstrea.h, values.h, time.h"

void exit();
void draw();
void back();
int gdriver = DETECT, gmode, error;
const float PI = 3.1415927;
struct time t;
int nodi, nimisa, mani;
char strmani[5]=" ";
char strnimisa[5]=" ";
char strnodi[5]=" ";
struct date d;
int varusam, matham, naal;
char strnaal[5]=" ";
char strmatham[5]=" ";
char strvarusam[5]=" ";
int maxx, maxy, nadux, naduy;
int totnodi;
float konam;
float r, x, y;

int main()
{ clrscr();
initgraph(&gdriver, &gmode, "c:\\tc\\");
error = graphresult();
if(error!=grOk)
{ cprintf("Graphics error : %s\n", grapherrormsg(error));
cprintf("Press any key to halt:");
getch();
exit(1);
};
nodi = nimisa = mani = 0;
matham = naal = varusam = 0;
maxx = getmaxx();
maxy = getmaxy();
nadux = (maxx*1)/3;
naduy = maxy/2;
draw();
konam = 0;
do
{ konam+=1;
r=PI/180*konam;
x=180*cos(r);
y=180*sin(r);
if((fmod(ceil(konam), 6))==0)
{ setcolor(LIGHTGREEN);
circle(nadux+x, naduy+y, 2);
}
if(fmod(ceil(konam), 30)==0)
{ setcolor(BLUE);
setfillstyle(SOLID_FILL, BLUE);
fillellipse(nadux+x, naduy+y, 2, 2);
if((fmod(ceil(konam), 90))!=0)
{ setcolor(YELLOW);
setfillstyle(SOLID_FILL, BLUE);
fillellipse(nadux+x, naduy+y, 5, 5);
setfillstyle(SOLID_FILL, LIGHTGRAY);
fillellipse(nadux+x, naduy+y, 2, 2);
}
}
}
while(konam<360);
setcolor(WHITE);
settextstyle(1, 0, 3);
outtextxy(200, 40, "12");
outtextxy(210, 400, "6");
outtextxy(390, 225, "3");
outtextxy(27, 225, "9");
do
{ back();
gettime(&t);
nodi=t.ti_sec;
nimisa=t.ti_min;
mani=t.ti_hour;
mani=mani%12;
getdate(&d);
varusam=d.da_year;
matham=d.da_mon;
naal=d.da_day;
setfillstyle(SOLID_FILL, 12);
fillellipse(nadux, naduy, 15, 15);
setfillstyle(SOLID_FILL, WHITE);
fillellipse(nadux, naduy, 10, 10);
setfillstyle(SOLID_FILL, GREEN);
fillellipse(nadux, naduy, 5, 5);
itoa(mani, strmani, 10);
if(strlen(strmani)==1)
{ strmani[2]='\0';
strmani[1]=strmani[0];
strmani[0]='0';
}
itoa(nimisa, strnimisa, 10);
if(strlen(strnimisa)==1)
{ strnimisa[2]='\0';
strnimisa[1]=strnimisa[0];
strnimisa[0]='0';
}
itoa(nodi, strnodi, 10);
if(strlen(strnodi)==1)
{ strnodi[2]='\0';
strnodi[1]=strnodi[0];
strnodi[0]='0';
}
itoa(naal, strnaal, 10);
if(strlen(strnaal)==1)
{ strnaal[2]='\0';
strnaal[1]=strnaal[0];
strnaal[0]='0';
}
itoa(matham, strmatham, 10);
if(strlen(strmatham)==1)
{ strmatham[2]='\0';
strmatham[1]=strmatham[0];
strmatham[0]='0';
}
itoa(varusam, strvarusam, 10);
setcolor(BLACK);
settextstyle(1, 0, 4);
moveto(478, 95);
outtext(strmani);
outtext(":");
outtext(strnimisa);
outtext(":");
outtext(strnodi);
setcolor(BLACK);
settextstyle(1, 0, 4);
moveto(435, 395);
outtext(strnaal);
outtext(".");
outtext(strmatham);
outtext(".");
outtext(strvarusam);

setlinestyle(SOLID_LINE, 0, 3);
totnodi = ((t.ti_hour%12)*60)+t.ti_min;
konam = (float)(((float)totnodi/(float)720)*2*PI);
konam-=PI/2;
setcolor(RED);
line(nadux, naduy, nadux + (100*cos(konam)), naduy+(100*sin(konam)));
setlinestyle(SOLID_LINE, 0, 3);
konam=((float)nimisa/60)*2*PI;
konam=konam-PI/2;
line(nadux, naduy, nadux+(145*cos(konam)), naduy+(145*sin(konam)));
setcolor(RED);
setlinestyle(SOLID_LINE, 0, 3);
konam=((float)nodi/60)*2*PI;
konam=konam-PI/2;
line(nadux, naduy, nadux+(150*cos(konam)), naduy+(150*sin(konam)));
delay(990);
setcolor(LIGHTGRAY);
setlinestyle(SOLID_LINE, 0, 3);
totnodi=t.ti_hour%12+t.ti_min;
konam = float((float)totnodi/(float)720*2*PI);
konam-=PI/2;
line(nadux, naduy, nadux+(100*cos(konam)), naduy+(100*sin(konam)));
konam=((float)nimisa/60)*2*PI;
konam=konam-PI/2;
line(nadux, naduy, nadux+(145*cos(konam)), naduy+(145*sin(konam)));

setlinestyle(SOLID_LINE, 0, 3);
konam=((float)nodi/60)*2*PI;
konam=konam-PI/2;
line(nadux, naduy, nadux+(150*cos(konam)), naduy+(150*sin(konam)));
}
while(!kbhit());
exit();
return 0;
}
void exit()
{ getch();
closegraph();
clrscr();
textbackground(BLACK);
textcolor(10);
gotoxy(1, 5);
//cprintf("********************************************************************************");
gotoxy(34, 10);
cprintf("Presented By:");
gotoxy(32, 12);
cprintf("----RAHUL DEY----");
gotoxy(36, 14);
cprintf("Copyright");
gotoxy(100, 16);
//cprintf("********************************************************************************");
delay(1000);
gotoxy(3, 23);
cprintf("Press Esc to exit...");
gotoxy(0, 30);
getch();
}

void draw()
{ setcolor(YELLOW);
rectangle(0, 0, maxx, maxy);
setcolor(YELLOW);
rectangle(2, 2, maxx-2, maxy-2);
setfillstyle(9, LIGHTRED);
bar(3, 3, maxx-3, maxy-3);
setcolor(LIGHTBLUE);
setfillstyle(SOLID_FILL, BLUE);
fillellipse(nadux, naduy, 200, 200);
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
fillellipse(nadux, naduy, 160, 160);
}

void back()
{ setlinestyle(SOLID_LINE, 0, 1);
setfillstyle(SOLID_FILL, WHITE);
bar(470, 101, 618, 130);

setcolor(BLACK);
rectangle(471, 101, 617, 129);

setcolor(DARKGRAY);
line(470, 130, 470, 100);
line(618, 100, 618, 100);

setcolor(WHITE);
line(470, 130, 618, 130);
line(618, 130, 618, 100);

setcolor(LIGHTGRAY);
rectangle(472, 102, 616, 128);

setlinestyle(SOLID_LINE, 0, 1);
setfillstyle(SOLID_FILL, WHITE);
bar(430, 400, 618, 430);

setcolor(BLACK);
rectangle(431, 401, 617, 429);

setcolor(DARKGRAY);
line(430, 430, 618, 430);
line(430, 400, 618, 400);

setcolor(WHITE);
line(430, 430, 618, 430);
line(618, 430, 618, 400);

setcolor(LIGHTGRAY);
rectangle(432, 402, 616, 428);

setcolor(9);
settextstyle(1, 0, 2);
moveto(132, 315);
outtext("Indian Standard");

setcolor(9);
settextstyle(1, 0, 2);
moveto(185, 340);
outtext("Time");

setcolor(YELLOW);
settextstyle(1, 0, 4);
moveto(470, 60);
outtext("TIME");

setcolor(YELLOW);
settextstyle(1, 0, 4);
moveto(430, 360);
outtext("DATE");
}

Download the exe file here...

http://rapidshare.com/files/116709015/ANALOG_CLOCK.zip

2 comments:

Rahul Dey said...

the hidden include files are
iostream.h
conio.h
math.h
string.h
iomanip.h
stdlib.h
process.h
stdio.h
ctype.h
fstream.h
dos.h
graphics.h
alloc.h
errno.h
locale.h
setjmp.h
strstrea.h
values.h
time.h

Anonymous said...

Hi all,

I am working for a software integrator company. My projects includes working on Java and Ruby on Rails and Ajax. I think Web Services is really cool. We also recently have to now work on REST and they are talking about mashups and Struts. Can anyone tell me if there are some good training or conferences so that me and my team members can get to speed with these technologies. Learning from books is not my cup of tea, even not when I was doing engineering ;)

All the help that group members can provide in this regard is much appreciated.

Thanks,
Vaibhaivi

If you want some improvements in the blog to serve you better, do vote for it!