// a telephone directory , deloped by mr. saleem ullah mcs 15 iiui.
#include<conio.h>
#include<ctype.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<graphicse.h>
#include<fstream.h>
void W_C_File(); //**** Functions Read & Write Master File
void R_C_File();
//**********************Global Variables
int Cur_Win=0; //Which Window is Open
int Button,M_X_Pos,M_Y_Pos; //Current Mouse Position
union REGS i,o; //For Mouse Initialization,Show....
int input=0,pos=0; //Required Variables for Input
char temp[35]={'\0'};
int ch; //Press Charecter Store
int Search_Cri=0; //Search By Phone #
char Search_Val[35]; //Search Input
char Cur_File[40]; //Which is Master File
//********************** Mouse Class
class mouse
{
public:
initmouse();
showmouse();
getposition(int *button,int *x,int *y);
hidemouse();
};
mouse::initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
o.x.cx=1;
o.x.dx=1;
return(o.x.ax);
}
mouse::showmouse()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
mouse::hidemouse()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
mouse::getposition(int*but,int*x,int*y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*but=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
//************************ Main Window Class
class main_win
{
public:
void screen();
void button(int,int,int,int,int,int,char*);
void textbox(int,int,int,int,char*);
void clr_scr_b(int,int,int,int);
void clr_scr(int,int,int,int);
};
void main_win::screen()
{
setcolor(15);
bar3d(70,70,550,72,3,1);
setcolor(8);
bar3d(550,70,550,430,3,1);
setcolor(8);
bar3d(70,430,550,430,3,0);
setcolor(15);
bar3d(70,70,70,430,3,0);
setfillstyle(2,3);
int c=4;
for(int i=75;i<=548;i+=3)
for(int j=75;j<=428;j+=3)
{putpixel(i,j,c++);
if(c==7)c=4;}
setcolor(12);
settextstyle(10,0,4);
outtextxy(120,80,"Phone Directory");
setcolor(2);
settextstyle(10,0,4);
outtextxy(122,82,"Phone Directory");
setcolor(15);
line(120,150,495,150);
setcolor(8);
line(120,152,495,152);
}
void main_win::button(int Lef,int Top,int Rig,int Bot,int Txt_X,int Txt_Y,char* text)
{
setcolor(15);
line(Lef,Top,Rig,Top);
setcolor(15);
line(Lef,Top,Lef,Bot);
setcolor(8);
line(Lef,Bot,Rig,Bot);
setcolor(8);
line(Rig,Bot,Rig,Top);
int c=3;
for(int i=Lef+1;i<Rig;i+=2)
for(int j=Top+1;j<=Bot-1;j+=2)
{
putpixel(i,j,8);
if(c==9)c=3;
}
setcolor(12);
settextstyle(7,0,3);
outtextxy(Txt_X,Txt_Y,text);
setcolor(2);
settextstyle(7,0,3);
outtextxy(Txt_X+1,Txt_Y+1,text);
}
void main_win::textbox(int Lef,int Top,int Rig,int Bot,char *text)
{
setcolor(15);
line(Lef,Top,Rig,Bot);
line(Lef,Top,Lef,Top+25);
setcolor(8);
line(Lef,Top+25,Rig,Top+25);
line(Rig,Top,Rig,Top+25);
setcolor(8);
line(Lef+1,Top+26,Rig+1,Top+26);
line(Rig+1,Top+1,Rig+1,Top+26);
setcolor(12);
settextstyle(7,0,3);
outtextxy(Lef-200,Top-10,text);
setcolor(2);
settextstyle(7,0,3);
outtextxy(Lef-200+1,Top-10+1,text);
for(int i=Lef+1;i<Rig;i++)
for(int j=Top+1;j<Top+25;j++)
putpixel(i,j,0);
}
void main_win::clr_scr_b(int x1,int x2,int y1,int y2)
{
for(int i=x1;i<=x2;i+=1)
for(int j=y1;j<=y2;j+=1)
putpixel(i,j,0);
}
void main_win::clr_scr(int x1,int x2,int y1,int y2)
{
int c=4;
for(int i=x1;i<=x2;i+=3)
for(int j=y1;j<=y2;j+=3)
{
putpixel(i,j,c++);
if(c==7)c=4;
}
}
//**********************Main Screen Buttons
void screen_but()
{
main_win W1;
W1.button(340,190,495,220,375,190,"Search");
W1.button(120,190,275,220,155,190,"Insert");
W1.button(120,270,275,300,155,270,"Update");
W1.button(340,270,495,300,375,270,"Delete");
W1.button(230,350,385,380,280,350,"Exit");
}
//***************************** Diretory Class
class Directory
{
private:
char phone[20],name[25],address[35],city[15];
public:
void getdata();
void Submit();
void search();
void Sea_by_Ph();
void Sea_Update();
void Update();
void Sea_Delete();
void Delete();
void Display();
};
//***************** Get Data
void Directory::getdata()
{
if(kbhit())
{
ch=getch();
if(input==0)
{
switch(ch)
{
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
temp[pos++]=ch;
temp[pos]='\0';
gotoxy(42,13);
cout<<temp<<"_";
if(pos>13) //If Phone # Is >13
{
ch=13;
strcpy(phone,temp);
temp[0]='\0';
cout<<"\b ";
input++;
gotoxy(42,16);
cout<<"_";
pos=0;
}
break;
case 8:
if(pos>0)
{
pos--;
cout<<"\b\b \b\b_";
}
break;
case 13:
if(strlen(temp)>6)
{
strcpy(phone,temp);
temp[0]='\0';
cout<<"\b ";
input++;
gotoxy(42,16);
cout<<"_";
pos=0;
break;
}
}
}
//******************** Name
if(input==1)
{
switch(ch)
{
case 0:
ch=getch();
switch(ch)
{
default:
break;
}
case 8:
if(pos>0)
{
pos--;
cout<<"\b\b \b\b_";
}
break;
case 13:
if(strlen(temp)>2)
{
strcpy(name,temp);
cout<<"\b ";
temp[0]='\0';
gotoxy(42,19);
cout<<"_";
input++;
pos=0;
}
break;
default:
temp[pos++]=ch;
temp[pos]='\0';
gotoxy(42,16);
cout<<temp<<"_";
if(pos>18) //If Name # Is >18
{
ch=13;
strcpy(name,temp);
temp[0]='\0';
cout<<"\b ";
input++;
gotoxy(42,19);
cout<<"_";
pos=0;
}
break;
}
}
//********************** Address
if(input==2)
{
switch(ch)
{
case 0:
ch=getch();
switch(ch)
{
default:
break;
}
break;
case 8:
if(pos>0)
{
pos--;
cout<<"\b\b \b\b_";
}
break;
case 13:
if(strlen(temp)>5)
{
strcpy(address,temp);
cout<<"\b ";
temp[0]='\0';
gotoxy(42,22);
cout<<"_";
input++;
pos=0;
}
break;
default:
temp[pos++]=ch;
temp[pos]='\0';
gotoxy(42,19);
cout<<temp<<"_";
if(pos>18) //If Address # Is >13
{
ch=13;
strcpy(address,temp);
temp[0]='\0';
cout<<"\b ";
input++;
gotoxy(42,22);
cout<<"_";
pos=0;
}
break;
}
}
//*************************** City
if(input==3)
{
switch(ch)
{
case 0:
ch=getch();
switch(ch)
{
default:
break;
}
break;
case 8:
if(pos>0)
{
pos--;
cout<<"\b\b \b\b_";
}
break;
case 13:
if(strlen(temp)>3)
{
strcpy(city,temp);
cout<<"\b ";
temp[0]='\0';
input=10;
pos=0;
}
break;
default:
temp[pos++]=ch;
temp[pos]='\0';
gotoxy(42,22);
cout<<temp<<"_";
if(pos>12) //If City Is >12
{
strcpy(city,temp);
temp[0]='\0';
cout<<"\b ";
input=10;
pos=0;
}
break;
}
}
}
}
//********************** Submit Record
void Directory::Submit()
{
for(int i=0;i<strlen(name);i++)
name[i]=toupper(name[i]);
for(i=0;i<strlen(address);i++)
address[i]=toupper(address[i]);
for(i=0;i<strlen(city);i++)
city[i]=toupper(city[i]);
ofstream W_Obj;
W_Obj.open(Cur_File,ios::app|ios::binary);
W_Obj.write((char*)*&this,sizeof(*this));
W_Obj.close();
}
//************************ Search By Phone
void Directory::Sea_by_Ph()
{
int f=0;
ifstream R_Obj;
R_Obj.open(Cur_File,ios::in|ios::binary);
while(R_Obj)
{
R_Obj.read((char*)*&this,sizeof(*this));
if(strcmp(Search_Val,phone)==0)
{
f=1;
break;
}
}
if (f==1)
phone-DIR.zip_names
版权申诉
165 浏览量
2022-09-14
22:21:22
上传
评论
收藏 4KB ZIP 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+