This graphics program reminds you of peoples’ birthdays.
[code language=cpp]/*******************************************************
* MYCPLUS Sample Code – http://www.mycplus.com *
* *
* This code is made available as a service to our *
* visitors and is provided strictly for the *
* purpose of illustration. *
* *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/

//Birthday Reminder Program by
//Manoj M
//manoj.exotic@gmail.com

#include
#include
#include
#include
#include
#include
#include #include
#include
#include “final\head.cpp”

fstream bdfile;
int button, x, y;

struct CURSOR
{
int x1;
int x2;
int y;
};

struct node
{
char ch;
node *next;
}*first = NULL, *temp;

void refreshbox()
{
hidemouseptr();
setfillstyle(1, 15);
bar(10, 25, getmaxx(), 459);
showmouseptr();
}

class menubutton
{
int x1, y1, x2, y2;
char caption[25];

public:
int flag;

menubutton(int a1, int b1, int a2, int b2, char cap[25])
{
x1 = a1; x2 = a2;
y1 = b1; y2 = b2;
strcpy(caption, cap);
flag=0;
}

void draw()
{
hidemouseptr();
setfillstyle(1, 15);
bar(x1, y1, x2, y2);
setcolor(0);
rectangle(x1, y1, x2, y2);
setcolor(1);
outtextxy(x1+10, y1+8, caption);
showmouseptr();
}

void onover()
{
hidemouseptr();
setfillstyle(1, 1);
bar(x1+2, y1+2, x2-2, y2-2);
setcolor(14);
outtextxy(x1+10, y1+8, caption);
showmouseptr();
}

int check()
{
getmousepos(&button, &x, &y);
int val;
val = x>x1 && xy1 && y=33 && ch<=126 && !(ty>=y2-10))
{
if ( !(ty>=y2-20 && tx>=x2-25) )
{
node *newlink = new node;
newlink = NULL;
newlink->ch = ch;
newlink->next=NULL;
if (first==NULL)
{
first=newlink;
}
else
{
temp = first;
while (temp->next!=NULL)
temp=temp->next;
temp->next=newlink;
}
setcolor(15);
line(cursor.x1, cursor.y, cursor.x2, cursor.y);
setcolor(0);
displaychar(tx, ty, ch);
tx+=8;
tm = tx;
cursor.x1+=8;
cursor.x2+=8;
cm = cursor.x1;
if (tx>=x2-15)
{
tm=tx;
tx=x1+5;
ty+=8;
cm = cursor.x1;
cursor.x1 = x1+5;
cursor.x2 = x1+10;
cursor.y += 8 ;
}
line(cursor.x1, cursor.y, cursor.x2, cursor.y);
}
}
//***************************************************************************

if (ch==8)
{
node *temp = first;
node *ptr = temp;
while (temp->next!=NULL)
{
ptr=temp;
temp=temp->next;
ch = temp->ch;
}
if (ptr==temp)
first=NULL;
setcolor(15);
line(cursor.x1, cursor.y, cursor.x2, cursor.y);
ptr->next=NULL;
displaychar(tx, ty, temp->ch);
tx-=8;
cursor.x1-=8;
cursor.x2-=8;
displaychar(tx, ty, temp->ch);
if (txch);
setcolor(0);
line(cursor.x1, cursor.y, cursor.x2, cursor.y);
}
//***************************************************************************

if (ch==13)
{
setcolor(15);
line(cursor.x1, cursor.y, cursor.x2, cursor.y);
tx = x1+5;
ty+=8;
cursor.x1 = x1+5;
cursor.x2 = x1+10;
cursor.y += 8;
setcolor(0);
line(cursor.x1, cursor.y, cursor.x2, cursor.y);
node *newlink = new node;
newlink = NULL;
newlink->ch = 32;
newlink->next=NULL;
if (first==NULL)
{
first=newlink;
}
else
{
temp = first;
while (temp->next!=NULL)
temp=temp->next;
temp->next=newlink;
}
}

}while (ch!=27);

string=first;
first = string;
/*setcolor(0);
tx=100;
node *temp = first;
while (temp!=NULL)
{
displaychar(tx, 400, temp->ch);
temp=temp->next;
tx+=8;
} */
}

