#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class tongxun//类名
{
public:
tongxun();
string name;//姓名
void xianyou();//现有人员函数
void searchname();//查找人员
void zengjia();//增加函数
};
tongxun m;//对象
fstream wenjian;//默认的文件
string name="zhang";
string y="18748192863";
string dizhi="shangyuan";
tongxun::tongxun()
{
}
void tongxun::searchname()//查找人员
{
wenjian.open("w_1",ios::in);
wenjian<<name;
wenjian<<y;
wenjian<<dizhi;
cout<<"请输入联系人姓名:"<<endl;
string name_1;
cin>>name_1;
if(name_1==name)
cout<<name<<endl<<y<<endl<<dizhi<<endl;
else
cout<<"nobody"<<endl;
wenjian.close();
}
void tongxun::zengjia()//增加人员
{
wenjian.open("w_1",ios::in);
cout<<"请输入姓名"<<endl;
cin>>name;
wenjian<<name;
cout<<"请输入号码"<<endl;
cin>>y;
wenjian<<y;
cout<<"请输入地址"<<endl;
cin>>dizhi;
wenjian<<dizhi;
cout<<"已存储"<<endl;
wenjian.close();
}
void tongxun::xianyou()//现有人员
{
wenjian.open("w_1",ios::out);
cout<<name<<endl<<y<<endl<<dizhi<<endl;
wenjian.close();
}
////////////////////////////////////////////////////////////
int main()//主函数
{
int n;
for(;;)
{
cout<<"输入操作序号\n"<<"1.查看联系人\n"<<"2.查找联系人\n"<<"3.增加联系人\n"<<endl;//输入判断
cin>>n;
if (n==1)
m.xianyou();
else
if
(n==2)
m.searchname();
else
if
(n==3)
m.zengjia();
else
cout<<"error"<<endl;
}
return 0;
}