/*用单链表的形式做成的电话本:功能:插入成员,删除成员,修改成员,搜索成员,输出整个链表*/
#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;}}
该回答引用ChatGPT
这段代码存在一些语法错误,因此在VC6.0中运行可能会出现问题。下面是修复这些错误的建议:
在代码开头添加头文件 ,因为代码中使用了 strcmp 函数。
在函数 print 的定义中,应该将 tel 修改为 void,因为该函数不需要返回值。
在函数 insert 的定义中,应该将 tel 修改为 void,因为该函数不需要返回值。
在函数 search 的定义中,应该将 tel 修改为 void,因为该函数不需要返回值。
在函数 update 的定义中,应该将 tel 修改为 void,因为该函数不需要返回值。
在函数 delect 的定义中,应该将 tel 修改为 void,因为该函数不需要返回值。
在函数 main 的定义中,应该将 void 修改为 int,因为 main 函数需要返回一个整数值。
在函数 main 的定义中,应该在最后添加 return 0;,因为 main 函数需要返回一个整数值。
另外,代码中存在一些拼写错误,例如 delect 应该为 delete,number 应该为 name,findname 应该为 name,等等。