Simple Calendar in C/C++


Simple Calendar in C\C++ : The following is a simple calendar created using BGI graphics library of Turbo C/C++ 3.0 :

While running this program , make sure you have used correct path for BGI graphics driver . Example : if Turbo C/C++ is installed at "C:\TC" , BGI graphics path would be "C:\\TC\\BGI" :

Screenshot :





C++ Code :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<dos.h>
int gm,gd,scan,ascii;
void main()
{
initgraph(&gm,&gd,"F:\\TC\\BGI");
union REGS ii,oo;
char masum[20],*month[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
int m,y,leapyears,row,col,x,i,firstday,thisyrdays;
long int totaldays;
char str1[5],str2[3];
setcolor(3);
outtextxy(25,75,"Which month do you want to see?");
setcolor(6);
settextstyle(0,0,2);
outtextxy(210,35,"WELCOME TO...");
setcolor(10);
settextstyle(7,0,6);
outtextxy(10,195,"MY");
setcolor(12);
settextstyle(10,0,3);
outtextxy(50,245,"DISPLAY CALENDER SERVICE");
setcolor(11);
settextstyle(7,0,5);
outtextxy(420,295,"PROGRAM");
setcolor(8);
settextstyle(0,0,2);
outtextxy(10,360,"CREATED BY...");
setcolor(9);
settextstyle(0,0,4);
outtextxy(10,400,"MD. MOHIUDDIN AHMED");
setcolor(11);
settextstyle(0,0,1);
rectangle(0,0,getmaxx(),getmaxy());
rectangle(3,3,getmaxx()-3,getmaxy()-3);
line(3,getmaxy()-30,getmaxx()-3,getmaxy()-30);
line(3,getmaxy()-33,getmaxx()-3,getmaxy()-33);
setfillstyle(9,8);
bar(30,100,400,180);
bar(183,getmaxy()-6,425,getmaxy()-21);
setfillstyle(1,3);
bar(20,90,390,170);
bar(180,getmaxy()-9,420,getmaxy()-24);
setcolor(0);
outtextxy(195,getmaxy()-20,"My Display Calender Service");
MM:
setcolor(0);
outtextxy(30,100,"Enter Month(1-12):");
gotoxy(24,7);
scanf("%d",&m);
if(m<1||m>12)
{
setviewport(180,96,370,111,1);
clearviewport();
setviewport(0,0,getmaxx(),getmaxy(),1);
goto MM;
}
outtextxy(30,132,"Enter Year:");
gotoxy(18,9);
scanf("%d",&y);
setcolor(11);
while(1)
{
cleardevice();
setcolor(3);
rectangle(0,0,getmaxx(),getmaxy());
rectangle(3,3,getmaxx()-3,getmaxy()-3);
line(3,getmaxy()-30,getmaxx()-3,getmaxy()-30);
line(3,getmaxy()-33,getmaxx()-3,getmaxy()-33);
setfillstyle(9,8);
bar(183,getmaxy()-6,425,getmaxy()-21);
setfillstyle(1,3);
bar(180,getmaxy()-9,420,getmaxy()-24);
setcolor(0);
settextstyle(0,0,1);
outtextxy(195,getmaxy()-20,"My Display Calender Service");
setcolor(11);
thisyrdays=0;
leapyears=(y-1)/4-(y-1)/100+(y-1)/400;
if(y%400==0||y%100!=0&&y%4==0)
days[1]=29;
else
days[1]=28;
totaldays=leapyears+(y-1)*365L;
for(i=0;i<=m-2;i++)
thisyrdays=thisyrdays=thisyrdays+days[i];
firstday=(int)((totaldays+thisyrdays)%7);
settextstyle(10,0,4);
setcolor(12);
sprintf(masum,"%s",month[m-1]);
outtextxy(75,30,masum);
itoa(y,str1,10);
outtextxy(400,30,str1);
setcolor(9);
settextstyle(0,0,3);
outtextxy(20,113,"Mon");
outtextxy(20,143,"Tue");
outtextxy(20,173,"Wed");
outtextxy(20,203,"Thu");
outtextxy(20,233,"Fri");
outtextxy(20,263,"Sat");
outtextxy(20,293,"Sun");
setcolor(3);
settextstyle(0,0,2);
col=120+firstday*30;
row=150;
for(x=1;x<=days[m-1];x++)
{
itoa(x,str2,10);
outtextxy(row,col,str2);
col=col+30;
if(y==1752&&m==9&&x==2)
x=13;
if(col>300)
{
row=row+100;
col=120;
}
if(row>550&&col==120)
row=150;
}
settextstyle(5,0,1);
outtextxy(138,5,"Change month and year using arrow keys");
settextstyle(0,0,1);
outtextxy(3,330,"---------------------------------------------------------------------------------------------------");
settextstyle(2,0,4);
outtextxy(5,332,"---------------------------------------------------------------------------------------------------------");
setcolor(11);
settextstyle(0,0,1);
outtextxy(20,350,"Press Up arrow for the next year.");
outtextxy(20,370,"Press Dn arrow for the previous year.");
outtextxy(20,390,"Press Rt arrow for the next month.");
outtextxy(20,410,"Press Lt arrow for the previous month.");
outtextxy(20,430,"Press Esc to exit.....");
settextstyle(0,0,2);
while(!kbhit());
ii.h.ah=0;
int86(22,&ii,&oo);
scan=oo.h.ah;
ascii=oo.h.al;
switch(scan)
{
 case 77:
 if(m==12)
 {
 y=y+1;
 m=1;
 }
 else
 m=m+1;
 break;
 case 75:
 if(m==1)
 {
 y=y-1;
 m=12;
 if(y<=0)
 y=1;
 }
 else
 m=m-1;
 break;
 case 72:
 y++;
 break;
 case 80:
 y--;
 if(y<=0)
 y=1;
 break;
 case 1:
 cleardevice();
 goto MMM;

}
}
MMM:
closegraph();
restorecrtmode();
}

No comments:

Post a Comment