#include #include #include #include #include #include #include #include int count; class person { public: char name[20],address[40]; char rph[15],oph[15]; }p1; class shape { public: void write_blink(char *); void box(int,int,int,int,int); void box_border(int,int,int,int,int); }sh; class dairy { public: void clear(); void main_menu(); }da; void shape::write_blink(char *buffer) { textcolor(BROWN+BLINK); cprintf(buffer); textcolor(WHITE);
} void shape::box(int x1,int y1,int x2,int y2,int color) { textbackground(color); for(int i=x1;i<=x2;i++) { for(int j=y1;j<=y2;j++) { gotoxy(i,j); cprintf(" "); } } } void shape::box_border(int x1,int y1,int x2,int y2,int color) { char l1=186,l2=201,l3=200,l4=187,l5=188,l6=205; textcolor(color); textcolor(color); gotoxy(x1,y1);cprintf("%c",l2); gotoxy(x1,y2);cprintf("%c",l3); gotoxy(x2,y1);cprintf("%c",l4); gotoxy(x2,y2);cprintf("%c",l5); int i; for(i=y1+1;i { gotoxy(x1,i);cprintf("%c",l1); gotoxy(x2,i);cprintf("%c",l1); } for(i=x1+1;i { gotoxy(i,y1);cprintf("%c",l6); gotoxy(i,y2);cprintf("%c",l6); } closegraph(); } class function { public: void ph_add(); void search(); void erase(); void display(); void add_app(); void erase_app();
}; void function::ph_add() { clrscr(); fstream fiout; char wish; fiout.open("phdiary.dat",ios::out|ios::app);
do { shape s1; s1.box(1,4,80,20,LIGHTGRAY); s1.box_border(1,4,80,20,WHITE); gotoxy(15,7);cout<<"Enter The Name :";gets(p1.name); gotoxy(15,9);cout<<"Enter The Address :";gets(p1.address); gotoxy(15,11);cout<<"Residance Phone Number :";gets(p1.rph); gotoxy(15,13);cout<<"Office Phone Number :";gets(p1.oph); fiout.write((char *)&p1,sizeof(person)); gotoxy(15,15);cout<<"Record Saved....\n"; gotoxy(15,17);cout<<"Do You Want To Continue....(y/n)";cin>>wish;da.clear(); }while(wish =='y'||wish=='Y'); closegraph(); } void function::search() { int found=0; char name1[20]; ifstream finout; finout.open("phdiary.dat",ios::in|ios::app); if(!finout) { textbackground(0); clrscr(); cout<<"\aError Opening Phone Data File.\n"; finout.close(); exit(0); } sh.box(5,4,75,6,BROWN); sh.box_border(5,4,75,6,WHITE); textcolor(YELLOW); gotoxy(10,5);cprintf("Enter the Name or Telephone no.to Search : "); gets(name1); while(finout.read((char *)&p1,sizeof(person))) { if((strcmp(p1.name,name1)==0)||(strcmp(p1.rph,name1)==0)||(strcmp(p1.oph,name1)==0)) { found=1; sh.box(19,9,65,16,WHITE); sh.box_border(19,9,65,16,WHITE); textcolor(YELLOW); gotoxy(21,11);cprintf("Name:%s",p1.name); gotoxy(21,12);cprintf("Resi. Ph.:%s",p1.rph); gotoxy(21,13);cprintf("Office Ph.:%s",p1.oph); gotoxy(21,14);cprintf("Address :%s",p1.address); textcolor(RED); gotoxy(15,23);cprintf("Record found"); textcolor(WHITE); }
} finout.close(); if(found==0) { gotoxy(15,23);cprintf("Record not in the telephone directory"); } getch(); da.clear(); closegraph(); } void function::erase() { int found=0; ifstream filin1; filin1.open("phdiary.dat",ios::in|ios::app); if(!filin1) { textbackground(0); clrscr(); cout<<"\aError Opening Phone Data File.\n"; filin1.close(); exit(0); } ofstream filout1; filout1.open("tempdir.dat",ios::out); if(!filout1) { textbackground(0); clrscr(); cout<<"\aError Opening Phone Data File.\n"; filout1.close(); exit(0); } char name[40]; sh.box(5,4,75,6,LIGHTGRAY); sh.box_border(5,4,75,6,WHITE); textcolor(WHITE); gotoxy(10,5);cout<<"Enter the Name to delete : "; gets(name); while(filin1.read((char*)&p1,sizeof(person))) { if(strcmp(p1.name,name)==0) found=1; if(strcmp(p1.name,name)!=0) { filout1.write((char*)&p1,sizeof(person)); if(filout1.fail()) { cout<<"\aError in Deleting Record \n"; found=2; filin1.close(); filout1.close(); } } } filin1.close(); filout1.close(); ifstream filin2; filin2.open("tempdir.dat",ios::in|ios::app); if(!filin1) { textbackground(0); clrscr(); cout<<"\aError Opening Phone Data File.\n"; filin2.close(); exit(0); } ofstream filout2; filout2.open("phdiary.dat",ios::out); if(!filout2) { textbackground(0); clrscr(); cout<<"\aError Opening Phone Data File.\n"; filout2.close(); exit(0); } while(filin2.read((char*)&p1,sizeof(person))) { filout2.write((char*)&p1,sizeof(person)); if(filout2.fail()) { cout<<"\aError in Deleting Record \n"; found=2; filin2.close(); filout2.close(); } } gotoxy(35,14);if(found==0) cout<<"Record Not Found...!"; gotoxy(35,14);if(found==1) cout<<"Record DELETED...!"; gotoxy(35,14);if(found==2) cout<<"Record cannot be deleted...!"; filin2.close(); filout2.close(); getch(); da.clear(); closegraph(); } void function::display() { int i=0; char ch; fstream list_all,list_all_tot; list_all.open("phdiary.dat",ios::in); list_all_tot.open("phdiary.dat",ios::in|ios::app); if(!list_all || !list_all_tot) { clrscr(); cout<<"\aError Opening Record Data File.\n"; list_all.close(); list_all_tot.close(); exit(0); } while(list_all_tot.read((char*)&p1,sizeof(person))) if(p1.name[0]!='¯') i++; list_all_tot.close(); clrscr(); gotoxy(22,12); cout< getch(); i=0; while(list_all.read((char*)&p1,sizeof(person))) if(p1.name[0]!='¯') { textbackground(0);clrscr(); sh.box(20,6,65,19,LIGHTGRAY); sh.box_border(20,6,65,19,WHITE); gotoxy(32,7); textcolor(YELLOW); cout<<"List of all the Records"; gotoxy(32,8); cout<<"======================="; gotoxy(26,10); cout<<"S.No. : "< gotoxy(26,12); cout<<"Name: "< gotoxy(26,16); cout<<"Resi. Phone No. : "< gotoxy(26,18); cout<<"Off. Phone No. : "< gotoxy(26,14); cout<<"Address : "< i++; gotoxy(15,21); cout<<"Press any key for next..."; ch=getch(); textbackground(0);clrscr(); if(ch=='0') break; } clrscr(); gotoxy(22,12); cout<<"Number of Records Displayed : "< getch(); list_all.close(); textcolor(WHITE); } void dairy::main_menu() { int choice; shape s1; function f1; do {clrscr(); s1.box(22,4,54,20,WHITE); s1.box_border(22,4,54,20,YELLOW); gotoxy(33,5);sh.write_blink("MAIN MENU"); gotoxy(23,6);cout<<"-------------------------------"; gotoxy(25,7);cout<<"1.ADD NEW RECORDS"; gotoxy(25,9);cout<<"2.SEARCH"; gotoxy(25,11);cout<<"3.ERASE"; gotoxy(25,13);cout<<"4.DISPLAY"; gotoxy(25,15);cout<<"5.EXIT"; gotoxy(25,17);cout<<"Enter Your Choice(1-5)..: ";cin>>choice;clear(); switch(choice) { case 1: f1.ph_add(); break; case 2: f1.search(); break; case 3: f1.erase(); break; case 4: f1.display(); break; } }while(choice !=5); closegraph(); } void dairy::clear()
{ int i,s=0,j; textbackground(BLACK); for(i=25;i>0;i--) { for(j=25;j>0;j--) { sound(s); s-=100 ; delay(3); gotoxy(j,i); clreol(); } nosound(); } closegraph(); } void main() { clrscr(); int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); setcolor(BROWN); rectangle(22, 7, 630, 450); rectangle(32, 17, 620, 440); setbkcolor(BLACK); int x = 0, h = 0, r, fla; while ((x != 143) && (!kbhit())) { int s=100;h = 0; while ((h <= 21) && (!kbhit())) { if ((h % 2) != 0) fla = 3; else fla = 15; setcolor(fla); settextstyle(1,HORIZ_DIR,8); highvideo(); outtextxy(85,30,"TELEPHONE"); outtextxy(100,150,"DIRECTORY"); outtextxy(155,270,"SYSTEM"); delay(20); sound(s) ; s += 25; delay(20); h++; setcolor(WHITE); settextstyle(1, HORIZ_DIR, 3); delay(20); x++;
setcolor(BLUE); settextstyle(4,0,3); outtextxy(345, 450, "Press any key to start.....");
}
} closegraph(); nosound(); dairy d1; d1.main_menu(); gotoxy(30,10);sh.write_blink("Thanking You...!"); gotoxy(49,17);cout<<"DEVELOPED BY:"; gotoxy(49,19);cout<<"Piyush Gaud"; gotoxy(49,20);cout<<"Nilesh Rathore"; gotoxy(49,21);cout<<"Shweta Jhanwer"; gotoxy(18,17);cout<<"GUIDED BY:"; gotoxy(18,19);cout<<" "; getch(); }
|