|
#include<stdio.h> u) P% f$ E" s- {
#include<stdlib.h>
6 p, X* O; P+ _. r' P& L#include<string.h>
5 B" N1 C0 D& g: W9 ^0 }* C4 v#include<conio.h>
9 s7 ~# U' j2 S& k#define OK 1
5 \3 l; h8 g8 A; m8 G& ]#define ERROR 03 O0 l% u7 n! u* [( O4 f: K( D3 O
typedef struct airline{- ~/ @: M- a' V2 X5 l. t& M# M
char air_num[8];5 u, ? K; b% E) u. _) \) Y( S
char plane_num[8];
/ E8 E: C& t# y: ?" j3 e7 u char end_place[20];' m6 x! f. j* I
int total;
; `6 N, u! f N: V3 H% @ int left;6 _) K n6 e4 ?6 ~( L/ V1 E
struct airline *next;. Q9 \: _: O/ S
}airline;
! B, g( i1 a7 U: ?% P" Vtypedef struct customer{6 x+ u) W3 _% v4 i: H" \
char name[8];2 R& {/ v5 t- K' l! u
char air_num[8];
! ~5 U. c. T, y int seat_num;
4 ]2 ~" k( C Z2 i* c struct customer *next;
% V+ N! x+ o8 d0 t2 k" ^}customer;
$ {0 y/ Z% N& Q; n U/ X Sairline *start_air()5 `; R9 j: f ?$ { _
{5 K' b7 u/ X# c$ \1 i/ b' f
airline *a;$ }( `% W2 O% o4 l
a=(airline*)malloc(sizeof(airline));
9 r% a# E) M- k8 S' @4 a if(a==NULL)
5 {0 v4 T+ o9 M7 L( ] a->next=NULL;
. _: w* W d! _1 M: F. x1 g& e6 g return a;
6 w7 ]* V8 D/ t: n: a4 ]# q0 }}
# y1 N* r2 E' s) I( {customer *start_cus()0 \& L, |* Y/ n4 Z$ i# S
{
q6 u: t& }7 t customer *c;
: A) t( H1 ~7 t3 H2 _/ o2 z c=(customer*)malloc(sizeof(customer));3 j0 ?/ ^' H% N' @" Q. }$ q
if(c==NULL): v/ u: M- h$ Y# K/ U" p' f, i) ]# c0 U' m5 Q
c->next=NULL;
% }) O2 _& L! W/ o/ q' Y6 Q& M return c;
h3 S1 U6 ~2 f ]$ V6 E' t" r}
/ y% J) G* g7 E2 t6 Mairline *modefy_airline(airline *l,char *air_num)! y# e. H' z' n3 V1 Q" d
{( [0 U- Z) J% P3 B
airline *p;
. F! z! p2 y+ G; {* O7 W2 g+ W J- Q" T p=l->next;
8 X5 N J2 _4 G" P# @+ p B6 i for(;p!=NULL;p=p->next)/ R' g( ~; J& h$ q+ _
{; m v8 }1 ^& S; u+ A0 v
if(strcmp(air_num,p->air_num)==0)
A5 s+ `2 c% x' L- L {5 F8 Y8 w7 ~( Q: J& u, Y/ G( n
p->left++;9 Q: `# a5 \0 ^3 G! I
return l;+ H9 w# V4 y% a& K9 [1 C
}
" m4 e7 I" e5 u4 W3 \' w printf("NO the airline!");! V- v/ j7 l# H$ z' T* {
return 0;0 k e; k. n) N9 h2 N* n
}2 J( n: u* u* l6 v8 [$ J# H' }3 j
}1 Z, q' t! o; t4 D& o% R
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)5 C1 r9 Q ^4 w+ |5 _
{) b, p5 W& g# t# v
airline *q;
' q1 y6 l; y, U" F+ Z- I q=(airline*)malloc(sizeof(airline));' R# Y9 m. z- } @
strcpy(q->air_num,air_num);# v3 H3 t v& e, f& T" @
strcpy(q->plane_num,plane_num);
" F% |$ B4 t( w5 v$ E3 m5 _ strcpy(q->end_place,end_place);
3 B# w2 |6 d) I9 @8 X9 S+ q q->total=total;
1 U" Q% b; E ?2 n5 k. | q->left=left; R, u5 L. @1 ?' O5 W, i
q->next=NULL;, ?# C4 ^- J! K* [5 D9 K
(*p)->next=q;. a9 A* w& j5 }+ e* m" W6 M
(*p)=(*p)->next;
6 X1 y: h# ^! C' Q# b, [ return OK;- F* J" E( ~8 @0 c2 m$ | m5 }
}9 y( s6 D9 e( @( T: f
int insert_cus(customer **p,char *name,char *air_num,int seat_num)5 ~* U7 G% z3 v- W v( E G4 z1 b, z4 p
{8 K4 F0 @/ f8 X. X2 P
customer *q;- D! `8 L- T) V) d U0 k- g2 ~1 S2 d
q=(customer*)malloc(sizeof(customer));9 l; m ^: s9 R! j# ^$ n& I. p
strcpy(q->name,name);
' O2 m3 r3 }( C' G0 V# i, V strcpy(q->air_num,air_num);. c2 Z" I7 h9 x4 s
q->seat_num=seat_num;& O; a! j5 R5 w5 i
q->next=NULL;. T# N* s; \9 H @1 M+ O( ~; O
(*p)->next=q;
1 f3 `3 z2 L4 h) s (*p)=(*p)->next;1 s3 r! r$ @0 m( A3 l% `5 z
return OK;2 H, T4 J- P+ L0 m
}
. R/ l4 ?0 P9 t; Wint book(airline *a,char *air_num,customer *c,char *name)
. q7 B+ @/ n; P+ N- I" D/ f9 K{
' C d4 N$ ?0 n' j/ O. s r$ i$ v airline *p=a;9 v5 P# s% m2 n; I
customer *q=c->next;
( w+ @, i' e/ m p=a->next;* ^4 q/ C/ q F& @ e" Y9 R
for(;q->next!=NULL;q=q->next){}: ]( O; _7 O7 w' q" d" B q% q
for(;p->next!=NULL;p=p->next)$ V, U# C. D- i, p1 S1 `
{
) b0 J8 y( T" d+ V: a1 { if(p->left>0)
: u [' v: ?* X" i; w& P" j {
7 S+ P' D: P' Z! ]4 j' c6 y printf("Your seat number is %d",(p->total-p->left+1));/ ~& d4 u( z$ l$ k) b; T K
insert_cus(&q,name,air_num,p->total-p->left+1);# `7 G0 S, y7 i$ X) ]6 z
p->left--;
' [; F, }0 n% W7 x" g2 y return OK;
. P8 e$ U6 z& u1 w# h& p }0 b9 X- J8 W. D+ V4 c
else
) r: m2 Y% R- m( t( p" F, ] {
1 W0 e* A( C7 ]! H* _, T" c printf("seat is full");5 ]/ h5 {9 S% B
return 0;
% g/ ]* Z% Q- q$ p3 l! N) P. Y) E }
7 D$ W' F* `2 S& } }- Z* V5 f- X% I. J0 x( a% J6 Q/ \: S; ?
return OK;
: g- {+ e3 H% `: B9 Q$ K}
6 W9 @- [& v& ?: B" U! Gint del_cus(customer *c,airline *l,char *name)
' V: C# s3 i, @( v{3 S& d% B$ e% W/ P* U6 T
customer *p,*pr;, S* p. U2 I9 ~
char air_num[8];# M5 F6 m' s- h ~+ V# |) F4 \ A
pr=c;
( X+ L I/ S: S9 D p=pr->next;
0 B. }+ t; i# d! _" @0 q& v4 u while(p!=NULL), F4 a7 J4 m& W& L. L' z
{8 M8 ?* ~+ m( z+ i2 O: y
if(strcmp(p->name,name)==0)
0 i* l& r$ A1 r* p& t {
; ~9 i P! g) @, N3 ?9 ~ strcpy(air_num,p->air_num);4 b; z7 @2 B0 L" }# g
l=modefy_airline(l,air_num);7 F6 J, _& T- C! b! ~4 F
pr->next=p->next; E2 P% M l: }& v( z" Y" M9 |+ O
p=pr->next;/ L/ l5 H, Z1 W+ k# b' z) ~, l: G
printf("finish!");
- c9 p4 ~. Q) f7 g j" | return OK;
( u$ u. y/ l$ D) t# O/ S0 p5 G }
4 }& @1 l/ M( W4 d' a pr=pr->next;% s7 x( H8 E' v/ x6 S% A6 w3 x
p=pr->next;5 c7 b# K$ V( [: \7 [4 Y
}
1 e$ g* f# t; F2 h- a9 p5 Q; q printf("NO the customer!");
3 Z5 ]7 t& U) v( T0 X return ERROR;
& z h; x7 H* J& K+ y: ?}: I& |; g* o" ?% A5 X" K% w% [' n/ ?
int search_air(airline *head)1 [2 M7 u! U4 l& d1 W
{
! j; m2 U! V4 c( P& q7 ? airline *p=head->next;" e% F7 w' m1 L5 \: @0 W2 j
printf("air_num plane_num end_place total left\n");
5 e$ b- h3 r4 G1 ] for(;p!=NULL;p=p->next)9 e4 M7 W1 d: t6 Y) _
{! ~9 o& {# R/ r2 Z! T+ C! |% y
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);: {* W( Y5 D0 K2 d1 a ~' R& `2 W
}
; r, |; y: }7 c! Q return OK;8 r- _) c/ i6 g( C# U! t
}7 H; R' C# m* U4 M- y5 c1 f O
int search_cus(customer *head)) N9 ^# E! g+ M* F/ B
{. X( j. b) z- ?- @0 d
struct customer *q=head->next;
. ?+ M/ _1 Y! T, | printf("name air_num seat_num\n");
9 E3 ?( h4 i7 L2 H( U; H8 T# X for(;q!=NULL;q=q->next)4 j0 U1 A$ u: j2 v8 m
{
# R9 n( x3 B( S5 l* W. l printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
1 B/ D+ |% Y3 D1 N) g8 o: r( c4 } }9 w/ p) b) @* \
return OK;
3 C+ C- x" r5 L& }7 S* s* @" {( P}
% E+ N/ r4 g& _$ Aint creat_air(airline **l)0 o$ |. d. o+ |0 i. o1 Y" f k
{
. j4 Y, A. n) M$ I+ Y0 P airline *p=*l;# Q( U, a& v4 Y- V ]
int i=0;, D9 X! X# `& [
char *air_num[3]={"007af","008af","009af"};5 H; S/ s+ |- g- s
char *plane_num[3]={"plane1","plane2","plane3"};
; ~: {& `0 c; J1 v8 ? char *end_place[3]={"Beijing","Shanghai","Tianjin"};
1 r: i8 T" u4 @1 t- n" j, g. x- f int total[3]={100,100,100};
1 s& B3 Y0 U7 F/ r! N ~7 H int left[3]={52,54,76};
, C; G/ W0 P; [5 ]: P. w: o for(i=0;i<3;i++)
9 X; W) {/ l5 K% Z4 K insert_air(&p,air_num,plane_num,end_place,total,left);( u. R$ g, H8 l
return OK;
! Q. u1 J6 U1 I}$ ^* P8 X2 o: `% }
int creat_cus(customer **l)6 [. j, n, ?9 X5 C, U4 c- k& o& G
{
* C/ a# r) Q+ f R' C$ m customer *p=*l; s$ x B+ i4 e, Q
int i=0;" i2 J' m% r8 Z5 f8 d
char *name[3]={"zhsan","lisi","wangwu"};& l7 a# C$ C3 T
char *air_num[3]={"007af","008af","009af"};
9 ]8 J8 _- K7 z& Y* d8 b/ ? int seat_num[3]={2,5,7};
4 ]6 F$ ?: M" W! l for(i=0;i<3;i++)! z9 k$ t/ M. b1 d/ F+ d* Q
insert_cus(&p,name,air_num,seat_num);: I0 _- X m9 \! `! q' n
return OK;, D( R. Y2 y$ @+ |
}* Y4 {1 S9 s8 L) G, S
void main()4 B# k# X1 A4 F: j* }. u5 q( W
{ r! E" e" |1 |% u. G) O5 O1 l* R
int t=1;0 `4 Q( d3 K+ x* f* u
customer *cus=start_cus();- }. L. L- g# m/ h
airline *air=start_air();! D. Z$ g! _+ W5 f1 ~/ Y
char name[8],air_num[8],ch;
' }) l: U: i9 f" ?: ? creat_air(&air);
+ b5 M3 z' a- I. w creat_cus(&cus);. i( q6 f& j* x* \8 F0 a4 x
while(t==1)
$ S& r) }9 b( Z( v2 b {
) V6 K7 ]0 H! N9 S& f' U printf("\n");
/ f/ G; B, @( [& d3 P8 ~ printf("*********************************\n");
M- g7 v5 h0 _3 j J printf("* Welcome to air firm! *\n");
8 f$ D' v, p7 e4 {0 v( c printf("* book--------1 *\n");, }9 T1 j. ]& w
printf("* cancel------2 *\n");
& |1 | k# k; Z! X4 }5 `) s printf("* search------3 *\n");9 K2 J) T7 ^3 J3 T- B3 _ D
printf("* exit--------4 *\n");
t% @: H: D* K9 W7 z printf("*********************************\n");
8 o4 Q, W6 d: Y8 K# X) _) d5 v ch=getch();
% n* |/ J/ T" u) M if(ch=='1')
: W9 Y& O* S+ G6 V1 @( u {* V& d* M; W) |( u5 U
printf("Please input a airline number:");
' d3 x& e# e# w( G E* n0 e- U scanf("%s",air_num);
& B4 r9 M% W6 B, [* _ printf("Please input a name:");
: I1 Q2 P" S8 z3 c' Y5 d scanf("%s",name);7 N' R/ x: d4 h! ?: W7 R0 U
book(air,air_num,cus,name);
3 C$ e7 A, y. w" T# h7 l }
# B! I7 t$ n4 T else
i; o8 I5 b5 t& x9 a7 j% h if(ch=='2')" N1 K4 t* W" m: Y& k: J8 [5 ^* Y
{9 h! z# A, k9 C2 S* A% O
printf("Please input the cancel name:");7 d% E" z V; T+ L
scanf("%s",name);
H' l ]7 U6 U% l; h. V) c del_cus(cus,air,name);; O `9 I+ ^/ I6 j- ]8 k
}
' {" `. e# j! ?- l4 g else" t1 Q% |3 A& t2 D7 k
if(ch=='3')+ I- O5 F( g( A2 a
{
8 r% K8 `; {1 ? search_air(air);0 o) B4 j/ Y9 s9 Q
printf("\n"); 8 f6 m3 L# l& J6 d/ c D
search_cus(cus);1 F: w8 y# y9 E" [6 k
}
9 w! F# P( R; }5 U$ H7 p7 K) q9 d else
) g2 [5 P, W) d. H* a- t9 m F if(ch=='4')6 j ]+ M& a( z
{3 f6 \$ J9 \1 a) t; p6 K
t=0;' z$ s! Z0 H3 y3 S. d* B; h, _
}
; N9 r% D; {2 n }* p/ P$ G0 J& _8 S1 Z" y+ @
}
# A/ ~5 M1 j& A% W1 I( x/*任务:通过此系统可以实现如下功能:4 k( a& _5 p! v$ s, H
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
/ F+ y: D* b- p: H+ o( ~查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
}; ?: A; M2 c" p9 c$ c可以输入起飞抵达城市,查询飞机航班情况;! [6 s8 C* R2 {9 K1 a
订票:(订票情况可以存在一个数据文件中,结构自己设定)
6 D2 P' P& ~3 q% J3 [$ S6 t3 w+ \8 N可以订票,如果该航班已经无票,可以提供相关可选择航班;
3 a- e0 r* I2 i U1 C3 [; y- @6 s退票:可退票,退票后修改相关数据文件;- ~% E7 x) W, e0 F j& p, T# A
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。, ~5 F$ ]- R3 t6 O6 g/ U
修改航班信息:当航班信息改变可以修改航班数据文件8 [- h) N. t% t
要求:! @0 I4 N- A' F# b
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|