用C++实现链表版本通讯录
来源:互联网 发布:淘宝网为什么打不开了 编辑:程序博客网 时间:2024/06/10 06:52
#include <iostream>#include <string>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"<<endl;}}Address::~Address(){delete head;}int Address::show() //主菜单函数{int choice = 0 ;cout<<"\t\t\t\t**************************"<<endl;cout<<"\t\t\t\t* 通讯录c++简易版本 *"<<endl;cout<<"\t\t\t\t**************************"<<endl;cout<<"\t\t\t\t* 1、添加 2、删除 *"<<endl;cout<<"\t\t\t\t**************************"<<endl;cout<<"\t\t\t\t* 3、查看 4、搜索 *"<<endl;cout<<"\t\t\t\t**************************"<<endl;cout<<"\t\t\t\t* 5、更新 6、退出 *"<<endl;cout<<"\t\t\t\t**************************"<<endl;cout<<"\t\t\t\t请输入选择:";cin>>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<<"删除成功!"<<endl;}else{cout<<"您删除的联系人不存在,删除失败!"<<endl;}}void Address::display() //查看联系人 {Contact *p = head;while(p->next != NULL){p = p->next;cout<<endl<<"======================================="<<endl;cout<<"姓名:"<<p->name<<endl;cout<<"性别:"<<p->sex<<endl;cout<<"电话:"<<p->tel<<endl;cout<<"QQ:"<<p->QQ<<endl;cout<<"地址:"<<p->address<<endl;cout<<"备注:"<<p->addition<<endl;}}void Address::search() //搜索联系人{string m_name;Contact *p = head;int flag = 0;cout<<"请输入你要搜索的联系人姓名:";cin>>m_name;while(p->next != NULL){p = p->next;if(p->name == m_name){cout<<endl<<"======================================="<<endl;cout<<"姓名:"<<p->name<<endl;cout<<"性别:"<<p->sex<<endl;cout<<"电话:"<<p->tel<<endl;cout<<"QQ:"<<p->QQ<<endl;cout<<"地址:"<<p->address<<endl;cout<<"备注:"<<p->addition<<endl;flag = 1;}}if(flag == 1){cout<<"\n查询成功!"<<endl;}else{cout<<"您查询的联系人不存在,删除失败!"<<endl;}}void Address::update() //修改联系人{Contact *p = head;string m_name;int flag = 0;cout<<"请输入你要更新的姓名:";cin>>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更新成功"<<endl;}else{cout<<"查无此人,更新失败!"<<endl;}}int main(){Address *person = new Address;int choice = 0;while(1){system("clear");choice = person->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;}
阅读全文
0 0
- 用C++实现链表版本通讯录
- 用c语言链表实现通讯录
- C语言写通讯录 链表版本
- 用C语言实现通讯录文件存储的版本
- 用C语言实现通讯录的文件版本
- 用C语言模拟实现通讯录的文件版本
- c语言实现动态版本通讯录
- C语言课程设计通讯录链表实现
- c语言链表实现通讯录
- 用C语言实现通讯录
- C语言通讯录(利用链表实现)
- 用C语言实现一个通讯录
- 用C语言实现简单通讯录
- c语言实现----通讯录
- C语言实现通讯录
- C语言实现通讯录
- C项目 实现通讯录
- c语言实现通讯录
- css
- 项目IAP代码更新流程
- 解决ubuntu下访问windows磁盘错误
- Spring配置入门案例(配置文件方式)
- msm 关机充电开启与关闭
- 用C++实现链表版本通讯录
- leetcode题解-82. Remove Duplicates from Sorted List II && 445. Add Two Numbers II
- 克隆二叉树
- noip2010 引水入城 bfs+贪心
- hibernate自动生成建表
- 开发可运行于Docker上的Spring Boot应用
- 文本多行最后一行溢出隐藏显示省略号
- Ubuntu如何安装setuptools
- 2017年7月13日21:31:13