重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章将为大家详细讲解有关C++怎么实现链表版本通讯录,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
我们提供的服务有:成都做网站、网站制作、微信公众号开发、网站优化、网站认证、顺昌ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的顺昌网站制作公司具体内容如下
#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++怎么实现链表版本通讯录”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。