这篇文章给大家介绍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://cqcxhl.cn/article/depcjs.html