小型订餐系统(麻烦找错)
#include<iostream.h>#include<string.h>
struct guest
{
int num;
char name[6];
int member;
char time[7];
guest *next;
};
void main()
{
guest *create(void);
guest *del(guest *head,int num);
guest *search(guest *head,int num);
void print(guest *head);
void del(guest *head);
guest *head,*p;
int num,n;
cout<<"=================="<<endl;
cout<<'1'<<"==="<<"create"<<endl;
cout<<'2'<<"==="<<"del"<<endl;
cout<<'3'<<"==="<<"search"<<endl;
cout<<'4'<<"==="<<"print"<<endl;
cout<<'5'<<"==="<<"exit"<<endl;
cout<<"=================="<<endl;
cout<<"what do you want to do:";
cin>>n;
while(n!=5)
{
switch(n)
{
case(1):head=create();break;
case(2):cout<<"请输入要删除的号码:";cin>>num;head=del(head,num);break;
case(3):cout<<"请输入要寻找的号码:";
cin>>num;
p=search(head,num);
cout<<p->num<<endl;
cout<<p->name;
cout<<p->member<<endl;
cout<<p->time<<endl;
break;
case(4):print(head);break;
}
cout<<"what do you want to do:";
cin>>n;
}
}
guest *insert(guest *head,guest *p)
{
guest *p1,*p2;
if(head==NULL)
{
head=p;
p->next=NULL;
return (head);
}
p1=head;
while(strcmp(p->time,p1->time)>0)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p->time,p1->time)<=0)
{
p->next=p1;
if(p1==head) head=p;
else p2->next=p;
}
else
{
p1->next=p;
p->next=NULL;
}
return(head);
}
guest *create(void)
{
guest *insert(guest *head,guest *p);
guest *head=NULL,*p1;
int num;
cout<<"input the num:";
cin>>num;
while(num!=0)
{
p1=new guest;
p1->num=num;
cout<<"name:";
cin>>p1->name;
cout<<"member:";
cin>>p1->member;
cout<<"time:";
cin>>p1->time;
head=insert(head,p1);
cout<<"input the num:";
cin>>num;
}
return (head);
}
guest *del(guest *head,int num)
{
guest *p1,*p2;
if(head==NULL)
return NULL;
p1=head;
while(p1->num!=num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num==num)
{
if(head==p1) head=p1->next;
else
p2->next=p1->next;
delete p1;
cout<<"已经删除";
}
else
cout<<"无此订号";
return (head);
}
guest *search(guest *head,int num)
{
guest *p;
p=head;
while(p->num!=num&&p->next!=NULL)
p=p->next;
if(p->num==num)
return p;
else
return NULL;
}
void print(guest *head)
{
guest *p;
p=head;
while(p!=NULL)
{
cout<<p->num<<endl;
cout<<p->name<<endl;;
cout<<p->member<<endl;
cout<<p->time<<endl;
p=p->next;
}
}
void del(guest *head)
{
guest *p;
while(head!=NULL)
{
p=head;
delete p;
head=head->next;
}
}