📄 plane.c
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
int data;
int seat;
int last;
int flynum;
char endcity[10];
struct node *next;
}node,*linklist;
linklist creat_list(int n){
linklist head,p;
int i;
head=(node *)malloc(sizeof(node));
if(!head){printf("memeory allocation error!\n");
exit(1);}
head->data=1;head->seat=5;head->last=5;
printf("Please input the flynum :");scanf("%d",&head->flynum);
printf("Please input the endcity :");scanf("%s",&head->endcity);
head->next=head;
for(i=n;i>1;--i){
p=(node *)malloc(sizeof(node));
if(!p){printf("memeory allocation error!\n");
exit(1); }
p->data=i;p->seat=5;p->last=5;
printf("Please input the flynum :");scanf("%d",&p->flynum);
printf("Please input the endcity :");scanf("%s",&p->endcity);
p->next=head->next;head->next=p;
}
printf("\nCreat Sucess !\n");
return head;
}/*creat_list*/
void output(linklist head){
linklist p;
printf("------------------------------------");
printf("\n Plane Seat Last FlyNum EndCity\n\n");
p=head;
do{
printf("%6d%6d%6d%8d%10s\n",p->data,p->seat,p->last,p->flynum,p->endcity);
p=p->next;
}while(p!=head);
printf("\n");printf("------------------------------------\n");
}/*output*/
linklist find_list(linklist head,char recity[10])
{
linklist p;
p=head;
do{
if(strcmp(recity,p->endcity)==0)
{printf("\n Find it !\n");
printf("\n Plane Seat Last FlyNum EndCity\n\n");
printf("%6d%6d%6d%8d%10s\n\n",p->data,p->seat,p->last,p->flynum,p->endcity);
p=p->next;}
else p=p->next;
}while(p!=head);
return p;
}/*find_list*/
linklist find_listp(linklist head,int m){
linklist p;int i;
i=1;p=head;
while(p&&p->data<m){p=p->next;i++;}
if(p&&(p->data==m))
{printf("\n Plane Seat Last FlyNum EndCity\n\n");
printf("%6d%6d%6d%8d%10s\n\n",p->data,p->seat,p->last,p->flynum,p->endcity);
return p;}
else printf("ERROR!\n");
}/*find_listp*/
linklist insert_list(linklist head,int x){
linklist p;int num;
p=find_listp(head,x);
printf("How many Ticket do you want : ");
scanf("%d",&num);
if(num>(p->last)) printf("You BookNum is to Large !\n");
else {p->last=p->last-num;
printf("\n Booking sucess !\n");}
return head;
}/*Booking_block*/
linklist delete_list(linklist head,int k){
linklist p;int num;
p=find_listp(head,k);
printf("How many Ticket have You Booked : ");
scanf("%d",&num);
if(num>(p->seat-p->last)) printf("You Num is Overpass the BookNum !\n");
else {p->last=p->last+num;
printf("\n Cancel sucess !\n");}
return head;
}/*delete_list*/
int readcmd(int a)
{
do{
scanf("%d",&a);
}while(a<1||a>6);
return(a);
}
linklist interpret(linklist head,int b)
{
int n,k,x;
char recity[10];
switch(b){
case 1: printf("\nPlease input the num of AirLine : ");scanf("%d",&n);
head=creat_list(n);
output(head);
return head;break;
case 2: output(head); return head; break;
case 3: printf("Please input the endcity of the record you want to require : ");
scanf("%s",recity);
find_list(head,recity); return head; break;
case 4: printf("Please input the number of the Plane you want to Booking : ");
scanf("%d",&x);
head=insert_list(head,x);
output(head);return head;break;
case 5: printf("Please input the number of the Plane you want to Cancel the Ticket : ");
scanf("%d",&k);
head=delete_list(head,k);
output(head);return head;break;
}
return head;
}
void main()
{
linklist head;
int n,m,k,x,a,b,c;
clrscr();
do{
printf("*********************************************\n");
printf("*Welcome to the Air Transport Booking System*\n");
printf("*********************************************\n\n");
printf(" 1. Creat the AirInfo\n");
printf(" 2. Display AirLineInfo\n");
printf(" 3. Require the AirLine\n");
printf(" 4. Booking the Ticket\n");
printf(" 5. Resign the Ticket\n");
printf(" 6. Exit to the System\n\n");
printf("Please give a chioce :\n ");
b=readcmd(a);
head=interpret(head,b);
}while(b!=6);
}/*main*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -