📄 汽车售票系统.txt
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct trav
{char tricknum[20];
char name[20];
char num[20];
int seat;
struct trav *next;
};
struct bus
{char number[20];
char time[20];
char city[20];
int seatnum;
struct bus *next;
};
struct bus *creatbus(void)
{int n=0;
struct bus *r,*s,*head;
while(n<3)
{r=(struct bus *)malloc(sizeof(struct bus));
scanf("%s%s%s%d",r->number,r->time,r->city,&r->seatnum);
if(n==0)s=head=r;
else s->next=r;
s=r;
n++;
}
s->next=NULL;
return(head);
}
void increase(struct bus *head)
{struct bus *p;
while(head->next!=NULL)head=head->next;
p=(struct bus *)malloc(sizeof(struct bus));
printf("Give the message of the next day's bus:\n");
scanf("%s%s%s%d",p->number,p->time,p->city,&p->seatnum);
p->next=NULL;
head->next=p;
}
struct trav *creattrav(void)
{struct trav *r,*s,*head=NULL;
int flag=1;
printf("Give the travellers' message:\n");
while(flag)
{s=r=(struct trav *)malloc(sizeof(struct trav));
scanf("%s%s%s%d",r->tricknum,r->name,r->num,&r->seat);
if(head==NULL)head=r;
else s->next=r;
s=r;
printf("If you haven't finish builting,enter1,else enter 2");
scanf("%d",&flag);
}
s->next=NULL;
return(head);
}
struct trav *incrtrav(struct trav *head)
{struct trav *p,*s=head,*r;
p=(struct trav *)malloc(sizeof(struct trav));
printf("Give the message of the traveller who want to buy ticket:\n");
scanf("%s%s%s%d",p->tricknum,p->name,p->num,&p->seat);
if(head==NULL)head=p;
else {while(strcmp(s->tricknum,p->tricknum)!=0&&s->next!=NULL)
{r=s;
s=s->next;}
if(strcmp(s->tricknum,p->tricknum)==0)
if(s==head){head=p;
p->next=s;
}
else {r->next=p;
p->next=s;}
else printf("The ticket isn't on sale\n");
}
return(head);
}
void printbus(FILE *fp,struct bus *head)
{char s[20];
int flag=0;
printf("Give the tricknumber of the bus that you want to know:\n");
scanf("%s",s);
while(head!=NULL)
{if(strcmp(head->number,s)==0){printf("%15s%15s%10s%8d\n",head->number,head->time,head->city,head->seatnum);
fprintf(fp,"%15s%15s%10s%8d\n",head->number,head->time,head->city,head->seatnum);
flag=1;}
head=head->next;
}
if(flag==0)printf("Can not find!\n");
}
void printtrav(FILE *fp,struct trav *head)
{char s[20];
int flag=0;
printf("Give the tricknumber of the traverller that you want to know:\n");
scanf("%s",s);
while(head!=NULL)
{if(strcmp(head->tricknum,s)==0){printf("%15s%15s%10s%8d\n",head->tricknum,head->name,head->num,head->seat);
fprintf(fp,"%15s%15s%10s%8d\n",head->tricknum,head->name,head->num,head->seat);
flag=1;}
head=head->next;
}
if(flag==0)printf("Can not find!\n");
}
void main()
{FILE *fp;
struct bus *head1;
struct trav *head2;
char filename[20];
int flag1,flag,flag2,flag3,flag4=1,flag5=1;
printf("Give the file's name:\n");
scanf("%s",filename);
if((fp=fopen(filename,"a+"))==NULL)
{printf("Can not find the file!\n");
exit(0);
}
while(flag5)
{printf("If you want to built a table,enter 1\n; If you want to increase the message ,enter2;\nIf you want to print the message,enter 3\n");
scanf("%d",&flag);
switch(flag)
{case 1:printf("If you want to enter the buses'message,enter 1;\nIf you want to enter the travellers'message,enter 2.\n");
scanf("%d",&flag1);
switch(flag1)
{case 1:head1=creatbus();break;
case 2:head2=creattrav();break;
default:printf("Enter mistake!\n");
}
break;
case 2:while(flag4)
{ printf("If you want to increase the next day 's bus message,enter 3;\nIf you want to sell ticket and add the traveller's message,enter 4;\n");
scanf("%d",&flag3);
switch(flag3)
{case 3:increase(head1);break;
case 4:head2=incrtrav(head2);break;
default:printf("Enter mistake!\n");
}
printf("If you want to continue increasing,enter1;else enter 0.\n");
scanf("%d",&flag4);
}
break;
case 3:printf("If you want to print the message of bus,enter1;\nIf you want to print the message of traveller,enter2;\n");
scanf("%d",&flag2);
switch(flag2)
{case 1:printbus(fp,head1);break;
case 2:printtrav(fp,head2);break;
default:printf("Enter mistake!\n");
}
break;
default:printf("Enter mistake!\n");
}
printf("If you want to continue the operation,enter1;else,enter 0\n");
scanf("%d",&flag5);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -