下面是代码,设了两个属性:name和phone number【这个你可以根据情况自己改一下】;关于其中的文件操作:读入文件为xt,输出文件为xt#include #include #include using namespace std;#define NUM 100int num=0;class BOOK{public: string name,phone_number; int d; BOOK(){ d=0;} void add_record(string n,string p); void delete_record(); void display_record(); void modify_record(string n,string p);}a[NUM];void BOOK::add_record(string n,string p){ name=n; phone_number=p; d=1;}void BOOK::delete_record(){ d=0;}void BOOK::display_record(){ cout<<"\t\t"<>nam; cout<<"PHONE NUMBER:\t"; cin>>pho; a[k]add_record(nam,pho); break; } num++;}void DELETE_RECORD(){ //2,删除记录 int k;string names; if(num==0){cout<<"ERROR!No Record!\n";return;} cout<<"Who's record do you want to delete?\nNAME:"; cin>>names; for (k=0;k>names; for (k=0;k>names; for (k=0;k>nname; cout<<"NEW PHONE NUMBER:\t"; cin>>nphn; a[k]dify_record(nname,nphn); t=1; break; } } if(t==0)cout<<"\t\tNO FIND!\n"; }void ADD_FROM_FILE(){ //6,从文本文件中添加 int k=0; string str1,str2; ifstream fin("xt"); while(!f()){ if(a[k]d==0){ fin>>str1>>str2; a[k]add_record(str1,str2); } k++; } if(num>c; switch(c){ case 1: ADD_RECORD(); break; case 2: DELETE_RECORD(); break; case 3: DISPLAY_ALL(); break; case 4: QUERY(); break; case 5: MODIFY_RECORD(); break; case 6: ADD_FROM_FILE(); break; case 7: WRITE_TO_FILE(); break; default: quit=0; break; } }}