/* Title Telephone Directory Author Vishal B. Author Email vishalbnair_85 [at] yahoo.co.in Description Telephone directory which can be used to store, edit,search data Category C++ » Computer Graphics Hits 1458 */ #include #include #include #include #include #include #include #include #include class telephone { char name[25]; char address[40]; char phoneno[15]; public: telephone(){ } telephone(char nam[25], char add[40], char phone[15]) { strcpy(name,nam); strcpy(address,add); strcpy(phoneno,phone); } void init(); void button(int x1,int y1,int x2,int y2,char str[]); int press(int,int,int,int); int unpress(int,int,int,int); int mouseini(); int showmp(); int hidemp(); int getmp(int *button,int *x,int *y); int setmp(); int click(int x1,int y1,int x2,int y2,char str[]); int screen(); void login(); void search(); void delete1(); void insert(); void update(); void display() { cout<<" Name : "<270) s=45; if (x2>370) s=10; if (x2==320) delay(999); else delay(s); } delay(800); for (int i=27; i<=78; i++) { gotoxy(i,23) ; cout <<" " ; } } void telephone::insert() { telephone tel1; fstream file; file.open("Phone.txt",ios::app); tel1.init(); file.write((char *) &tel1, sizeof(tel1)); setcolor(7); outtextxy(250,250,"Inserting Record....."); file.close(); delay(3000); } void telephone::init() { cout<<" Enter Name : "; cin.getline(name,25); cout<<" Enter Address : "; cin.getline(address,40); cout<<" Enter Phone Number: "; cin.getline(phoneno,15); } void telephone::delete1() { telephone tel1; fstream file ; char nam[25],nam1[25]; strcpy(nam1,""); cout<<"Enter the Name to be deleted: "; cin>>nam; file.open("Phone.txt", ios::in) ; fstream temp ; temp.open("temp.txt", ios::out) ; file.seekg(0,ios::beg) ; while (file.read((char *) &tel1, sizeof(telephone))) { if(!tel1.compare(nam)) temp.write((char *) &tel1, sizeof(telephone)) ; else strcpy(nam1,nam); } file.close() ; temp.close() ; setcolor(7); if(strlen(nam1)!=0) { file.open("Phone.txt", ios::out) ; temp.open("temp.txt", ios::in) ; temp.seekg(0,ios::beg) ; while (temp.read((char *) &tel1, sizeof(telephone))) { file.write((char *) &tel1, sizeof(telephone)) ; } file.close() ; temp.close() ; outtextxy(250,250,"Deleting Record....."); } else outtextxy(250,250,"Record not found"); delay(3000); } void telephone::update() { telephone tel1; fstream file ; char nam[25],nam1[25]; strcpy(nam1,""); cout<<"Enter the Name to be updated: "; cin>>nam; file.open("Phone.txt", ios::in) ; fstream temp ; temp.open("temp.txt", ios::out) ; file.seekg(0,ios::beg) ; while (file.read((char *) &tel1, sizeof(telephone))) { if(!tel1.compare(nam)) temp.write((char *) &tel1, sizeof(telephone)) ; else strcpy(nam1,nam); } file.close() ; temp.close() ; setcolor(7); if(strlen(nam1)!=0) { file.open("Phone.txt", ios::out) ; temp.open("temp.txt", ios::in) ; temp.seekg(0,ios::beg) ; while (temp.read((char *) &tel1, sizeof(telephone))) { file.write((char *) &tel1, sizeof(telephone)) ; } file.close() ; temp.close() ; char nam[25],add[40],ph[15]; file.open("Phone.txt",ios::app); cout<<" Enter Name : "; cin.getline(nam,25);cin.getline(nam,25); cout<<" Enter Address : "; cin.getline(add,40); cout<<" Enter Phone Number: "; cin.getline(ph,15); tel1=telephone(nam,add,ph); file.write((char *) &tel1, sizeof(tel1)); file.close(); outtextxy(250,250,"Updating Record....."); } else outtextxy(250,250,"Record not found"); delay(3000); } void telephone::search() { fstream file; telephone tel1; int i=1; char nam[25]; file.open("Phone.txt",ios::in); cout<<"Enter name to be Searched: "; cin>>nam; file.seekg(0,ios::beg); while(file.read((char *) &tel1, sizeof(telephone))) { if(tel1.compare(nam)) { tel1.display(); i=0; break ; } } file.close() ; if(i) { setcolor(7); outtextxy(250,250,"Record not found"); } getch(); } void telephone:: button(int x1,int y1,int x2,int y2,char str[]) { int xc,yc,i=0,l=0; while(ix1 && xy1 && y