|
#include<stdio.h>
0 w$ [- s; Q& k* S#include<stdlib.h>) i: N8 x* i" V
#include<string.h>0 K+ u5 W9 O/ d/ I7 c7 T- J" `/ M2 k% A
#include<conio.h>
; U" n/ l, F/ [# j#define OK 16 u5 c# R, y% r' ~- n
#define ERROR 0
, W& V6 S0 z* p8 Ltypedef struct airline{
+ X9 n- D& v5 S5 o$ m char air_num[8];
% L; C/ Q1 d S V9 q4 v1 m char plane_num[8];
1 l9 _* Q- t, h% W char end_place[20];/ Q. d( g: i% @" z
int total;
& _ g% R ?# |( F' Z: y+ \) d0 q int left;
# E2 W8 F% a' ?3 p/ g4 A" d/ K struct airline *next;* P" I" f( |- G1 R |
}airline;' S7 r B3 N; L3 ~( M
typedef struct customer{
1 p& _, B9 ~- r2 w* r0 S6 \ char name[8];
) v" j) }& i5 Y+ l; {! U5 K char air_num[8];; {; |; l. t3 {# C7 h4 m
int seat_num;
0 E- Q- I+ g/ W6 {2 p7 `2 P struct customer *next;
5 Y: _5 n7 f- ^1 O( F}customer;0 D8 C: w2 L. Q3 p1 X7 j
airline *start_air()
& g+ C z+ r% ]! l b3 U) S" w{2 [+ H$ |' y9 P/ E
airline *a;) }% x3 X. ^# w' b: L8 A
a=(airline*)malloc(sizeof(airline));0 s* d" o V' Q
if(a==NULL)7 V( y2 r; G2 K$ v6 @! K
a->next=NULL;2 t7 O, s4 j( |2 h
return a;2 c' v+ i1 d. W$ l# {% e2 K
}# D! d8 v3 B h6 p: ]+ S
customer *start_cus()8 x! y4 N& l) M
{; o: J$ i) e+ E+ T5 @5 w0 s
customer *c;) D5 a: m$ B3 R. J2 `0 @
c=(customer*)malloc(sizeof(customer));
* z1 P+ O0 Y# R7 @3 ~" H if(c==NULL)
, J5 s( p) p' w# a+ x c->next=NULL;
2 a( Q% m$ }" J# C1 P6 U x6 g return c;
1 Q/ E+ a, e o7 f8 t- z! p* M7 E}1 |+ m O& P$ n$ z
airline *modefy_airline(airline *l,char *air_num)' y+ N7 { Q9 g8 m$ w$ s8 q0 i
{5 k2 M: X5 a7 W2 B6 }+ ?
airline *p;
' H% ?8 K6 p2 S p=l->next;
- f+ H4 j4 u, P, @. l for(;p!=NULL;p=p->next). b5 b# W( l. i; x
{
! v* n3 ^' ~: x( n) g7 R0 E# `; k9 I* r if(strcmp(air_num,p->air_num)==0)& u" [: b/ J+ T c9 L
{( {' |. O" d3 ~# a% B; Q* l& R
p->left++; h* ~# K; @! q7 }
return l;9 O# {; C% Q1 r& e+ n: ]
}
* T8 f" h* e N+ h" I2 Q7 c printf("NO the airline!");
" H! `/ s3 l6 l7 _' u0 _' q return 0;
/ P! {% n" B1 u# t9 N/ m }
: C5 b% R4 g5 Z$ k, Y}
. B" v1 ]( Q) S G( n+ U: a1 D5 Bint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)3 o# U+ ^" G, J) W8 Z' A
{# [3 m1 j- c8 s% V3 y; ]; ~& e
airline *q;
6 R8 V3 c/ e) t; C' ^' } q=(airline*)malloc(sizeof(airline));
$ o5 E# u+ j! V, E7 \ m strcpy(q->air_num,air_num);
7 S8 L* D- y; ^7 D; { strcpy(q->plane_num,plane_num);
@5 z9 Y9 s0 h, k6 R$ n* d" q$ ^ strcpy(q->end_place,end_place);
" V7 V9 ]) b$ {8 o1 e, h2 m q->total=total;
. H4 ]2 G( j1 o1 v* ]; ? q->left=left;
8 _) U* _2 y, I7 `& p) l. Y q->next=NULL;
% L* F* ^% E, N1 E- V (*p)->next=q;
6 W1 p" Q$ n# I+ d (*p)=(*p)->next;
6 _6 W$ C# t7 D) E8 d$ I7 s return OK;
' O' e ]6 q# `- T6 a }
1 q& K' k s7 U+ P" H9 i& Oint insert_cus(customer **p,char *name,char *air_num,int seat_num)
( `8 J& |+ a$ w- m0 |, d0 e{, [5 |" z6 o' i# w8 S7 b/ u
customer *q;# o7 ?+ T8 Z# s3 L# N7 j0 C
q=(customer*)malloc(sizeof(customer));
1 H; p& ^2 l- {1 ^3 ` strcpy(q->name,name);
8 r$ _2 w' O$ T% e: T, O# B" | strcpy(q->air_num,air_num);
9 m8 K$ z1 g. E q->seat_num=seat_num;
4 z$ F, ?+ u# ~7 s8 y' X0 N: K q->next=NULL;' F$ ]8 t2 D' U" d- d
(*p)->next=q;
( s( i! U( a; s: L" ]" p (*p)=(*p)->next;* o9 F7 B7 R* d$ I5 k2 A" ]
return OK;( _1 [6 g. e. m% q' N9 n
}
4 K4 A* s, h. o5 w; s m5 Uint book(airline *a,char *air_num,customer *c,char *name)
2 S1 A, W1 i# j) S{
; G% s6 t4 i+ U9 c: [ airline *p=a;
2 \' z% @, R6 a$ v; R* j0 L" f customer *q=c->next;
: s3 d3 X" W' ?3 }$ J: `8 _ p=a->next;6 A% m: Z; C# e- T
for(;q->next!=NULL;q=q->next){}
' t g& A: S$ b0 K- ^' W$ {+ g for(;p->next!=NULL;p=p->next)# d" c: u* c# I) E$ P! X
{
# v K! a& Y& [# d& e! p8 ] if(p->left>0)
: t# _# f: w$ z( d+ l {7 R$ k3 a' g3 s: Q" k' n
printf("Your seat number is %d",(p->total-p->left+1));' F3 O5 @0 k+ M! Z) k) e; e5 ^
insert_cus(&q,name,air_num,p->total-p->left+1);
# J- y% q: M" q' u p->left--;# M5 Y: v0 H' W) R% d
return OK;3 u8 j: `+ S) [, Q: C
}
, R% ~7 I$ ]: Z6 I5 E& r else
7 C9 L2 `: _7 Y* m0 Z {5 R) s0 h V! a7 C
printf("seat is full");% y) k9 C. R2 ~# g3 u, X6 N8 T1 Y
return 0;. T4 S( b0 F4 q }& H
}# g$ P: L O @- l
}
/ A. |7 s& s4 Y" N7 [5 Zreturn OK;# o4 A$ K# [5 [" b E1 v# {0 Q
}- X7 R) z' m. g/ u% J5 e! h# J
int del_cus(customer *c,airline *l,char *name)7 \( A$ b$ L4 _: R
{0 Y; H/ }. W% l
customer *p,*pr;
: e: X6 F. S8 x1 Z char air_num[8];
1 ^6 W. Z/ g) F& I8 Z" L( E8 ~, ] pr=c;
5 e& h, x* b4 v: I! J: f p=pr->next;* q0 r' N" _; @+ K, j& d
while(p!=NULL)
/ F$ R5 @8 n. \+ O8 O {% e& w0 b6 h, A% m# ]8 w
if(strcmp(p->name,name)==0)' q7 n) K/ g& K2 k& d( K- b
{; M; j5 r$ W3 M. G# S
strcpy(air_num,p->air_num);
" X! I* _/ u0 m. C l=modefy_airline(l,air_num);
5 o$ k; u& ~* z5 M) c! j# z) f pr->next=p->next;
$ x$ d6 w: b1 }: r1 Z+ B' }. H p=pr->next;
6 ?. r! m: v: K) q8 j$ P4 A* C, w9 F printf("finish!");9 w! g7 y- X" [9 n
return OK;
/ c: ~+ z1 a7 l6 S }
' N4 m+ F) X2 ~3 B7 K pr=pr->next;
! [6 D8 q( p( B7 q p=pr->next;: J$ d! p' _8 m
}
7 I* r) y7 A. k# c0 u printf("NO the customer!");
/ h x) ?0 C3 r: W) C' l return ERROR;' G( O) {% t# C& a
}
2 p0 }5 X, j2 Yint search_air(airline *head)) Y& d& d5 _' A: B% n
{
% `* ~5 ^ h' i: j airline *p=head->next;
! ?5 z1 Y& h$ F9 g2 ~* r& N, E printf("air_num plane_num end_place total left\n");
, c) O! A; Y# ~ n for(;p!=NULL;p=p->next)
/ h4 @" k7 L: Q" W2 m {
2 R+ o- o9 V2 L' b printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);, o' Y% m0 ]& m5 p: Q4 B
}& [, I/ @& D8 Y5 ?5 l. y
return OK;# n% E' d$ J5 S, M/ I5 b4 G
}
& y* y# z5 q' n G( _# D5 mint search_cus(customer *head)
) H9 U& m; r) `- ?* Q{
0 y: [! @. X) D/ z$ ]: A5 B5 L. U" q struct customer *q=head->next;9 x0 P; h9 ^0 F* ~
printf("name air_num seat_num\n");( z4 f, P" \7 ~7 L
for(;q!=NULL;q=q->next)
% N# b" ]( h* V# {/ c0 E {
( q% V+ ^# S- Q printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);3 Q9 `; ~' z3 H6 V' x) _: [ O
}
0 ^7 {, j! I( y8 \ return OK;4 W4 p6 k- [# ^- v* q6 N: E" m2 o
}3 g8 A$ M( Y$ ^
int creat_air(airline **l)
( w, B6 s; \' @/ g @1 C{. h+ @/ D3 H5 j+ {5 {
airline *p=*l;* _5 B4 Z' a' ^3 @% R0 y% [
int i=0;3 F( Z9 h* S! m* v! i8 l
char *air_num[3]={"007af","008af","009af"};# Z+ a) ]" R8 v4 ^
char *plane_num[3]={"plane1","plane2","plane3"};
7 z6 ]: H1 U& i- y1 ^4 @: f9 g7 ] char *end_place[3]={"Beijing","Shanghai","Tianjin"};. q% H( Y/ U* y+ U
int total[3]={100,100,100};4 I8 E0 L [* U! o! g( t3 F; I* B6 h
int left[3]={52,54,76};
) D$ a/ U( {& [: {5 r" F for(i=0;i<3;i++)
/ ?) L. d E: S$ R; e; }3 h insert_air(&p,air_num,plane_num,end_place,total,left);
l8 S' b0 |! i0 s+ E7 } return OK;
! Z+ y, c2 X3 o, G}
5 j8 b- K8 B0 ] J! {0 o7 nint creat_cus(customer **l)
- O, M2 y7 O b0 F8 G& v{
, y1 v$ E6 w r8 \ customer *p=*l;
3 R! h. D/ f3 ~4 {$ x# m% k int i=0;
! m8 c6 G1 |( B- J$ D- \. w char *name[3]={"zhsan","lisi","wangwu"};6 U! k \4 ` W/ r8 C$ A
char *air_num[3]={"007af","008af","009af"};
% c8 k% I. W' A" z/ \3 } int seat_num[3]={2,5,7};
: |" Q1 b- ]* f' b' | for(i=0;i<3;i++)
; k7 a% L% ~6 r4 }" ~! |* y3 W insert_cus(&p,name,air_num,seat_num);
+ V% }3 N# Y! q, c! F$ c return OK;& W- ~$ U$ z3 Z/ M: ]
}. x2 E7 U I$ l( a# Q) E
void main()
W: c$ [) e Q1 n: L% h{, ^2 w% [7 M! O4 @$ n1 D
int t=1;) e$ r; t' R8 E8 _0 F: A9 |, h% @$ S4 }+ k
customer *cus=start_cus();
8 T9 G2 }! B% p$ J$ z2 q airline *air=start_air();$ {2 W c9 q: r7 _" s: F& y6 r
char name[8],air_num[8],ch;' Q' ?' ]. f" N) ^) N- I6 @
creat_air(&air);
1 x9 c, @- V" G$ P8 \ G creat_cus(&cus);
6 X: { M0 C& m- U1 C7 ? while(t==1)
5 z- e7 O: Y, ? {
: Q7 x7 s$ T; v2 P2 p% M( a printf("\n");
* K/ A/ I4 n$ l# I/ O" ~ printf("*********************************\n");
- b: j) H8 [7 C4 d! W" n printf("* Welcome to air firm! *\n");6 U% P7 R; x5 N j( M. A; @/ o. F6 D
printf("* book--------1 *\n");
" f" }# K# T2 }8 M8 u printf("* cancel------2 *\n");& V% x8 K) d9 }
printf("* search------3 *\n");
" {1 ~4 K8 ?. R0 ~$ U" z! t1 H printf("* exit--------4 *\n");: x& h5 S+ _9 m9 Y6 ?! b
printf("*********************************\n");
?' z& J& H) v2 P7 r Z$ G* V ch=getch();
9 d) Q0 G7 V; Z6 b: F1 L6 u0 g if(ch=='1')
! V# @, n) ^9 {- T$ i5 j {+ E, t6 C) n5 G. i
printf("Please input a airline number:");
2 B& _6 N/ l; K7 D* ^4 V4 W0 O7 f scanf("%s",air_num);
6 Z. h) Q, j9 o( {- M2 H3 r printf("Please input a name:");
6 h* N L& L8 B scanf("%s",name);
! }- r2 g; z( z9 P3 _& _$ [# N: ]5 c book(air,air_num,cus,name);5 A. W9 q, e0 a5 w
}" N/ D- L& `9 A+ z1 n+ K8 }% e3 s
else
0 Q2 o. V& P5 Z0 g6 ^- \, k if(ch=='2')0 i; I% b' Q$ n
{
( M8 k& _0 L, K printf("Please input the cancel name:");
& P' Z( R8 a; l% }) ?0 R2 E scanf("%s",name);- c, P P. A* @
del_cus(cus,air,name);* }& L( O# l! Z' J
}
& ^% _( ?+ c% ]- r: ]0 Z( A4 V else
& [! j* ] g) K# J) l if(ch=='3')
4 h4 M: j# e, v8 V5 d {; X; [3 N u' D. U+ E* F* M
search_air(air);! e7 v k$ A2 a) u+ L
printf("\n");
* w/ D% H8 R( f# p6 P2 u% ^ search_cus(cus);
# M$ S& \4 Q" `! F: G0 x/ [6 ~ }7 S! T* P2 Z% r, H; ^# O
else# P5 }) H9 l; C+ k& }: U' W# Z' i {
if(ch=='4')
! S+ p: X; V6 E6 a& E {/ E6 o g$ G. w( j( i
t=0;
. Z2 i8 K2 {( V4 Q9 {' |( } }
/ R7 D/ j8 K8 E1 J8 z' o6 K }9 w( a3 o/ V* {3 m Q
} I9 H1 u& f9 [2 @
/*任务:通过此系统可以实现如下功能:4 [1 Q7 l2 _' P* a
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
[4 R% N/ s9 N. c. C3 |* J7 L查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);2 `% A7 F7 Z2 G |0 g
可以输入起飞抵达城市,查询飞机航班情况;+ H- R1 v/ Q |9 {
订票:(订票情况可以存在一个数据文件中,结构自己设定)
$ n p( L# U9 ^# k4 k8 ^6 L }, [可以订票,如果该航班已经无票,可以提供相关可选择航班;
' X# S8 R0 _6 } V+ O/ ~7 k8 Q, L" ^4 \退票:可退票,退票后修改相关数据文件;* s$ C" a! ?. ^, H8 B: l i* V1 K
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。( M9 ^7 ~' q5 ~- d/ C+ Z5 t: H
修改航班信息:当航班信息改变可以修改航班数据文件
`" w- B, ~0 C8 p4 H+ w要求:
. X3 r/ B/ ?! G$ R1 r; k根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|