C++实现链表版本通讯录
本文实例为大家分享了C++实现链表版本通讯录的具体代码,供大家参考,具体内容如下
#include#include usingnamespacestd; classAddress; classContact{ private: stringname; stringsex; stringtel; stringQQ; stringaddress; stringaddition; Contact*next; public: Contact(); friendclassAddress; }; Contact::Contact() { next=NULL; } classAddress{ public: Address(); ~Address(); intshow(); voidinsert(); voiddelete_per(); voiddisplay(); voidsearch(); voidupdate(); private: Contact*head; }; Address::Address() { head=newContact; if(head==NULL) { cout<<"failcreate"< >choice; while(!(choice>=1&&choice<=6)) { while(getchar()!='\n'); cout<<"输入有误,请重新输入!"; cin>>choice; } returnchoice; } voidAddress::insert()//添加联系人 { Contact*p=head; charrelay=0; while(p->next!=NULL) { p=p->next; } Contact*person=newContact; cout<<"请输入姓名:"; cin>>person->name; cout<<"请输入性别:"; cin>>person->sex; cout<<"请输入电话:"; cin>>person->tel; cout<<"请输入QQ:"; cin>>person->QQ; cout<<"请输入住址:"; cin>>person->address; cout<<"请输入备注:"; cin>>person->addition; p->next=person; person->next=NULL; cout<<"\n添加成功,是否继续添加?(y/n)"; cin>>relay; while(!(relay=='y'||relay=='Y'||relay=='N'||relay=='n')) { cout<<"输入错误,请重新输入(y/n):"; cin>>relay; } if(relay=='y'||relay=='y') { system("clear"); insert(); } } voidAddress::delete_per()//删除联系人 { stringm_name; Contact*p=head; Contact*pre=head; intflag=0; cout<<"请输入你要删除的联系人姓名!"; cin>>m_name; while(p->next!=NULL) { pre=p; p=p->next; if(p->name==m_name) { pre->next=p->next; deletep; p=NULL; flag=1; break; } } if(flag==1) { cout<<"删除成功!"< next!=NULL) { p=p->next; cout< name< sex< tel< QQ< address< addition< >m_name; while(p->next!=NULL) { p=p->next; if(p->name==m_name) { cout< name< sex< tel< QQ< address< addition< >m_name; while(p->next!=NULL) { p=p->next; if(p->name==m_name) { cout<<"请更新性别:"; cin>>p->sex; cout<<"请更新电话:"; cin>>p->tel; cout<<"请更新QQ:"; cin>>p->QQ; cout<<"请更新住址:"; cin>>p->address; cout<<"请更新备注:"; cin>>p->addition; flag=1; break; } } if(flag==1) { cout<<"\n更新成功"< show(); switch(choice) { case1: { system("clear"); person->insert(); break; } case2: { system("clear"); person->delete_per(); break; } case3: { system("clear"); person->display(); break; } case4: { system("clear"); person->search(); break; } case5: { system("clear"); person->update(); break; } case6: { exit(0); } } cout<<"\n\n按任意键返回....."; getchar(); getchar(); } return0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。