void enterlinetext(int x1, int y1, int x2, char *string, int opt=0)
{
/*
OPTION USE
0 Files
1 Name
2 Numbers
3 Email
4 Address
*/
char *perm = NULL;
char ch, sub[2];
int y2 = y1+25;
int tx, ty;
tx = x1+5;
ty = y1+8;
perm = string;
sub[1] = 0;
CURSOR cursor;
cursor.x1 = x1+5;
cursor.x2 = x1+10;
cursor.y = y2-8;
setcolor(0);
rectangle( x1, y1, x2, y2);
line( cursor.x1, cursor.y, cursor.x2, cursor.y);
*string =0;
do
{
ch = getch();
sub[0] = ch;
if ( ( isalpha(ch) || isdigit(ch) || ch ==’.’ || ch ==’_’ || ch ==’\\’
|| ch ==’:’ ) && cursor.x2=’0′ && ch<='9' && i<2) { str[i] = ch; str[i+1] = 0; i++; setcolor(0); outtextxy(x+10, y+8, str); } else if (ch==8 && i>0)
{
setcolor(15);
outtextxy(x+10, y+8, str);
i–;
str[i]=0;
setcolor(0);
outtextxy(x+10, y+8, str);
}
}while ( (ch!=27 && ch!=13) || i==0 );
strcpy(d.dd, str);

i=0;
str[i]=0;
rectangle(x+38, y+5, x+60, y+25);
do
{
ch=getch();
if (ch>=’0′ && ch<='9' && i<2) { str[i] = ch; str[i+1] = 0; i++; setcolor(0); outtextxy(x+40, y+8, str); } else if (ch==8 && i>0)
{
setcolor(15);
outtextxy(x+40, y+8, str);
i–;
str[i]=0;
setcolor(0);
outtextxy(x+40, y+8, str);
}
}while ( (ch!=27 && ch!=13) || i==0 );
strcpy(d.mm, str);

i=0;
str[i]=0;
rectangle(x+68, y+5, x+150, y+25);
do
{
ch=getch();
if (ch>=’0′ && ch<='9' && i<4) { str[i] = ch; str[i+1] = 0; i++; setcolor(0); outtextxy(x+70, y+8, str); } else if (ch==8 && i>0)
{
setcolor(15);
outtextxy(x+70, y+8, str);
i–;
str[i]=0;
setcolor(0);
outtextxy(x+70, y+8, str);
}
}while ( (ch!=27 && ch!=13) || i==0 );
strcpy(d.yy, str);
}

void addremmenu()
{
refreshbox();
hidemouseptr();
setcolor(0);
outtextxy(100, 110, “Enter Name: “);
outtextxy(60, 150, “Enter Birth Date: “);
outtextxy(45, 190, “Enter Relationship: “);
setcolor(0);
rectangle(200, 100, 400, 125);
rectangle(200, 140, 360, 170);
rectangle(200, 180, 400, 205);
enterlinetext(200, 100, 400, rem.name, 1);
enterdate(200, 140, rem.datebd);
enterlinetext(200, 180, 400, rem.rel, 1);
bdfile.open(“Birthday.dat”, ios::app);
bdfile.write((char*)&rem, sizeof(rem));
bdfile.close();
setfillstyle(1, 4);
bar(5, 440, getmaxx()-5, 455);
setcolor(14);
outtextxy(20, 445, “Reminder successfully Added !”);
getch();
showmouseptr();
}

void delremmenu()
{
char *name=NULL;
int flag=0;
refreshbox();
hidemouseptr();
setcolor(0);
outtextxy(100, 110, “Enter Name: “);
enterlinetext(200, 100, 400, name, 1);
fstream temp_file;
bdfile.open(“Birthday.dat”, ios::in);
temp_file.open(“Temp.dat”, ios::out);
bdfile.read((char*)&rem, sizeof(rem));
while(!bdfile.eof())
{
if (strcmpi(name, rem.name)!=0)
temp_file.write((char*)&rem, sizeof(rem));
else
flag=1;
bdfile.read((char*)&rem, sizeof(rem));
}
if (strcmpi(name, rem.name)!=0 && flag==0)
temp_file.write((char*)&rem, sizeof(rem));
else
flag=1;
temp_file.close();
bdfile.close();
if (flag==1)
{
setfillstyle(1, 4);
bar(5, 440, getmaxx()-5, 455);
setcolor(14);
outtextxy(20, 445, “Reminder successfully Deleted !”);
getch();
}
else if (flag==0)
{
setfillstyle(1, 4);
bar(5, 440, getmaxx()-5, 455);
setcolor(14);
outtextxy(20, 445, “Reminder Not Found !”);
getch();
}
remove(“Birthday.dat”);
rename(“Temp.dat”, “Birthday.dat”);
showmouseptr();
}

