#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
using namespace std;
fstream phonebook;
struct phone
{
char word[50];
char fword[50];
fstream edit;
int id;
string fname;
string sname;
string lname;
int phonenumber;
int mobilenumber;
string email;
};
phone info;
char d,f,r;
string c,g;
int add()
{
phonebook.open("c:\\c\\phonebook.txt",ios::out|ios::app);
cout<<"enter the first name\n";
cin>>info.fname;
cout<<"enter the second name\n";
cin>>info.sname;
cout<<"enter the last name\n";
cin>>info.lname;
cout<<"enter the phone number\n";
cin>>info.phonenumber;
cout<<"enter the moile number\n";
cin>>info.mobilenumber;
cout<<"enter the e-mail\n";
cin>>info.email;
phonebook<<info.fname<<"\t "<<info.sname<<"\t "<<info.lname<<" \t "
<<info.phonenumber<<" \t "<<info.mobilenumber<<" \t "<<info.email<<endl;;
cout<<endl;
phonebook.close();
return 0;
}
int getdisplay()
{
cout<<"if u wanna display all contacts press 'a'\n"<<"if u wanna display contacts begining with specific letter press 'c'\n";
cin>>r;
phonebook.open("c:\\c\\phonebook.txt",ios::in);
phonebook.clear();
switch(r)
{
case 'a':
{
while(!phonebook.eof())
{
getline(phonebook,c);
cout<<c<<endl;
}
phonebook.close();
break;
}
case 'c':
{
phonebook.open("c:\\c\\phonebook.txt",ios::in);
phonebook>>c;
cout<<"enter the wanted letter";
cin>>g;
// getdisplay;
cout<<"dsucyeehr";
phonebook.close();
break;
}
}
return 0;
}
void getsearch()
{
cout << "Enter your contact:"<<endl;
cin >> info.word;
phonebook.open("c:\\c\\phonebook.txt",ios::in);
phonebook.clear();
int counter =0;
while (!phonebook.eof()){
phonebook >> info.fword;
int j=strcmp(info.fword,info.word);
if (j==0){
cout << "contact was found in the file :)"<<endl;
cout<< info.word << endl;
counter ++;
phonebook>>info.fname>>info.sname>>info.lname>>info.phonenumber>>info.mobilenumber>>info.email;
cout<<info.fword<<" "<<info.fname<<" "<<info.sname<<" "<<info.lname
<<" "<<info.phonenumber<<" "<<info.mobilenumber<<" "<<info.email;
break;
}
}
if (counter == 0)
cout << "contact was not found in the file :(" << endl;
phonebook.close();
}
int main()
{
while(1)
{
cout<<endl<<"1-Adding new contacts"<<endl
<<"2-Displaying contacts information"<<endl
<<"3-Searching for a contact"<<endl
<<"4-Deleting a contact"<<endl
<<"5-Modifying a contact information"<<endl
<<"6-Sort the contacts by name"<<endl
<<"7-exit"<<endl<<endl;
cout<<"enter your choice"<<endl;
cin>>d;
switch(d)
{
case '1':
{
add();
cout<<"if u wann add another contact press 'y' if not press 'n'";
cin>>f;
if(f=='y')
{
add();
}
break;
}
case '2':
{
getdisplay();
break;
}
case '3':
{
getsearch();
break;
}
case '4':
{
break;
}
case '5':
{
break;
}
case '6':
{
break;
}
case '7':
{
return 0;
break;
}
}
}
system ("pause");
return 0;
}