Sunday, October 25, 2009

C++ program to display a calender

A simple C++ graphics program to display a Calender.It also gives an introduction to mouse programming in graphics. Save the file with a '.cpp' extension and compile it.


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
union REGS i,o;
initmouse();
showmouse();
hidemouse();
void restrictmouse(int x1,int y1,int x2,int y2);
void getmousestatus( int *button,int *x,int *y);
void findday();
void menu();
void cal();
void main()
{
clrscr();
int gd=EGA,gm=EGAHI;
initgraph(&gd,&gm,"c:\\tc\\bgi ");
menu();
getch();
closegraph();
}
void findday()
{
int k=1,m=11,mon,D,C,f,i,y,total=0,t,I,d,x1=115,y1=160,q,r,v;
static int s=0;
char st2[3],st3[9],st4[5];
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
char
*month[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMEBER"};
restorecrtmode();
cout<<"Enter year : ";
cin>>y;
cout<<"Enter month : ";
cin>>mon;
if(mon>12)
{
cout<<" Invalid entry !.....";
delay(1000);
setgraphmode(getgraphmode());
menu();
}
y-=1;
C=y/100;
D=y%100;
f=(k+((13*m-1)/5)+D+(D/4)+(C/4)-(2*C));
i=f%7;
if(i< 0)
i+=7;
y++;
if(y%4==0)
days[1]=29;
for(t=0;t<mon-1;t++)
{
total+=days[t];
}
I=total%7;
d=I+i;
if(d>=7)
d=d%7;
setgraphmode(getgraphmode());
cal();
v=mon-1;
strcpy(st3,month[v]);
itoa(y,st4,10);
settextstyle(2,0,8);
outtextxy(100,90,st3);
outtextxy(250,90,st4);
q=days[mon-1];
settextstyle(1,0,2);
setcolor(15);
for(r=1;r<=d;r++)
{
x1+=62;
s++;
}
for(r=1;r<=q;r++)
{
itoa(r,st2,10);
if(s>=6)
{
outtextxy(x1,y1,st2);
y1+=30;
x1=112;
s=0;
continue;
}
outtextxy(x1,y1,st2);
x1+=60;
s++;
}
s=0;
getch();
menu();
}
void menu()
{
cleardevice();
int b,xx,yy;
initmouse();
restrictmouse(0,0,getmaxx(),getmaxy());
setbkcolor(0);
settextstyle(10,0,2);
outtextxy(100,70,"***********MENU***********");
outtextxy(100,150,"=> MONTH'S CALENDAR");
outtextxy(100,200,"=> EXIT");
settextstyle(8,0,1);
outtextxy(350,300,"Made By: ANGAD");
showmouse();
while(!kbhit())
{
getmousestatus(&b,&xx,&yy);
if(xx>=100&&yy>=150&&xx<=500&&yy<=200)
{
getmousestatus(&b,&xx,&yy);
if(b&1==1)
{
hidemouse();
cleardevice();
findday();
}
}
if(xx>=100&&yy>=200&&xx<=300&&yy<=260)
{
getmousestatus(&b,&xx,&yy);
if(b&1==1)
{
hidemouse();
cleardevice();
setbkcolor(0);
setcolor(15);
settextstyle(10,0,5);
outtextxy(100,200,"EXITING");
int o=0;
for(int n=0;n< 10;n++)
{
outtextxy(380+o,200,".");
o+=20;
delay(200);
}
exit(0);
}
}
}
}
void cal()
{
cleardevice();
int l=100,t=125,r=155,b=185,g,x=110,y=127;
char *day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
char st1[4];
setbkcolor(0);
settextstyle(10,0,7);
setcolor(15);
outtextxy(100,-40,"C");
settextstyle(10,0,6);
outtextxy(160,-20,"ALENDAR");
setfillstyle(1,BLUE);
bar(85,115,530,345);
setfillstyle(1,0);
bar3d(l,t,r,b,0,0);
bar3d(l,t+30,r,b+30,0,0);
bar3d(l,t+60,r,b+60,0,0);
bar3d(l,t+90,r,b+90,0,0);
bar3d(l,t+120,r,b+120,0,0);
bar3d(l,t+150,r,b+150,0,0);
bar3d(l,t+180,r,b+150,0,0);
bar3d(l+60,t,r+60,b,0,0);
bar3d(l+60,t+30,r+60,b+30,0,0);
bar3d(l+60,t+60,r+60,b+60,0,0);
bar3d(l+60,t+90,r+60,b+90,0,0);
bar3d(l+60,t+120,r+60,b+120,0,0);
bar3d(l+60,t+150,r+60,b+150,0,0);
bar3d(l+60,t+180,r+60,b+150,0,0);
bar3d(l+120,t,r+120,b,0,0);
bar3d(l+120,t+30,r+120,b+30,0,0);
bar3d(l+120,t+60,r+120,b+60,0,0);
bar3d(l+120,t+90,r+120,b+90,0,0);
bar3d(l+120,t+120,r+120,b+120,0,0);
bar3d(l+120,t+150,r+120,b+150,0,0);
bar3d(l+120,t+180,r+120,b+150,0,0);
bar3d(l+180,t,r+180,b,0,0);
bar3d(l+180,t+30,r+180,b+30,0,0);
bar3d(l+180,t+60,r+180,b+60,0,0);
bar3d(l+180,t+90,r+180,b+90,0,0);
bar3d(l+180,t+120,r+180,b+120,0,0);
bar3d(l+180,t+150,r+180,b+150,0,0);
bar3d(l+180,t+180,r+180,b+150,0,0);
bar3d(l+240,t,r+240,b,0,0);
bar3d(l+240,t+30,r+240,b+30,0,0);
bar3d(l+240,t+60,r+240,b+60,0,0);
bar3d(l+240,t+90,r+240,b+90,0,0);
bar3d(l+240,t+120,r+240,b+120,0,0);
bar3d(l+240,t+150,r+240,b+150,0,0);
bar3d(l+240,t+180,r+240,b+150,0,0);
bar3d(l+300,t,r+300,b,0,0);
bar3d(l+300,t+30,r+300,b+30,0,0);
bar3d(l+300,t+60,r+300,b+60,0,0);
bar3d(l+300,t+90,r+300,b+90,0,0);
bar3d(l+300,t+120,r+300,b+120,0,0);
bar3d(l+300,t+150,r+300,b+150,0,0);
bar3d(l+300,t+180,r+300,b+150,0,0);
bar3d(l+360,t,r+360,b,0,0);
bar3d(l+360,t+30,r+360,b+30,0,0);
bar3d(l+360,t+60,r+360,b+60,0,0);
bar3d(l+360,t+90,r+360,b+90,0,0);
bar3d(l+360,t+120,r+360,b+120,0,0);
bar3d(l+360,t+150,r+360,b+150,0,0);
bar3d(l+360,t+180,r+360,b+150,0,0);
settextstyle(1,0,2);
setcolor(15);
for(g=0;g< 7;g++)
{
strcpy(st1,day[g]);
outtextxy(x,y,st1);
x+=60;
}
}
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
showmouse()
{
i.x.ax=1;
int86(0x33,&i,&o);
return(o.x.ax);
}
hidemouse()
{
i.x.ax=2;
int86(0x33,&i,&o);
return(o.x.ax);
}
void restrictmouse(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}
void getmousestatus(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

35 comments:

太可怕 said...
This comment has been removed by a blog administrator.
佩璇佩璇 said...

^^ 謝謝你的分享,祝你生活永遠多彩多姿!........................................

怡均怡均怡均 said...

It's great!!..........................................

G702aynelleKress0 said...

blog不錯唷~我會常常來看的~加油~!! .........................

冠慧 said...

這一生中有多少人擦肩而過?而朋友是多麼可貴啊!..................................................

ShaneT_Rogers皇雯 said...

辛苦了!祝你愈來愈好!.............................................

天光天光 said...
This comment has been removed by a blog administrator.
熙辰 said...

好喜歡你的部落格唷,剛下班,要去睡了!!!掰~~..................................................

josema said...

希望能常常看到你的更新........................................

皇雯皇雯 said...
This comment has been removed by a blog administrator.
玫友 said...

要持續更新下去喲!!祝你心情愉快.................................................................

江婷 said...
This comment has been removed by a blog administrator.
貴寶 said...
This comment has been removed by a blog administrator.
原秋原秋 said...
This comment has been removed by a blog administrator.
羅承霞 said...
This comment has been removed by a blog administrator.
雅芳 said...
This comment has been removed by a blog administrator.
原秋原秋 said...

我來湊熱鬧的~~^^ 要平安快樂哦..................................................................

香昱信張君林 said...

看到大家都留言-我也忍不住說聲---加油..................................................................

賢林賢林 said...
This comment has been removed by a blog administrator.
明儒 said...
This comment has been removed by a blog administrator.
佳皓 said...
This comment has been removed by a blog administrator.
洪瑋婷洪瑋婷 said...

來看你囉~加油~~!!.................................[/url]...............

魏智偉魏智偉 said...

感謝分享唷^^~~.........................................

俊張霖 said...
This comment has been removed by a blog administrator.
陳陳昀人良喬 said...

嘩做左推介BLOG 果然人氣勁旺............................................................

亦奈美妮 said...

君子立恆志,小人恆立志。............................................................

偉曹琬 said...
This comment has been removed by a blog administrator.
靜詹怡詹詹 said...

出遊不拘名勝,有景就是好的..................................................................

蔡曼鄭美玉屏 said...

Necessity is the mother of invention.......................................................................

翊翊翊翊張瑜翊翊翊 said...

困難的不在於新概念,而在於逃避舊有的概念。......................................................................

孫邦柔 said...

如果你批評他人。你就沒有時間付出愛......................................................................

阿袁袁袁袁華 said...

你怎麼能經過一片海,而忘記它的藍?......................................................................

怡靜怡靜怡靜怡雯 said...

第一次睇你blog,鐘意!............................................................

饶湘国 said...

看著你的BLOG 好多朋友都回應 真厲害..................................................

Karan1337 said...

Turbo C is fading away, yet is used in some colleges. Good example btw :)