标题:小型订餐系统(麻烦找错)
只看楼主
教皇
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2011-10-6
结帖率:95.65%
 问题点数:0 回复次数:1 
小型订餐系统(麻烦找错)
#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;
  
  }
 
 
 }
















搜索更多相关主题的帖子: void head include search create 
2012-04-08 00:23
教皇
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2011-10-6
得分:0 
在输入数据的时候,只能输入两个人的数据,然后程序就显示正在寻找错误。
2012-04-08 10:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-365349-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.183093 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved