|
#include<stdio.h>. ?8 a6 _7 b) i a( m" a1 h) j
#include<stdlib.h>: M) J# U/ y8 D0 l! [* k; a* W( j
#include<string.h>
5 ^1 s% P/ k; j5 x1 H# R#include<conio.h># F% Q# I& h; A
#define OK 15 ^ R& r$ W9 N: g' {
#define ERROR 0
0 x3 d1 K% m! {* m. Mtypedef struct airline{- n8 B# |$ Z2 z$ Z7 J' Y
char air_num[8];% n0 N8 y H$ v x
char plane_num[8];
+ {7 t" @ w; _0 C6 K char end_place[20];
" q+ B9 z3 u4 n2 e int total;7 N4 e* y0 j/ W
int left;
8 v2 l3 q) e& E5 R% e struct airline *next;
3 U' o) {# o( t% w( M5 q$ P0 u}airline;
$ M2 Q' i" U! U" Etypedef struct customer{
. z6 J) j0 Y6 l: T8 `1 t6 Z char name[8];
% P1 s+ x8 j4 a6 d char air_num[8];3 c5 Q( e; G C
int seat_num;
7 z% |4 {7 P% Y5 f- p$ B0 S0 u9 O struct customer *next;) p1 ?/ s$ B7 I- V# I1 g5 t
}customer;) C/ T& {5 u) o6 v7 P2 `: K
airline *start_air()
9 Q; d& ]1 y( T' v \{1 r' n, l. V2 c# D% [! C# \' t
airline *a;# h3 n" L3 ~" R: `0 b2 U' B
a=(airline*)malloc(sizeof(airline));! b' H' k; M; L7 M4 s3 k
if(a==NULL)" B. ?7 T6 i' ?( V
a->next=NULL;- b( ^1 |) D, ?& q- A' _
return a;, N" p: h( G1 Q$ E1 [5 u
}
/ ]( ?0 L$ M$ z9 ~5 Fcustomer *start_cus()1 ?" b% o! U( ?4 U. f6 |9 a
{
* {+ |7 }; S: d+ C j$ Z customer *c;6 i! y1 F( v9 T) w6 w" C
c=(customer*)malloc(sizeof(customer));
1 ]; R$ s9 q" b$ o6 t2 \ if(c==NULL)
) J8 m* m! _ E/ L8 ]5 Y c->next=NULL;' B. w# }* p; P3 y7 X
return c;9 ?8 u; y! J3 C9 P, o
}5 z" C7 @/ S- e/ m2 I/ M! U
airline *modefy_airline(airline *l,char *air_num)
! R3 }7 G' i0 g; f) w" R{
: \6 N3 H. t8 M airline *p;
2 A9 _( Z; z$ ~! o* p) q p=l->next;
) O; ~8 r4 d' D- U for(;p!=NULL;p=p->next)8 v( J9 W( J; y6 p! R! M
{
Q6 `( d- O0 { if(strcmp(air_num,p->air_num)==0)/ y* p* b, I9 G8 _3 ?; ^, v
{
5 d: f5 e' Z" o: o; E p->left++;
9 W4 X7 ~6 c1 s0 d, d6 }7 W return l;7 F. K9 {* {, d T: f: x, a- \
}1 D2 z0 i% ^2 _( s8 }$ J
printf("NO the airline!");
: A. e$ v6 }# Q; G7 l: B' B return 0;
! ]. K4 e. b4 D3 A( Y5 s1 B5 j: ?: c- I }7 X* [1 L" e0 o. X
}: {, T" W* n% b% r; M4 \" d* g! g5 P
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
8 K( M" z, h1 v2 i) L{
& d: t! e- a6 z: a. u( n) u airline *q;
3 Z( q& e( ?7 x# V q=(airline*)malloc(sizeof(airline));
: ]" s; X, G$ N; m( E) ?1 K strcpy(q->air_num,air_num);$ M! t- y0 X: P1 V
strcpy(q->plane_num,plane_num);) V, d. N0 `5 P) Y1 m2 O9 ]
strcpy(q->end_place,end_place);2 L3 Y1 P6 A8 x& V
q->total=total;
G; G @ U5 m/ @ q->left=left;" y2 g p( \. z0 o1 h7 |3 h
q->next=NULL;
, f3 m" N! ~- A+ x' e (*p)->next=q;
8 C. e+ I% K# o* y. q (*p)=(*p)->next;4 j9 _5 Q: O$ V" i1 W( Q; S7 G
return OK;. H! Z% _3 d* l0 @9 [ T
}
% M: ]- H$ T* Y3 U) s- e6 Cint insert_cus(customer **p,char *name,char *air_num,int seat_num)
/ Z6 i' B, N P3 R' V! M) d{
2 Z2 t; f- I0 N customer *q;
" P% w! u! w, s( q: O q=(customer*)malloc(sizeof(customer));; o1 W4 K! o, I+ I
strcpy(q->name,name);( q) \& p5 I9 U7 \
strcpy(q->air_num,air_num);
, f. ?) Z9 m& K4 B, _/ E q->seat_num=seat_num;
; K8 g+ C( \' {' [ q->next=NULL;
+ s1 R6 f2 e" [+ H5 t (*p)->next=q;: O: d. x/ ^0 T: g, J* h9 U5 ~( y( c* e
(*p)=(*p)->next;) v" B3 T9 g; i5 R/ ~: m1 t# D
return OK;
) W( ]' v2 B# q( c N; f}
: G, \ D! q/ |- S5 |9 t: Lint book(airline *a,char *air_num,customer *c,char *name)/ N9 d3 p6 }' `; T# U/ p
{9 s$ K( j2 P8 w$ Z3 V; T
airline *p=a;3 t. H2 z, X P
customer *q=c->next;
0 G7 f/ _ ~; U9 Q4 ? p=a->next;$ n# c! Q u6 o5 x
for(;q->next!=NULL;q=q->next){}
$ R) D0 T- w; d9 {- s% S& N for(;p->next!=NULL;p=p->next)
9 C( H5 J$ ^* `; m/ N3 h& D {4 c* Z4 D; z5 t0 {+ c9 f
if(p->left>0)
* D: r6 W0 N" Q/ @ {0 p {0 R* J, X" y( L1 v& ]( e
printf("Your seat number is %d",(p->total-p->left+1));
: l5 X: J6 n. e insert_cus(&q,name,air_num,p->total-p->left+1);7 \' `9 c4 }9 w* e$ ^
p->left--;" X0 g- x7 D; S
return OK;) o" s% ^ p/ ^
}; J/ E# \' e# Y, Q5 P5 w
else
* _/ o7 l% N' n# X6 x% ^ {
$ u2 I1 Y2 I! q4 W printf("seat is full");
# C ]% G4 [( z! x9 e return 0;' U! ^2 P0 ]. B8 O$ e- z2 o; u3 p( Q" X8 p
}
* p1 b% F( `+ @- a, z }$ k6 O/ a9 T4 S T
return OK;
7 Q/ f9 O0 L- }" H/ @}
6 _% r4 x( Q4 j- uint del_cus(customer *c,airline *l,char *name)4 a8 y* W! p% s$ g6 h
{& i) F {- C4 z
customer *p,*pr;
- z% V- r$ k% w: G X char air_num[8];
8 A! H- R! J' w! V1 e# d# N; `* z pr=c;+ H! Z3 m' X) I
p=pr->next;' e8 N! n: |# |$ j2 ?6 z
while(p!=NULL)
( H$ `4 x7 c% O: V. v* m {
% `0 i' u4 F" b5 k- e# N9 I1 k if(strcmp(p->name,name)==0)
1 S' ?5 o* \+ x6 ~. P$ a/ x% S$ q7 f {
2 z7 H7 K7 P# G2 y9 m! x1 c5 ` strcpy(air_num,p->air_num);
) t6 S; q8 C* c2 j l=modefy_airline(l,air_num);3 z. h: H# f/ J- } c' R2 \6 P
pr->next=p->next;; t' h' K) z/ d+ P; f
p=pr->next;
/ z4 g9 m+ r" _' a. E7 d printf("finish!");
1 B z) ]2 W/ N/ J$ M return OK;
* B& j+ H/ b' d, j" D7 W- t }5 f- H- l% ^ p6 @7 M, S% i
pr=pr->next;
1 u. a8 p$ L2 r z8 Q5 \2 O: P p=pr->next;( x& U: J6 @' z0 s
}
- o5 | k4 A8 {* b# S# w printf("NO the customer!");3 b" g% o" B( |, M- O7 v
return ERROR;
0 S# f0 P0 x, o+ g& J4 [}" D" Q- |% p# J; D+ f1 L+ V
int search_air(airline *head)
6 v2 [5 _0 x, O' B{
1 \0 o" r6 v& m4 j: j airline *p=head->next;: h8 {: Q5 S' d5 D
printf("air_num plane_num end_place total left\n");
" n/ w3 V' D) c) b: A for(;p!=NULL;p=p->next)
" J: D0 N- @+ x5 j; z {9 U! T3 f9 L1 v. M# Z: H
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
/ V5 ]7 C2 `6 d3 ]& J }
* B! ~' @# B5 }2 B; q6 G! G$ {& @ return OK;
9 Y4 ]+ \ B' F; z$ {; t$ E" h5 b}
$ P- k7 g/ r5 p$ L$ ]1 \7 Jint search_cus(customer *head)
' b/ H. i5 Y% l4 U. X{
& ~9 i' r/ M' k8 J2 ^ { struct customer *q=head->next;1 W! g4 L, [4 P, k E" D
printf("name air_num seat_num\n");, p$ _! I. I; R$ O2 a7 a
for(;q!=NULL;q=q->next)
. I! x) F2 o4 K" _: ?& P {8 f' b' v9 s! N2 R
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);: `* Y3 y9 k' J0 [! t _
}* Y6 o; E( ~7 V2 s3 a4 T" K
return OK;
, u1 l8 L1 I1 ?4 I}
$ O1 K8 t+ R, J- S6 }int creat_air(airline **l)* E- ~+ e t, E% @! O# n
{% Q2 c) J' u4 ~$ p& H7 p
airline *p=*l;
4 ~, u; j; e2 T/ l8 d int i=0;
y7 \! n/ k3 C5 ] char *air_num[3]={"007af","008af","009af"};3 M9 W0 {* L* _5 ^$ V
char *plane_num[3]={"plane1","plane2","plane3"};
9 A4 i. i0 e; H char *end_place[3]={"Beijing","Shanghai","Tianjin"};. i4 J3 Y/ @& N. \- }7 q5 r* V
int total[3]={100,100,100};4 i: H/ ~' E$ @) u8 Z0 `
int left[3]={52,54,76};& h {% F' X9 g
for(i=0;i<3;i++)% j$ Y! }" \" C6 ?# A; I* s$ {
insert_air(&p,air_num,plane_num,end_place,total,left);0 ^: _ X! S9 O8 J- O: X% S0 m2 w
return OK;
$ O- L0 d \; H5 r3 F; v}
6 W, L' ~! s2 _) ], o1 ?' b ?" \int creat_cus(customer **l)& F- ^4 h9 W [4 o4 B* r
{
1 ^, u9 q) Q* r: ?& ^6 d _ customer *p=*l;
7 W) l. ]3 b0 W5 E" X( B int i=0;3 b) h( v- G7 H" B" h( C
char *name[3]={"zhsan","lisi","wangwu"};$ ~7 s, C, c3 x, {" R" ?/ l
char *air_num[3]={"007af","008af","009af"};
. f! e/ F# C5 H# A+ P) ]7 z) o int seat_num[3]={2,5,7};
& t9 r( ?# O# e2 E3 @9 m. E for(i=0;i<3;i++)3 e7 n8 V! E% R; @7 c
insert_cus(&p,name,air_num,seat_num);
3 z* P* i3 y2 A- H return OK;0 y T* {$ ^" U# ? u. m
}
1 n5 m! x$ A- t" ?7 G/ Yvoid main()9 i) j( [; a& V( d- S' e
{1 X1 {! H% a0 u+ O! H
int t=1;3 D" U/ H, j' J* q3 m% X
customer *cus=start_cus();/ a. M9 w$ `8 t: p# x6 \2 j2 U/ {
airline *air=start_air();! T3 }& C& M9 B
char name[8],air_num[8],ch;
0 L, W: T! c9 x creat_air(&air);
4 @% r5 U {5 ?" L creat_cus(&cus);7 x+ w5 n- U4 Z3 m( Y" c/ y; e
while(t==1)' h0 e& i# r" R3 g1 A1 }& t# `
{+ @2 _! m4 m/ ]: o9 v! l& J: h8 k
printf("\n");, H2 o& r. D, S. F% t" J0 b, h/ {
printf("*********************************\n");
1 A2 v: t' l( s8 i printf("* Welcome to air firm! *\n");! \8 Q3 r3 m4 b* j7 ?% P1 y
printf("* book--------1 *\n");' k, M% k0 R8 ~0 ]# U) F
printf("* cancel------2 *\n");
9 k7 M5 ^; F9 x9 I: _" z3 _ printf("* search------3 *\n");
' s7 g2 U( f3 P5 _ x7 t! U5 F printf("* exit--------4 *\n");
2 e, T& \5 x; Y/ U printf("*********************************\n");
/ l+ n2 W2 v- p ch=getch();
1 L" f9 {3 ?; w1 i4 P' l if(ch=='1')2 d2 ?8 T8 L r8 R( C% |
{9 t% n% U$ V8 }' d
printf("Please input a airline number:");
) O( E* a+ o0 p# f7 y scanf("%s",air_num);
. V% |3 ]2 w3 n* e* _ printf("Please input a name:");
3 V: G2 {" R' U scanf("%s",name);
1 R) @, W5 f0 s8 R0 H: f book(air,air_num,cus,name);* `! K3 c# j6 o6 n
}
x+ ^1 @. q! }6 e5 k) ]# L" O) u5 u0 H else* z. c$ H3 G1 B
if(ch=='2')
0 n; b ^% H! o3 R3 @: M {
% |4 l9 d- B7 G& p( L1 j# _ printf("Please input the cancel name:");
7 A" |! }, r0 G- w scanf("%s",name);
, k$ G% i9 ~6 r0 Q del_cus(cus,air,name);
0 E+ R/ ~5 F. _: ^+ Y" j6 W }
" r9 D( ^7 a% i3 w9 ] else
8 s7 s$ D1 J$ C7 X9 D2 j if(ch=='3')" y. \* p% k o$ g) I* H3 H2 z
{
) w5 b: L# ~) x- v9 r search_air(air); C) s( Q$ P* {4 l% H! p/ k0 j
printf("\n"); 5 S) ?+ y+ O# [1 |; T# n/ E
search_cus(cus);
+ l4 T4 {2 X7 j8 K& J }
K, V) Z( K0 J else7 d! u. y4 A, |) O/ t% `$ w1 g/ j
if(ch=='4')$ t. [3 D5 V3 w" R
{
r: P8 E5 Z" _) m& L t=0;3 C5 H) L0 I e8 z( [" I- q* F2 K
}
4 l/ `- ]2 S1 p8 F }# r+ y# p+ k# w; l! e
}# Z: V+ V/ C" z
/*任务:通过此系统可以实现如下功能:6 o' b& `1 ?4 K( T3 u) b5 |% U
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
3 s: O) c3 Q: b$ l R查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);, C' Y. k- r+ S% y, s; D% L
可以输入起飞抵达城市,查询飞机航班情况;$ e- d: w7 {: T$ @% `# |
订票:(订票情况可以存在一个数据文件中,结构自己设定)
2 E* w h% @6 |* d" {& g可以订票,如果该航班已经无票,可以提供相关可选择航班;
' v- }- ^' D: S! t. ^退票:可退票,退票后修改相关数据文件;
8 f5 @, k' c) A. c4 l* X客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
3 x3 e3 ]9 x4 d1 k& U# V修改航班信息:当航班信息改变可以修改航班数据文件
: _1 W! e- b' ]3 B5 O- s, o要求:
' v+ ? p2 e" Q9 C/ `# I根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|