void viewremmenu()
{
char *name=NULL;
char *str=NULL;
int flag=0;
strcpy(str, “Name: “);
refreshbox();
hidemouseptr();
setcolor(0);
outtextxy(100, 110, “Enter Name: “);
enterlinetext(200, 100, 400, name, 1);
bdfile.open(“Birthday.dat”, ios::in);
bdfile.read((char*)&rem, sizeof(rem));
while(!bdfile.eof())
{
if (strcmpi(name, rem.name)==0)
{
strcat(str, rem.name);
outtextxy(200, 150, str);
*str=0;
strcpy(str, “Birth Date: “);
strcat(str, rem.datebd.dd);
strcat(str, “/”);
strcat(str, rem.datebd.mm);
strcat(str, “/”);
strcat(str, rem.datebd.yy);
outtextxy(200, 175, str);
*str=0;
strcpy(str, “Relationship: “);
strcat(str, rem.rel);
outtextxy(200, 200, str);
flag=1;
}
bdfile.read((char*)&rem, sizeof(rem));
}
if (strcmpi(name, rem.name)==0)
{
*str=0;
strcpy(str, “Name: “);
strcat(str, rem.name);
outtextxy(200, 150, str);
strcpy(str, “Birth Date: “);
strcat(str, rem.datebd.dd);
strcat(str, “/”);
strcat(str, rem.datebd.mm);
strcat(str, “/”);
strcat(str, rem.datebd.yy);
outtextxy(200, 175, str);
strcpy(str, “Relationship: “);
strcat(str, rem.rel);
outtextxy(200, 200, str);
flag=1;
}
bdfile.close();
if (flag==1)
{
setfillstyle(1, 4);
bar(5, 440, getmaxx()-5, 455);
setcolor(14);
outtextxy(20, 445, “Hit any key to continue…”);
}
else if (flag==0)
{
setfillstyle(1, 4);
bar(5, 440, getmaxx()-5, 455);
setcolor(14);
outtextxy(20, 445, “Reminder not found !”);
}
getch();
showmouseptr();
}

void main()
{
initialize();
drawinterface();
showmouseptr();
menubutton addrem(200, 150, 370, 180, “Add Reminder”);
menubutton delrem(200, 200, 370, 230, “Delete Reminder”);
menubutton viewrem(200, 250, 370, 280, “View Reminders”);
menubutton bdayqt(200, 300, 370, 330, “Back”);
hidemouseptr();
restrictmouseptr(0, 0, getmaxx(), 459);
setfillstyle(1, 1);
bar(4, 4, getmaxx()-4, 24);
setcolor(15);
outtextxy(240, 10, “BIRTHDAY REMINDER”);
addrem.draw();
delrem.draw();
viewrem.draw();
bdayqt.draw();
draw3dbox(2, 2, getmaxx()-2, 457);
showmouseptr();
do
{
getmousepos(&button, &x, &y);
if (addrem.check() && addrem.flag==0)
{
addrem.onover();
addrem.flag=1;
}
if (!addrem.check() && addrem.flag==1)
{
addrem.draw();
addrem.flag=0;
}
if ((button&1)==1 && addrem.check())
{
addrem.flag=2;
delrem.flag=2;
viewrem.flag=2;
bdayqt.flag=2;
addremmenu();
refreshbox();
addrem.draw();
delrem.draw();
viewrem.draw();
bdayqt.draw();
addrem.flag=0;
delrem.flag=0;
viewrem.flag=0;
bdayqt.flag=0;
}

if (delrem.check() && delrem.flag==0)
{
delrem.onover();
delrem.flag=1;
}
if (!delrem.check() && delrem.flag==1)
{
delrem.draw();
delrem.flag=0;
}
if ( (button & 1)==1 && delrem.check() )
{
addrem.flag=2;
delrem.flag=2;
viewrem.flag=2;
bdayqt.flag=2;
delremmenu();
refreshbox();
addrem.draw();
delrem.draw();
viewrem.draw();
bdayqt.draw();
addrem.flag=0;
delrem.flag=0;
viewrem.flag=0;
bdayqt.flag=0;
}

if (viewrem.check() && viewrem.flag==0)
{
viewrem.onover();
viewrem.flag=1;
}
if (!viewrem.check() && viewrem.flag==1)
{
viewrem.draw();
viewrem.flag=0;
}
if ( (button & 1)==1 && viewrem.check() )
{
addrem.flag=2;
delrem.flag=2;
viewrem.flag=2;
bdayqt.flag=2;
viewremmenu();
refreshbox();
addrem.draw();
delrem.draw();
viewrem.draw();
bdayqt.draw();
addrem.flag=0;
delrem.flag=0;
viewrem.flag=0;
bdayqt.flag=0;
}

if (bdayqt.check() && bdayqt.flag==0)
{
bdayqt.onover();
bdayqt.flag=1;
}
if (!bdayqt.check() && bdayqt.flag==1)
{
bdayqt.draw();
bdayqt.flag=0;
}
if ((button&1)==1 && bdayqt.check())
break;
}while (1);
}[/code]

0 Shares
Share
+1
Tweet
Share
Stumble