这篇文章将为大家详细讲解有关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++怎么实现链表版本通讯录”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。