/*用单链表的形式做成的电话本:功能:插入成员,删除成员,修改成员,搜索成员,输出整个链表*/
#include
#include
using namespace std;
struct tel{
int number;
char name[20];
tel *next;};
/*print the whole line*/
tel print(tel*head){
tel*p=new tel;
p=head;
while(p->next!=NULL)
{
cout<<"name"<name<
coutnumber<
p=p->next;}
return *head;}
/*insert the new member*/
tel insert(tel*head){
tel*p=new tel; tel*q=new tel; q=head;
cout<<"please input what you want to insert"<
cout>p->name;
cout<<"number:";cin>>p->number ;
while(q->next!=NULL){
q=q->next ;}
q->next=p;
p->next=NULL;return *head;
}
/*search the member*/
tel search(tel*head){
tel*q=new tel;
q=head;
char findname[20];
cout<<"please input who's number do you want to search"<
cin>>findname;
while(q->next!=NULL){
if(strcmp(q->name,findname)==0)
{cout<number<
break;}
else{q=q->next ;}}
cout<<"what you find is not exist"<<endl;
return *head;
}
/*update the data*/
tel update(tel*head){
tel*p=new tel; p=head; int number;
char findname[20];
cout<<"please input who's number do you what to update"<
cin>>findname;
cout<<"please write out your new number"<
while(p->next !=NULL){
if(strcmp(p->name,findname)==0)
{p->number =number;
break; }
else {p=p->next ;}}
cout<<"what you find is not exist"<<endl;
return *head;
}
/*delect the member*/
tel delect(tel*head){
tel*p=new tel; p=head;
tel*q=new tel;
char findname[20];
cout<<"please input who's number do you want to delect"<
cin>>findname;
while(p->next!=NULL){
if(strcmp(p->name,findname)==0){
q=p->next ;
p->next=p->next->next;
delete q;
break;}
else {p=p->next ;}}
cout<<"what you find is not exist"<<endl;
return *head;
}
/*main*/
void main(){
tel*head=new tel; int letter;
cout<<"what do you want to do?"<
cout
cout
cout
cout
cout
cin>>letter;
while(letter!=0){
switch(letter){
case 1:delect(head);break;
case 2:insert(head);break;
case 3:update(head);break;
case 4:print(head);break;
default: search(head);}
cout<<"what do you want to do?"<<endl;
cout<<"if you want to delect,please input 1"<<endl;
cout<<"if you want to insert,please input 2"<<endl;
cout<<"if you want to update,please input 3"<<endl;
cout<<"if you want to print, please input 4"<<endl;
cout<<"if you want to search,please input 5"<<endl;
cout<<"if you do not want to continue,please input 0"<<endl;}}