|
#include<stdio.h>3 d: j7 z) @& |" y- m
#include<stdlib.h>
, \5 T$ a8 U1 | R' e/ `#include<string.h>
# _4 o+ W- p' U2 g4 G" C! j#include<conio.h>5 T0 R# C I( L& q) d0 C. i
#define OK 1
8 `5 M* G' d) {$ D#define ERROR 0
/ f4 ~; \& a. [4 Gtypedef struct airline{
9 K9 U8 n8 U. W. K* J+ x6 \$ b' c char air_num[8];$ X" E" \3 o8 |; J @! m
char plane_num[8];
A7 F, `, J8 W char end_place[20];
0 I) P' @; F0 o+ ^' ] int total;
' ?6 o, H+ y3 s4 T- q2 W& h, W int left;3 N7 o( \7 z8 n+ N+ J
struct airline *next;
/ _+ E, l/ t& x+ c A* K}airline;- e% s7 L' \" _1 s/ u, s
typedef struct customer{3 x- d7 D G% L8 v% v* r
char name[8];
9 G. P& `% f: p' N, N+ i) ] char air_num[8];
8 { ]1 R7 i& y$ r3 W! H: ?. j int seat_num;/ K) t" r3 e, c$ K5 ?
struct customer *next;' @- X9 G$ X0 W6 H/ K8 ]
}customer;( l: ]' }+ g: }- S- `. E2 `
airline *start_air()4 o% B9 `9 p F, A" {
{+ b& j& d1 n) w- G
airline *a;
0 P8 R2 ^8 ^) t1 S, u a=(airline*)malloc(sizeof(airline));: e6 n0 C4 M3 }
if(a==NULL)0 y! y) G( U4 b; N/ X
a->next=NULL;
7 e6 u; `. U5 n return a;
) n0 }+ ~( Z Q0 ~" L+ E}
! _& i9 R$ @* B/ d$ i S9 H5 Ncustomer *start_cus()
4 Z" A4 t) w$ W% ~+ m- R{0 f4 z+ \* v4 }1 Z' H8 p
customer *c;
/ u; r3 S' f L7 S8 j3 `( Y8 Y# _4 ] c=(customer*)malloc(sizeof(customer));
, f! p/ O5 v7 \. c5 m" f. ] if(c==NULL)
* o% a5 e1 \! r( n+ g! Y# N c->next=NULL;
( f4 D0 C9 G' o! U; L2 M% q return c;
% B" n& q0 \# X, n! w2 B}
0 s9 j( u+ W& Z4 b9 t3 X+ eairline *modefy_airline(airline *l,char *air_num)
0 U) @! f7 z5 k4 U; ^4 s" M, n{; x8 y& }9 R! H2 b$ O
airline *p;5 Z- l- y1 g7 T8 l& q* t
p=l->next;
8 W$ n, N8 p5 d9 p- B9 M% U for(;p!=NULL;p=p->next)! R1 k& y0 t3 |+ n* H9 o
{. r0 I6 z# \: _ Y8 y( j* _
if(strcmp(air_num,p->air_num)==0)
r5 A( U" E# L7 F {6 Z3 X2 O. |' R3 u1 T; N- ]
p->left++;; N& z) Q1 x% H) l v
return l;
' |, m- V% z1 g% a8 n9 x. | }# f# |' k) O4 e# n7 b
printf("NO the airline!");) h+ ^( L% l2 B/ t
return 0;
8 T N. l- M- ~" K4 N }
' K+ z l6 `' @}
/ N3 }0 L/ O: r2 L+ d: b/ L. hint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)9 I n% ~! C- I" o
{, s# _5 g9 I# `& v
airline *q;0 {& G! X$ i) D: I- k4 L# k- }6 W
q=(airline*)malloc(sizeof(airline));
" z+ @+ f4 {" T- w) [0 ]$ n$ s6 { strcpy(q->air_num,air_num);% d; h8 i5 A1 D) ^
strcpy(q->plane_num,plane_num);! Z- m2 b8 O4 _0 Q: e5 m/ s
strcpy(q->end_place,end_place);
$ ]; B. W: g) z( o q->total=total;
r0 T+ q4 _# F' H: V+ Y1 y q->left=left;! O: ~3 X* {% `
q->next=NULL;
$ U- u5 X' k& d" I$ I (*p)->next=q;2 d, {: p0 e3 H# Q
(*p)=(*p)->next;
8 Y; f# E+ U7 ]% i3 }9 D return OK;
$ O" a$ z2 [2 X0 C* B+ h& r7 R }4 B3 G# E+ T U# G+ o/ V! q
int insert_cus(customer **p,char *name,char *air_num,int seat_num)6 |7 C% N( \( u; X8 ^0 s8 k9 I4 O
{1 F6 V6 o. r) {# q
customer *q;+ U+ F, }3 h1 x4 V. y9 J ]1 V/ s
q=(customer*)malloc(sizeof(customer));7 [$ p. w6 r t5 H8 t6 ?
strcpy(q->name,name);7 b4 A; @7 j- J( R+ N: m
strcpy(q->air_num,air_num);
- J4 j, c0 G! _( D* a q->seat_num=seat_num;
: E" B: K+ _% Z+ h" B( n q->next=NULL;
; N4 _" E& i% W9 K (*p)->next=q;
8 q' P/ _* x/ D! ?4 d4 S6 n (*p)=(*p)->next;* B/ s' Q7 r; ~$ F5 i3 o G
return OK;
6 A8 b; I; |4 H}/ P4 d6 Q( f- }* ?' p
int book(airline *a,char *air_num,customer *c,char *name)
" K8 R4 f8 b* s7 x{0 J6 ~0 {- K3 B
airline *p=a;5 F+ y' n0 Z [0 ?( E
customer *q=c->next;* p* _" x6 h' Z2 ~5 Y
p=a->next;
5 b ]: G Q: } for(;q->next!=NULL;q=q->next){}
- V& Y1 R* _# L8 R6 Q) s7 \ for(;p->next!=NULL;p=p->next)
- N" N; Y D: g& b {7 A( q' c/ k# s& z7 e
if(p->left>0)/ z' `, L8 S, p: T& E% w( I
{
1 s5 _5 R; D# }: Y* X2 d | printf("Your seat number is %d",(p->total-p->left+1));
6 H9 }1 M- B) L! c insert_cus(&q,name,air_num,p->total-p->left+1);
$ _5 G% n# h( X p->left--;
. `# E P/ R! r return OK;" y# m9 A: g5 u4 J6 c( q2 y
}
- P" y0 ^, ?! R) H, | else
5 |( }* H: {* R; G! L* ` {: Z% Z4 U; ?# O+ b
printf("seat is full");$ g [/ c) A! }, o$ `6 \9 p
return 0;
V& A% [8 [2 g6 q, R/ i }3 t/ k2 D# r/ X1 ~( x. f/ U1 {
}
" |9 f! r+ O3 \7 @/ \8 a0 {' lreturn OK;4 E% I: G# T# _# u( b
}+ t9 f1 Y# C) d/ X
int del_cus(customer *c,airline *l,char *name)" h9 r3 e1 W4 s6 y
{
. d2 R( F1 G! k+ Y$ h# X6 [ F- y customer *p,*pr;1 R" {: m# n$ s- X4 d
char air_num[8];
/ F: N" ~) P0 ?4 Z. b4 t pr=c;% ^9 h) G U& S
p=pr->next;! V R1 }$ {1 I7 Q9 {- F
while(p!=NULL)
2 ~8 [: E( N( N. f5 K {
* ~& Y. d4 L4 n4 T9 G if(strcmp(p->name,name)==0)' n' ~7 h' u* s; D: f$ j8 Q
{2 ?, k! c& t+ S. G0 w- _* M
strcpy(air_num,p->air_num);
7 I5 ^: e+ ^8 q5 R. ~ l=modefy_airline(l,air_num);
3 B2 N/ E, F+ G: L) o3 e+ Q pr->next=p->next;
( G% }$ e% S$ P& `% ]: z) x p=pr->next;2 n. }. c" i& E# @' {/ v
printf("finish!");
4 m2 ^: z# T" T return OK; ) u2 f* |- ]- T, d
}, `' ~' R7 [5 k* B" J8 I
pr=pr->next;, {% @& r7 J: ^/ H! u* x
p=pr->next;
9 q: F' m, `; ] R! H }
/ S# e8 [# `9 Z L% a" j+ _ printf("NO the customer!");8 x5 @! \7 l* R3 u# y, g# H3 i
return ERROR;4 D0 ?, E3 ^- T( e$ V
}
+ X+ q6 m$ e( D+ aint search_air(airline *head)
+ K% Q8 ^( x2 d& H$ Y0 G5 |, W{5 d6 y+ I' H; @) O1 l
airline *p=head->next;
9 o0 R2 }$ v8 M$ U) o printf("air_num plane_num end_place total left\n"); d; q4 V _6 e1 _+ E- O
for(;p!=NULL;p=p->next)2 r" K+ W9 C2 k, G' M) Z2 [- ?, m! h5 c
{+ `* n* e8 _. c9 D9 g
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
" v# r" L4 z8 }& h% C8 V, b- R3 X }
( H$ M6 r' P: J2 T; S4 } return OK;5 y3 B9 J6 x# ?$ F8 k) q C; t4 k' I
}
& M! e# T! H9 Uint search_cus(customer *head)0 N3 U+ b$ z5 A6 K9 l/ S; m
{3 `7 P+ k. Z9 X8 @
struct customer *q=head->next;
, y$ o2 ?" S; M0 u* } printf("name air_num seat_num\n");
# N- y4 z% M/ v8 b5 a+ E# j for(;q!=NULL;q=q->next)
( G. y( ~9 g4 i- n: K, k6 f- t {
( z2 R+ e8 P$ V6 b! z( Z, u printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);4 `8 J9 } r! ~: j" l7 m
}
/ L6 d. ^" u& {% P. E+ B return OK;7 |1 I- A' q9 p h; `! ?1 U
}
7 |7 r* c/ d/ }1 sint creat_air(airline **l)" O3 G% s& c a+ k9 p
{
+ }* ^' j% v) f; b# m' B airline *p=*l;" n# t3 @; X8 q u7 X
int i=0;
+ G* u. t+ j/ k' c1 k( M: N, w char *air_num[3]={"007af","008af","009af"};" y: j. e- h: j+ h7 P4 d
char *plane_num[3]={"plane1","plane2","plane3"};; b- P# [; [ @. H' i
char *end_place[3]={"Beijing","Shanghai","Tianjin"};8 u5 \: u; D0 @' {$ F0 l) b+ r
int total[3]={100,100,100};. Z) n& u5 L: @0 H L4 P
int left[3]={52,54,76};
; ?) U3 f# k) H+ r/ } `! _ for(i=0;i<3;i++) z0 Z6 S. N* x t/ `
insert_air(&p,air_num,plane_num,end_place,total,left);4 l3 c* [7 N; a5 k- P
return OK;
8 e7 P' a q% a" k* l}3 m. h6 W. l5 E' }; i0 R5 G* T
int creat_cus(customer **l)0 z& W( @# h" r$ l1 A
{
6 P/ H9 m0 J; ]# c% h customer *p=*l;3 h8 V% F$ M/ T( U
int i=0;
8 B5 b7 S/ i+ q* l! i8 T6 P; Y char *name[3]={"zhsan","lisi","wangwu"};3 C6 ^% k7 F% g3 s7 |1 h; z9 {6 H" v
char *air_num[3]={"007af","008af","009af"};( C/ Q& W9 T' B& ~4 @6 W: ~$ q [
int seat_num[3]={2,5,7};
; i1 ?* i+ g; ^- f for(i=0;i<3;i++)1 s* t- {0 |1 U. E: ~% Q
insert_cus(&p,name,air_num,seat_num);6 r$ \# Z8 |0 L# g, t; x5 V
return OK;
$ D, B4 p* T& b5 H& G& P+ a0 C3 b4 J}
& n7 b6 Q3 K1 S5 {void main()
8 b2 p, u7 A! K- K+ s{
& E Z1 y5 c- c8 R6 V+ X int t=1;. U y% l! p J+ ^3 d$ E/ H$ G: ^
customer *cus=start_cus();
& |: J. A) j0 v1 { airline *air=start_air();0 _+ Z9 D; H8 Q9 H/ i" X
char name[8],air_num[8],ch;$ K9 J7 ?0 a3 g& ]: L' S
creat_air(&air);3 D8 T$ Z: U8 L8 I; F" v( I
creat_cus(&cus);2 m% ?) F, u- J
while(t==1)" H$ o9 q: [% W( K, k
{
/ \$ f4 K( ], B$ o printf("\n"); \2 P0 G8 {' O8 d9 S6 V. |# a$ L
printf("*********************************\n");
3 R1 P3 m( h, H2 C% ` printf("* Welcome to air firm! *\n");; x; f2 u! _+ Y
printf("* book--------1 *\n");* F! ?: _$ J9 V: h/ q8 x# N
printf("* cancel------2 *\n");
+ }+ e+ R/ l; m5 J printf("* search------3 *\n");3 r i! a1 `1 i! C! b" P
printf("* exit--------4 *\n");% U' V$ q7 [" ^$ D
printf("*********************************\n");
* n8 N: M" A& G0 u2 B& p* C ch=getch();
, d0 D0 O% I8 L if(ch=='1')
9 X- x+ I* ?; p! N) n {- q" p+ T1 _4 P$ ?& c& ~' f
printf("Please input a airline number:");
( W* D1 P9 E! y& W, O) k, ^* r scanf("%s",air_num);3 p0 P, u' y) N! K; E
printf("Please input a name:");
/ ]* O3 ?6 c, X- I scanf("%s",name);
& _) W7 [% V5 m, k; b& O book(air,air_num,cus,name);
1 G% c8 `; q: V$ c2 @ }
, M' f6 r! \. c; a' Q/ j$ V( e$ e% d else
2 Z! l; z/ T9 N0 t( } if(ch=='2')" G' B+ j+ W: F- u( h8 Z6 N
{* C* G& ?# H% W, Y! [. `) [
printf("Please input the cancel name:");
( |2 [6 W( s4 C' N# _ scanf("%s",name);
, K" P; _- q' Q4 Y% [' F0 Z del_cus(cus,air,name);5 `9 {; b# _! T: `/ Y% ^
}0 L2 M% _% f: L# {4 X. l! Y
else
/ [1 k9 {& }, r. K" m if(ch=='3')
% y% m1 T% X6 h0 X7 I {
P1 w: s) _- E6 e search_air(air);
" H, O& U5 y% W# j( Z& y9 A printf("\n");
4 D* e8 O0 R6 c& t' R& |5 ^ z search_cus(cus);8 _+ x! @; T( @2 [* P
}
: ~; f. w% G/ ^& e) o6 X else% p0 s6 I5 N2 d/ J T
if(ch=='4'). m$ d* j1 M! a9 t& z' I
{
* @$ \# c1 l6 x t=0;
( P2 }$ S) D$ A! n/ x T% P8 @ }* J, z+ H, n2 l4 |
}
7 ?9 ?6 {! d6 l) ~- P}
, _0 Y8 C' P$ U$ H/*任务:通过此系统可以实现如下功能:% U' q9 I- l# b6 i
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
J& Z2 e; r/ N) q7 `查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
3 u0 _# R5 L' Q. a$ H& J! ]) b可以输入起飞抵达城市,查询飞机航班情况;% I+ s* r+ m( s2 |1 G& n9 P
订票:(订票情况可以存在一个数据文件中,结构自己设定). L9 ^) d. C7 t) ?
可以订票,如果该航班已经无票,可以提供相关可选择航班;
) \! a* E9 n6 K. A6 z退票:可退票,退票后修改相关数据文件;& u' t2 _2 Z9 n7 A
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
$ o; l" a0 x. t. ]9 h4 Z修改航班信息:当航班信息改变可以修改航班数据文件4 o. [4 r7 g# r
要求:: c3 [ ^5 d: @
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|