Вы находитесь на странице: 1из 7

// Phone Book

//Kafil Ahmed

/*
Instruction to Use:
*
*
*
*
*
*
*

Please Wait Until the Phone Book load


Don't press any key until phone book loads
Use the arrow keys to navigate up and down{Select}.
Press 'Enter' key to proceed
To add new contact to the phone book Select "Add New"
To view all the existing contacts select "View"
To search a particular detail Select "Search" and enter a name to sear

ch
* To quit select "Exit"
* All the best!!!!!!!!!!!

*/

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<time.h>
#include<graphics.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
void add();
void view();
void search();
void print(char *str);
void welcome();
int posn=1;
int i=1;
void main()
{
welcome();
textbackground(GREEN); textbackground(GREEN);
clrscr();
textcolor(WHITE);
char ch;
go:
clrscr();
cout<<"\n\t\t\t\t\t\t Date : ";
struct date dt;
getdate(&dt);
cout<<int(dt.da_day)<<'-'
<<int(dt.da_mon)<<'-'
<<dt.da_year;
cout<<"\n\t\t\t\t\t\t ---";
cout<<"\n\t\t\t\t\t\t Time : ";
struct time t;
gettime(&t);
cout<<int(t.ti_hour)<<':'<<int(t.ti_min);
cout<<"\n\t\t\t\t\t\t ---";
cout<<"\n\n\t\t\t============\n\t\t\t PHONE BOOK\n\t\t\t============\n\n\n\n";

if(posn==1)
print(" Add Record");
else
cprintf(" Add Record");
puts("");
if(posn==2)
print(" View Record");
else
cprintf(" View Record");
puts("");
if(posn==3)
print(" Search Record");
else
printf(" Search Record");
puts("");
if(posn==4)
print(" Exit");
else
cprintf(" Exit");
puts("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
puts("\n\n\n\n\n\n\n\n Press 'Up' & 'Down' arrow keys to Navigate");
puts("\n Press Enter if 'Ok'");
do{
ch=getch();
if(ch==0)
{
ch=getch();
if(ch==72 && posn>1)
{
posn--;
goto go;
}
else if(ch==72 && posn==1)
{
posn=4;
goto go;
}
else if(ch==80 && posn<4)
{
posn++;
goto go;
}
else if(ch==80 && posn==4)
{
posn=1;
goto go;
}
}
}while(ch!=13);
switch(posn)
{
case 1:
add();
goto go;
case 2:
view();
goto go;
case 3:
search();

goto go;
case 4:
textcolor(0 +BLINK);
gotoxy(15,25);
cprintf("Do you wish to exit(Y/N)?");
ch=getch();
if(ch=='y' ||ch=='Y')
exit(0);
else
{
main();
}
default:
cout<<"\nInvalid choice\n\n";
goto go;
}
}
void add()
{
char *name,*addr,*ph,ch;
clrscr();
ofstream out("ph.dat",ios::app);
cout<<"\t\t\tPhone Book\n";
cout<<"\t\t\t==========\n\n";
cout<<"\n\n\nName\t\t:\n\n";
cout<<"PhoneNo.\t:\n\n";
cout<<"Address\t\t:\n\n";
gotoxy(20,7);
gets(name);
name=strupr(name);
gotoxy(20,9);
gets(ph);
gotoxy(20,11);
gets(addr);
addr=strupr(addr);
if(name[0]=='\0' || ph[0]=='\0' || addr[0]=='\0')
{
clrscr();
cout<<"All the fields have to be filled completely";
getch();
out.close();
return;
}
out<<'\n'<<name<<'#'<<ph<<'#'<<addr<<'#';
out.close();
cout<<"\n\n\nDo you want to continue(Y/N):";
ch=getch();
if(ch=='n' || ch=='N')
exit(0);
else
main();
}
void print(char *str)
{
textcolor(RED);
cprintf("%s",str);
textcolor(WHITE);

}
void view()
{
clrscr();
char name[30],ph[15],addr[100],ch;
FILE *fp;
int x=1,y=10;
fp=fopen("ph.dat","r");
cout<<"\n\n-----------------------------------------------------------------------------";
cout<<"\n| Name\t\t|
Phone Number\t|
Residential Address
|\n";
cout<<"-----------------------------------------------------------------------------\n\n";
for(int i=4;i<50;i++)
{
gotoxy(x,i);
printf("|");
gotoxy(x+24,i);
printf("|");
gotoxy(x+48,i);
printf("|");
gotoxy(x+77,i);
printf("|");
}
x=2,y=5;
while(1)
{
ch=fgetc(fp);
if(ch=='#')
{
if(x>2 && x<25)
x=27;
else if(x>27 && x<60)
x=51;
continue;
}
else if(x>77)
{
x=50;
y++;
}
else if(ch==EOF)
{
fclose(fp);
break;
}
else if(ch=='\n')
{
cout<<"\n-----------------------------------------------------------------------------\n";
y+=2;
x=2;
}
gotoxy(x++,y);
cout<<ch;
}
getch();
}

int p=0;
void search()
{
FILE *fp;
char ch,ch1,*s;
int i=0,l=0,f=0;
clrscr();
fp=fopen("ph.dat","r");
cout<<"\nEnter the name to search\t:";
cin>>s;
s=strupr(s);
clrscr();
cout<<"\n\n-----------------------------------------------------------------------------";
cout<<"\n| Name\t\t|
Phone Number\t|
Residential Address
|\n";
cout<<"-----------------------------------------------------------------------------\n\n";
l=strlen(s);
ch=fgetc(fp);
int x=2,y=7;
while(1)
{
for(i=0;i<l;i++)
{
ch=fgetc(fp);
if(ch==EOF)
{
fclose(fp);
cout<<"\n\nSearch completed";
getch();
main();
}
if(s[i]==ch)
continue;
else
{
while(ch!='\n')
{
ch=fgetc(fp);
if(ch==EOF)
{
fclose(fp);
textcolor(BLUE);
puts(" ");
cprintf("Search completed");
textcolor(WHITE);
if(f==0)
{
textcolor(MAGENTA +BLINK);
cout<<"\n\n\n";
cprintf("No Records found");
textcolor(WHITE);
}
getch();
return;
}
}

break;
}
}
x=2;
if(i==l)
{
f=1;
y+=2;
gotoxy(x,y);
cout<<s;
x+=l;
while(ch!='\n')
{
ch=fgetc(fp);
if(ch=='#')
{
if(x<25)
x=27;
else if(x>25 && x<49)
x=52;
continue;
}
if(ch==EOF)
{
fclose(fp);
textcolor(BLUE+BLINK);
puts(" ");
cprintf("Search completed");
textcolor(WHITE);
getch();
return;
}
gotoxy(x++,y);
if(x>72)
x=52,y=y+1;
cout<<ch;
}
}
}
}
void welcome()
{
delay(50);
window(1,1,80,80);
textbackground(WHITE);
textcolor(RED);
clrscr();
gotoxy(25,12);
cprintf(" Phone Book");
gotoxy(25,13);
cprintf(" **********");
gotoxy(40,25);
cprintf("Designed by");
gotoxy(40,26);
cprintf("-----------");
gotoxy(32,31);
textcolor(0);
cprintf("D.G.Vaishnav Evening College(B.sc(cs))");
gotoxy(38,32);

cprintf("Arumbakkam, Chennai-106");
delay(500);
gotoxy(39,28);
textcolor(GREEN + BLINK);
cprintf("Kafil Ahmed.K");
printf("\n\n\n\n\n\n\n\n\n\n\n
delay(500);
delay(700);
printf(".");
delay(500);
printf(".");
delay(500);
printf("..");
delay(750);
printf("...");
delay(750);
}

Loading Please Wait");

Вам также может понравиться