您的当前位置:首页正文

通讯簿管理系统程序

2024-10-18 来源:威能网
#include #include #include #include #include #include #include using namespace std; struct personinfo {

string name; string tel;

string addr; personinfo *link;

};

class UserList {

public: UserList()

{

first=new personinfo;

first->link=NULL; }

personinfo * Searchperson(string name1) {

personinfo *current=first->link ; while(current!=NULL)

if(current->name==name1) break; else current=current->link; return current;

}

bool UpdatepersonInfo(string name)

{ personinfo *current= Searchperson(name);

if(current!=NULL) { cout<<\"请输入你要更新个人信息:\"<cout<<\"请输入姓名: \"<>current->name;

cout<<\"电话号码: \"<>current->tel;

cout<<\"家庭住址: \"<>current->addr; return true;

}

else return false; }

bool Deleteperson(string name) {

personinfo * current,*pre; pre=first;

current=first->link; while(current!=NULL) { }

if(current->name==name) { pre->link=current->link; delete current; return true; break; }

else { pre=current;

current=current->link;}

if(current==NULL) return false;

}

bool Add() {

personinfo *current=first; while(current->link!=NULL) current=current->link;

personinfo *x=new personinfo;

cout<<\"请输入你要录入学生信息:\"<>x->name;

cout<<\"电话号码: \"<cin>>x->tel;

cout<<\"家庭住址: \"<cin>>x->addr; current->link=x;

x->link=NULL; return true;

}

void display(personinfo *x) {

cout<<\"__________________________________________\"<name<tel<addr<}

void baocun() { }

void init() { ifstream fin(\"123.txt\"); if(!fin.eof())

{

string s;

personinfo *current=first; while(!fin.eof()) { }

current->link=NULL; fin.clear(); fin.close();

personinfo *x=new personinfo; fin>>s; x->name=s; fin>>s; if(s==\"\")break; x->tel=s; fin>>s; x->addr=s;

current->link=x; current=x;

ofstream myfile(\"123.txt\"); personinfo *current=first->link; while(current!=NULL) {

myfile<name<tel<addr; cout<<\"__________________________________________\"<current=current->link; }

myfile.close();

}

}

void AllDisp() { }

personinfo *current=first->link; while(current!=NULL) { display(current); current=current->link; }

private: personinfo *first; };

void main( ) {

int m; bool b; string name;

UserList user_list; user_list.init(); personinfo* a; while(1)

{

m=0;

system(\"cls\");//清屏

printf(\"\\n**********通讯簿管理系统**********\\n\"); printf(\"* 1 输出 *\\n\"); printf(\"* 2 录入 *\\n\"); printf(\"* 3 查询 *\\n\"); printf(\"* 4 修改 *\\n\"); printf(\"* 5 删除 *\\n\"); printf(\"* 6 退出 *\\n\"); printf(\"************************************\\n\"); printf(\"\\n请选择(1~6):\"); scanf(\"%d\getchar(); if(m==6) break; switch(m)

{

case 1:user_list.AllDisp();break; case 2:

}

}

user_list.Add();

cout<<\"增加同学成功!\\n\"; break;

break; case 3: cout<<\"请输入您需查询的同学名称:\";

cin>>name;

if(a=user_list.Searchperson(name)) user_list.display(a); else cout<<\"不存在该同学!\\n\";

break; case 4: cout<<\"请输入您需更新同学姓名:\"; cin>>name;

b=user_list.UpdatepersonInfo(name);

if(b==true) cout<<\"信息更新成功!\"<case 5: cout<<\"请输入您需删除同学名称:\";

cin>>name;

if(user_list.Deleteperson(name)) cout<<\"删除成功!\\n\";

else cout<<\"删除失败!\\n\"; default:printf(\"\\n选择错误!\");break; }

user_list.baocun(); char ch; if(m>=1&&m<=5) { }

do{ printf(\"是否继续操作,是-y/否-n \\n\");

scanf(\"%s\getchar();

}while(ch!='n'&&ch!='y'); if(ch=='n'||ch=='N') break;

因篇幅问题不能全部显示,请点此查看更多更全内容