| | |
Digital Clock in C++
Please support our C++ advertiser: Intel Parallel Studio Home
Here is simple Digital Clock coded in C++ and compiler used is TurboC.
A class DIGIT is designed to draw digits. Follwoing are the details for this class:
Consructor: DIDGT(); for default settings
DIGITE(int s,int c,int st); for user define settings
s -> is size of the digit
c -> color of the digit
st -> fill style of the digit
Methods: void DIGITE:
rawDig(int x,int y,int n)
x,y -> x and y coordinates of the screen
n -> interge value (<10) to be display
void DIGITE:
utDig(int x,int y,int n)
x,y -> x and y coordinates of the screen
n -> interge value (<100) to be display
void DIGITE::MakeBars()
internal function used to draw horizontal and vertical bars for the digits in the memory.
thats it!
A class DIGIT is designed to draw digits. Follwoing are the details for this class:
Consructor: DIDGT(); for default settings
DIGITE(int s,int c,int st); for user define settings
s -> is size of the digit
c -> color of the digit
st -> fill style of the digit
Methods: void DIGITE:
rawDig(int x,int y,int n)x,y -> x and y coordinates of the screen
n -> interge value (<10) to be display
void DIGITE:
utDig(int x,int y,int n)x,y -> x and y coordinates of the screen
n -> interge value (<100) to be display
void DIGITE::MakeBars()
internal function used to draw horizontal and vertical bars for the digits in the memory.
thats it!
/* Developed by: Vivek Kumar Email: vivek_kumar_bt@yahoo.co.in A Simple Digital Clock */ #include<iostream.h> #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<stdlib.h> #define DOTCOLOR 14 #define DIGCOLOR 4 class DIGITE { private: int X,Y; int SIZE; int COLOR; int HIGHT,WIDTH; void *VER,*HOR; public: int style; DIGITE(); DIGITE(int s,int c,int st); void MakeBars(); void PutDig(int x,int y,int n); void DrawDig(int x,int y,int n); ~DIGITE(); }; DIGITE::DIGITE() { style=1; SIZE=1; HIGHT=1; WIDTH=12; COLOR=15; MakeBars(); } DIGITE::DIGITE(int s,int c,int st) { style=st; SIZE=s; COLOR=c; HIGHT=1; WIDTH=6; MakeBars(); } void DIGITE::MakeBars() { int x,y,w,h; int area; x=10; y=getmaxy()/2; w=WIDTH*SIZE; h=HIGHT*SIZE; setfillstyle(style,COLOR); bar(x+h,y,x+w-h,y+h); setcolor(COLOR); line(x,y+h/2,x+h,y); line(x,y+h/2,x+h,y+h); floodfill(x+h/2,y+h/2,COLOR); setcolor(COLOR); line(x+w-h,y,x+w+-h+h,y+h/2); line(x+w-h,y+h,x+w-h+h,y+h/2); floodfill(x+w-h+h/2,y+h/2,COLOR); area=imagesize(x,y,x+w,y+h); HOR=malloc(area); if(HOR==NULL) { printf("Low Memory(Horizontal)...\nPress Any Key"); getch(); exit(0); } getimage(x,y,x+w,y+h,HOR); putimage(x,y,HOR,XOR_PUT); x=getmaxx()/2; y=10; h=SIZE*WIDTH; w=HIGHT*SIZE; bar(x,y+w,x+w,y+h-w); setcolor(COLOR); line(x,y+w,x+w/2,y); line(x+w,y+w,x+w/2,y); floodfill(x+w/2,y+w/2,COLOR); setcolor(COLOR); line(x,y+h-w,x+w/2,y+h); line(x+w,y+h-w,x+w/2,y+h); floodfill(x+w/2,y+h-w/2,COLOR); area=imagesize(x,y,x+w,y+h); VER=malloc(area); if(VER==NULL) { printf("Low Memory(Vertical)...\nPress Any Key"); getch(); exit(0); } getimage(x,y,x+w,y+h,VER); putimage(x,y,VER,XOR_PUT); } void DIGITE::PutDig(int x,int y,int n) { int num,gap,qu,rem; gap=(HIGHT*SIZE); num=n; if(num>=0&&num<10) { DrawDig(x,y,0); DrawDig(x+WIDTH*SIZE+HIGHT*SIZE+gap,y,n); } if(num>=10&&num<100) { qu=num/10; rem=num%10; DrawDig(x,y,qu); DrawDig(x+WIDTH*SIZE+HIGHT*SIZE+gap,y,rem); } } void DIGITE::DrawDig(int x,int y,int n) { int H[10][3]={1,0,1, 0,0,0, 1,1,1, 1,1,1, 0,1,0, 1,1,1, 1,1,1, 1,0,0, 1,1,1, 1,1,1}; int V[10][4]={1,1,1,1, 0,1,0,1, 0,1,1,0, 0,1,0,1, 1,1,0,1, 1,0,0,1, 1,0,1,1, 0,1,0,1, 1,1,1,1, 1,1,0,1}; int HX[3]={x,x,x}; int HY[3]={y,y+WIDTH*SIZE,y+2*WIDTH*SIZE}; int VX[4]={x-(HIGHT*SIZE)/2,x+WIDTH*SIZE-(HIGHT*SIZE)/2,x-(HIGHT*SIZE)/2,x+WIDTH*SIZE-(HIGHT*SIZE)/2}; int VY[4]={y+(HIGHT*SIZE)/2,y+(HIGHT*SIZE)/2,y+WIDTH*SIZE+(HIGHT*SIZE)/2,y+WIDTH*SIZE+(HIGHT*SIZE)/2}; int i; setfillstyle(1,getpixel(x-1,y-1)); bar(x-(SIZE*HIGHT)/2,y,x+WIDTH*SIZE+(SIZE*HIGHT)/2,y+2*SIZE*WIDTH+HIGHT*SIZE); for(i=0;i<3;i++) { if(H[n][i]==1) putimage(HX[i],HY[i],HOR,XOR_PUT); } for(i=0;i<4;i++) { if(V[n][i]==1) putimage(VX[i],VY[i],VER,XOR_PUT); } } DIGITE::~DIGITE() { delete VER; delete HOR; } void drawdot(); int color=DOTCOLOR; void main() { int gd=DETECT,gm,i; initgraph(&gd,&gm,""); struct time t; int th=t.ti_hour; int tm=t.ti_min; int ts=t.ti_sec; int tms=t.ti_hund; //setbkcolor(15); gettime(&t); DIGITE h(8,DIGCOLOR,1); DIGITE m(8,DIGCOLOR,1); DIGITE s(8,DIGCOLOR,1); DIGITE ms(2,DIGCOLOR,1); int y=200; int flag=1; h.PutDig(20,y,t.ti_hour); m.PutDig(220,y,t.ti_min); s.PutDig(380,y,t.ti_sec); ms.PutDig(500,y,t.ti_hund); while(!kbhit()) { gettime(&t); if(th!=t.ti_hour) { th=t.ti_hour; h.PutDig(20,y,t.ti_hour); } if(tm!=t.ti_min) { tm=t.ti_min; m.PutDig(220,y,t.ti_min); } if(ts!=t.ti_sec) { ts=t.ti_sec; s.PutDig(380,y,t.ti_sec); drawdot(); color=color-DOTCOLOR; if(color<0) color=DOTCOLOR; } if(tms!=t.ti_hund) { tms=t.ti_hund; ms.PutDig(500,y,t.ti_hund); } } getch(); } void drawdot() { int x,y,gap,size,c; c=color; gap=10; size=15; x=170; y=200; setfillstyle(1,color); bar(x+gap,y+gap,x+gap+size,y+gap+size); bar(x+gap,y+8*gap,x+gap+size,y+8*gap+size); //color=15; delay(0); }
Similar Threads
- hi, digital clock (Assembly)
- digital clock (C++)
- need source code for digital alarm clock using pic16f84a (Assembly)
- Code Snippet: Tkinter Digital Clock (Python) (Python)
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference simple string strings studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets



