المساله :
write a simple directory program that looks up phone numbers in a file
containing a list of names and phone numbers .The user prompted to enter
a first and last name and the program outputs the corresponding number
or indicates the the name is not in directory.
After each look up,the program should ask the user whether they wantto look up
another number,and then either rpeat the process or exist th program.
the data on the file should organized so that each line contain
a first name ,last name , and phone numbers .
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string first,last;
string fname,lname;
string filename;
ifstream infile;
int phone;
infile.open("phone.txt");
if (!infile)
{
cout<<"Can't open file phone.txt"<<endl;
return 1;
}
if(infile)
cout<<"please enter your first and last name"<<endl;
cin>>first>>last;
{
infile>>fname>>lname>>phone;
cout<<endl;
if(infile)
{
fname=first;
lname=last;
cout<< phone<<endl;
}
else
cout<<"your name is not in directory"<<endl;
cout<<endl;
cout<<"please enter other name"<< endl;
cin>>first>>last;
if(infile)
{
fname=first;
lname=last;
cout<< phone<<endl;
}
}
cout<<endl;
infile.close();
return 0;
}