0% found this document useful (0 votes)
3 views

PHONEBOOK.cpp oops

Uploaded by

kritika23ojha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PHONEBOOK.cpp oops

Uploaded by

kritika23ojha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

C++ Project-PhoneBook

Application
#include<stdio.h>
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
class phonebook
{
private:
char name[50],ph[30],email[50],add[100];
public:

void get_data()
{

cout<<"\n_________PHONE BOOK APPLICATION_________\n"<<endl;


cout<<"enter name of contact:"<<endl;
gets(name);
cout<<"enter phone number of contact"<<endl;
gets(ph);
cout<<"enter email of contact:"<<endl;
gets(email);
cout<<"enter address of contact:"<<endl;
gets(add);
}
void show_data()
{
cout<<"\n_________PHONE BOOK APPLICATION_________\n"<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Phone Number:"<<ph<<endl;
cout<<"Email:"<<email<<endl;
cout<<"Address:"<<add<<endl;
}
void search_data()
{
cout<<"\n_________PHONE BOOK APPLICATION_________\n"<<endl;
char searchName[30];
cout<<"Enter name to search contact:"<<endl;
gets(searchName);
if(strcmp(searchName,name)==0)
{
cout<<"Name:"<<name<<endl;
cout<<"Phone Number:"<<ph<<endl;
cout<<"Email:"<<email<<endl;
cout<<"Address:"<<add<<endl;
}
else{
cout<<"name not found \n";
}}
void update_data()
{
cout<<"\n_________PHONE BOOK APPLICATION_________\n"<<endl;
char upName[30];
char d;
cout<<"enter the contact name to be updated:"<<endl;
gets(upName);
if(strcmp(upName,name)==0)
{
cout<<"press a to change name\n";
cout<<"press b to change phone number\n";
cout<<"press c to change email\n";
cout<<"press d to change address\n";
cout<<"press any key to exit\n";
cin>>d;
switch(d)
{
case'a':cout<<"enter new name:"<<endl;
cin>>name;
break;
case'b':cout<<"enter new phone number:"<<endl;
cin>>ph;
break;
case'c':cout<<"enter new email:"<<endl;
cin>>email;
break;
case'd':cout<<"enter new address:"<<endl;
cin>>add;
break;
default:exit(0);
}}
else
{
cout<<"contact not found!!"<<endl;
}
}
void delete_data()
{
cout<<"\n_________PHONE BOOK APPLICATION_________\n"<<endl;
char delName[50];
cout<<"enter record name you want to delete:"<<endl;
gets(delName);
if(strcmp(delName,name)==0)
{
name[50]='\0';
ph[30]='\0';
email[50]='\0';
add[100]='\0';
}
cout<<"contact is deleted!"<<endl;
}
};
int main(){
clrscr();
phonebook obj[2];
fstream f;
f.open("myfile.txt",ios::in|ios::out|ios::app);
char ch='y';
int d;
while(ch=='y'||ch=='Y')
{
cout<<"\n_________PHONE BOOK APPLICATION_________\n"<<endl;
cout<<"\nOperations\n";
cout<<"press 1 to enter data\n";
cout<<"press 2 to show data\n";
cout<<"press 3 to search data\n";
cout<<"press 4 to update data\n";
cout<<"press 5 to delete data\n";
cout<<"press 6 to exit\n";
cin>>d;
switch(d)
{
case 1:for(int i=0;i<2;i++)
{
obj[i].get_data();
f.write((char*)&obj[i],sizeof(obj[i]));
}
break;
case 2:f.seekg(0);
for(i=0;i<2;i++)
{
f.read((char*)&obj[i],sizeof(obj[i]));
obj[i].show_data();
}
break;
case 3:f.seekg(0);
for(i=0;i<2;i++)
{
f.read((char*)&obj[i],sizeof(obj[i]));
obj[i].search_data();
}
break;
case 4:f.seekg(0);
for(i=0;i<2;i++)
{
obj[i].update_data();
f.write((char*)&obj[i],sizeof(obj[i]));
}
break;
case 5:f.seekg(0);
for(i=0;i<2;i++)
{
obj[i].delete_data();
f.write((char*)&obj[i],sizeof(obj[i]));
}
break;
case 6:exit(0);
break;
default:cout<<"invalid input!!";
}
cout<<"press y or Y to continue";
flushall();
cin>>ch;
}
f.close();
getch();
return 0;
}

You might also like