Programming C++?
Programming C++?
programming: Who can write a program in C++ which shows how a timer works!and designs the graphic of it!(with class and functions
Programming C++?
#include %26lt;dos.h%26gt;
#include%26lt;stdio.h%26gt;
#include%26lt;iostream.h%26gt;
#include%26lt;math.h%26gt;
#include%26lt;stdlib.h%26gt;
#include%26lt;graphics.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
struct time timep;
double varx,vary;
int x,y;
char daylist[][15]={"SUNDAY","MONDAY","TUESDA...
int day;
int cal_arr[7][7]={0,0};
int mon_arr[13];
void watch_draw(void);
void init()
{
clrscr();
int gd,gm;
gd=DETECT;
registerfarbgidriver(EGAVGA_driver_far);
initgraph(%26amp;gd,%26amp;gm,NULL);
setlinestyle(SOLID_LINE,0,3);
outtextxy(50,10,"ANALOG CLOCK");
setcolor(GREEN);
x=getmaxx();
y=getmaxy();
setlinestyle(SOLID_LINE,0,3);
line(25,25,x-25,25);
line(x-25,25,x-25,y-25);
line(x-25,y-25,25,y-25);
line(25,y-25,25,25);
setlinestyle(SOLID_LINE,0,1);
line(22,22,x-22,22);
line(x-22,22,x-22,y-22);
line(x-22,y-22,22,y-22);
line(22,y-22,22,22);
}
void draw_clock()
{
setlinestyle(SOLID_LINE,0,3);
setcolor(RED);
circle(x/2,y/2,100);
circle(x/2,y/2,2);
setcolor(GREEN);
setlinestyle(SOLID_LINE,0,2);
for(int i=1;i%26lt;=12;i++)
{
vary=(22.0/7.0)*(i*30)/180;
vary=cos(vary);
varx=(22.0/7.0)*(i*30)/180;
varx=sin(varx);
varx=102 * varx;
vary=102 * vary;
circle(x/2+varx,y/2+vary,2);
}
setcolor(CYAN);
for(i=1;i%26lt;=60;i++)
{
vary=(22.0/7.0)*(i*6)/180;
vary=cos(vary);
varx=(22.0/7.0)*(i*6)/180;
varx=sin(varx);
varx=102 * varx;
vary=102 * vary;
circle(x/2+varx,y/2+vary,1);
}
outtextxy(x/2-5,y/2-113,"12");
outtextxy(x/2-3,y/2+110,"6");
outtextxy(x/2+105,y/2-2,"3");
outtextxy(x/2-113,y/2-2,"9");
setfillstyle(1,BLUE);
fillellipse(x/2,y/2,99,99);
}
void func_clock()
{
double prev_secx,prev_secy,prev_minx,prev_miny,...
int hour_temp;
int flag_sec=0,flag_min=0,flag_hour=0;
unsigned char counter_min,counter_hour;
while(!kbhit())
{
watch_draw();
/* second display */
gettime(%26amp;timep);
vary=(22.0/7.0)*(180-timep.ti_sec*6)/180...
vary=cos(vary);
varx=(22.0/7.0)*(180-timep.ti_sec*6)/180...
varx=sin(varx);
varx=90 * varx;
vary=90 * vary;
if(!flag_sec){prev_secx=varx; prev_secy=vary;}
flag_sec=1;
setlinestyle(SOLID_LINE,0,1);
setcolor(BLUE);
line(x/2,y/2,x/2+prev_secx,y/2+prev_secy...
setcolor(CYAN);
line(x/2,y/2,x/2+varx,y/2+vary);
prev_secx=varx; prev_secy=vary;
/* minute display */
counter_min=counter_min+1;
if(timep.ti_sec==30)
counter_min=0;
if(counter_min%30==0||flag_min==0)
{
vary=(22.0/7.0)*(180-timep.ti_min*6)/180...
vary=cos(vary);
varx=(22.0/7.0)*(180-timep.ti_min*6)/180...
varx=sin(varx);
varx=80 * varx;
vary=80 * vary;
if(!flag_min){prev_minx=varx; prev_miny=vary;}
flag_min=1;
setlinestyle(SOLID_LINE,0,3);
setcolor(BLUE);
line(x/2,y/2,x/2+prev_minx,y/2+prev_miny...
setcolor(BROWN);
line(x/2,y/2,x/2+varx,y/2+vary);
prev_minx=varx; prev_miny=vary;
}
counter_hour=counter_hour+1;
if(timep.ti_min==0)
counter_hour=0;
/* hour display */
if(counter_hour%5==0||flag_hour==0)
{
hour_temp=timep.ti_hour;
if(timep.ti_hour%26gt;12)
hour_temp-=12;
vary=(22.0/7.0)*(180-(hour_temp*30)-(tim...
vary=cos(vary);
varx=(22.0/7.0)*(180-(hour_temp*30)-(tim...
varx=sin(varx);
varx=60 * varx;
vary=60 * vary;
if(!flag_hour){prev_hourx=varx; prev_houry=vary;}
flag_hour=1;
setcolor(BLUE);
setlinestyle(SOLID_LINE,0,3);
line(x/2,y/2,x/2+prev_hourx,y/2+prev_hou...
setcolor(RED);
line(x/2,y/2,x/2+varx,y/2+vary);
prev_hourx=varx; prev_houry=vary;
}
}
getch();
}
/* Digital display */
void watch_draw()
{
struct time ti_di;
char ch[100];
char prev_char[100];
settextstyle(0,0,3);
gettime(%26amp;ti_di);
sprintf(ch,"%2d:%02d:%02d:%02d",ti_di.ti... ti_di.ti_min,
ti_di.ti_sec,ti_di.ti_hund);
setcolor(RED);
outtextxy(175,75,ch);
delay(20);
setcolor(BLACK);
strcpy(prev_char,ch);
outtextxy(175,75,prev_char);
}
void dayfunc(int dd,int mm,int yy)
{
int cal4;
cal4=(yy-1)/4;
int cal100;
cal100=(yy-1)/100;
int cal=3200;
int test=0;
while(1)
{
test=(yy-1)/cal;
if(test) break;
cal-=400;
}
test=cal/400;
int ans1;
ans1=cal4-cal100+test;
int dayarr[]={0,3,0,3,2,3,2,3,3,2,3,2,3};
int sum=0;
test=1;
while(test%26lt;mm)
{
sum+=dayarr[test];
test+=1;
}
int flag=0;
if((yy%100)==0)
{
if((yy%400)==0) flag=1;
}else if((yy%4)==0) flag=1;
for(int m=1;m%26lt;=7;m++)
{
if((m%2)==1)
mon_arr[m]=31;
else mon_arr[m]=30;
}
for(m=8;m%26lt;=12;m++)
{
if((m%2)==0)
mon_arr[m]=31;
else mon_arr[m]=30;
}
if(flag) {
mon_arr[2]=29;
sum=sum+1;
}else mon_arr[2]=28;
int calday;
calday=dd%7;
int total;
total=2*ans1+(yy-1-ans1)+sum+calday;
day=total%7;
}
void cal_func()
{
struct date d;
getdate(%26amp;d);
int mm,yy;
mm=d.da_mon;
yy=d.da_year;
dayfunc(1,mm,yy);
int i,j,k;
for(i=1,k=0,j= day;i%26lt;=mon_arr[mm];i++,j++)
{
if(!(j=j%7) %26amp;%26amp; i!=1) k++;
cal_arr[j][k]=i;
}
/*
for(i=0;i%26lt;=6;i++)
{
for(j=0;j%26lt;=6;j++)
{
cout%26lt;%26lt;cal_arr[i][j]%26lt;%26lt;" ";
}
cout%26lt;%26lt;endl;
}
*/
}
void draw_cal()
{
settextstyle(0,0,2);
setcolor(RED);
outtextxy(55,245,"CALENDAR");
settextstyle(0,0,1);
outtextxy(35,270,"SUN:");
outtextxy(35,290,"MON:");
outtextxy(35,310,"TUE:");
outtextxy(35,330,"WED:");
outtextxy(35,350,"THU:");
outtextxy(35,370,"FRI:");
outtextxy(35,390,"SAT:");
cal_func();
setcolor(CYAN);
rectangle(30,265,215,410);
for(int i=0;i%26lt;=6;i++)
{
for(int j=0;j%26lt;=5;j++)
{
if( cal_arr[i][j] !=0)
{
char c[2];
itoa(cal_arr[i][j],c,10);
//cout%26lt;%26lt;cal_arr[i][j]%26lt;%26lt;" ";
outtextxy((70+(25 * j)),(270+(20 * i)),c);
//c[0]='\0';
//c[1]='\0';
}
}
cout%26lt;%26lt;endl;
}
}
void main()
{
init();
draw_clock();
draw_cal();
func_clock();
}
this was implemented by me. hope it is good enough
palm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment