快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

C++中怎么利用链表实现通讯录

这篇文章给大家介绍C++中怎么利用链表实现通讯录,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了紫云免费建站欢迎大家使用!

具体内容如下

#include #include using namespace std;class Address; class Contact{private: string name; string sex; string tel; string QQ; string address; string addition; Contact *next;public: Contact(); friend class Address;  };Contact::Contact(){ next = NULL;}class Address{public: Address(); ~Address(); int show(); void insert(); void delete_per(); void display(); void search(); void update(); private: Contact *head;};Address::Address(){ head = new Contact; if(head == NULL) { cout<<"fail create"<>choice; while(!(choice >= 1&&choice <= 6)) { while(getchar()!='\n'); cout<<"输入有误,请重新输入!"; cin>>choice; } return choice; }void Address::insert() //添加联系人{ Contact *p = head; char relay = 0; while(p->next != NULL) { p = p->next; } Contact *person = new Contact; 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(); }}void Address::delete_per() //删除联系人{ string m_name; Contact *p = head; Contact *pre = head; int flag = 0; cout<<"请输入你要删除的联系人姓名!"; cin>>m_name; while(p->next != NULL) { pre = p; p = p->next; if(p->name == m_name) { pre->next = p->next; delete p; 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) { case 1: { system("clear"); person->insert(); break; } case 2: { system("clear"); person->delete_per(); break; } case 3: { system("clear"); person->display(); break; } case 4: { system("clear"); person->search(); break; } case 5: { system("clear"); person->update(); break; } case 6: { exit(0); } } cout<<"\n\n按任意键返回....."; getchar(); getchar(); } return 0;}

关于C++中怎么利用链表实现通讯录就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


标题名称:C++中怎么利用链表实现通讯录
本文链接:http://6mz.cn/article/gpdgpo.html

其他资讯