日暮下的约定 2014-03-02 05:28 采纳率: 0%
浏览 853

单链表做电话本 在VC6.0中运行不了?

/*用单链表的形式做成的电话本:功能:插入成员,删除成员,修改成员,搜索成员,输出整个链表*/
#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;}}
  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-03-05 13:06
    关注

    该回答引用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,等等。

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况