该用户从未签到
|
#include<stdio.h>
+ J6 ?9 }( e, a1 V k% G#include<stdlib.h>( R1 n- Y3 \' m1 l
#include<string.h>0 K% m+ l+ A' y2 l/ E. ?5 ^, t( R
#include<conio.h>
: _, ` O" f1 I) d( b' I" D3 S#define OK 1
8 E; I% D$ ?9 M q3 `6 e#define ERROR 0
/ T/ H8 A% R& E' j3 ~4 Ktypedef struct airline{
+ c# Y+ I% b7 x! K9 t char air_num[8];7 b1 n; V8 F, E% S7 r1 B
char plane_num[8];5 y8 D A* s- p2 i2 T# T( x/ J
char end_place[20];
8 E. w9 r1 b8 Z# p3 L int total;
8 P, y/ H( d0 L) D/ s% b9 @# \: a int left;
: W5 W$ m; E3 Q& I struct airline *next;5 m. m" o& W4 R6 m! C6 K. U
}airline; K- F( j8 H3 e
typedef struct customer{
$ \+ w/ y/ F8 x" c char name[8];! ~0 G# e$ f; _* H# { _ f( D
char air_num[8];
1 V/ g8 b$ Z2 K* A* r# ~- P int seat_num;1 M& [! N; n7 @5 i. J
struct customer *next;3 j1 |& K* O) S$ P
}customer;
X: N+ G; b# e$ Kairline *start_air()' {; t/ a* _3 m9 [/ M
{
( U- d% j6 W5 _ airline *a;
r1 y9 ?6 d# Q i: P a=(airline*)malloc(sizeof(airline));
( Y7 S9 v( I3 i" j+ p4 J if(a==NULL) ?2 a1 _& q* v
a->next=NULL;
$ U3 C& j& o" M5 F# W- w# z return a;
' V7 P" n; R2 n, K# S}/ J5 h, Z/ @& J$ d- E
customer *start_cus()
( T- n' e0 a- S0 u/ K( n{
! t6 J( @6 |$ q# @ g customer *c;
: }5 H5 c) j1 t2 w3 x+ M: S c=(customer*)malloc(sizeof(customer));
- }* b- W( q* Z+ y) G9 M2 r. t( z if(c==NULL)& u* N) b, w; M
c->next=NULL;
$ _- M5 z' t) D$ I- ^' H return c;
" u5 K+ R+ {! J+ u) m4 U, i}
9 h: t' n6 v. E" n, B: U4 zairline *modefy_airline(airline *l,char *air_num)
: M: k9 e) q, V: j6 r{0 _# @4 z+ g: O4 {
airline *p;+ Q* D5 l; P( W: b. \9 M& A& `5 w
p=l->next;2 Q/ q6 k3 Q, X: T8 F1 ~% g0 Z
for(;p!=NULL;p=p->next)
1 |* c6 {4 d( o% c9 ^5 ~ {' _, N2 l. H9 K( [
if(strcmp(air_num,p->air_num)==0). t2 L. f. F/ G; E
{
# ]2 S6 X. [' U' t7 P- K p->left++;
0 [3 M/ L; w# F0 K/ C return l;# c! L+ G2 u% V1 }4 c; i1 O$ a
}
! o7 E" h! w3 \5 H( D, | ~ printf("NO the airline!");7 \1 S2 \# m" F
return 0;
k8 e4 f: W1 u1 T" _ X }
1 x& N: E2 D/ G K5 R}0 n: Y+ `5 u+ _! S/ B
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)2 f9 u0 _/ L8 ?/ q/ ?( r
{3 V, t5 m3 r% O2 b1 P
airline *q;! s: `8 H+ O, P& V/ b$ Q. _; t& o
q=(airline*)malloc(sizeof(airline));1 f0 \4 C' _: ?" X$ |2 s# K
strcpy(q->air_num,air_num);
$ u& i6 P2 s6 ?0 f6 { strcpy(q->plane_num,plane_num);
7 ~; Y' f- s6 G+ X) h2 k strcpy(q->end_place,end_place);( d, w/ u) e8 h* g# F0 ]# y
q->total=total;% c, q# P4 _- Y1 p
q->left=left;5 }( i% d7 V! x& G
q->next=NULL;1 O1 m" B3 I% C" o% R1 K
(*p)->next=q;" P8 S* _' q+ Z1 K/ j' f j
(*p)=(*p)->next;
3 l/ ^* Z: }7 O& { return OK;+ r' m% a& Z) v- B8 u0 c. @5 E; {! u$ v
}
2 K" j; f% q' k& bint insert_cus(customer **p,char *name,char *air_num,int seat_num)/ I% j& O% @' f; k P% p( J
{4 |' ?$ o) H; c3 ]# X( b. e% B' b
customer *q;
; ^; a. G3 P; J( r* ^% S/ `9 ` q=(customer*)malloc(sizeof(customer));
. r. Q' L, _7 h1 W strcpy(q->name,name);
3 z' B) M4 E, H @' Y7 S, | strcpy(q->air_num,air_num);
6 B* c2 ^0 T7 I q->seat_num=seat_num;
, F0 h# L# u9 g( q q->next=NULL;- }, p5 O- L) O! r1 Y2 `
(*p)->next=q;$ ~9 h) L Z* o: Z4 c
(*p)=(*p)->next;
, |0 n2 [: n6 h return OK;& w" }4 Z; L2 t; B$ K
}1 Z; ?+ R0 q% ^7 D
int book(airline *a,char *air_num,customer *c,char *name); _9 N: u; @7 E. Y7 G7 W% N
{, t% }6 H1 ?5 o) c% E
airline *p=a;7 _: Z) L8 w4 y- P
customer *q=c->next;
0 f5 |. Z5 y; ^0 F+ g9 g p=a->next;0 w: @2 ~+ q$ t$ d* u, Z3 z
for(;q->next!=NULL;q=q->next){}
" V0 ?) z! E( x3 }/ O) E! n) G for(;p->next!=NULL;p=p->next)% _+ @( J4 \ }/ w
{( A S- G. b- g$ |& S! R
if(p->left>0)
\# V% M. G% p/ l- V t {
3 Z8 Q! t7 K- O' k printf("Your seat number is %d",(p->total-p->left+1));( p9 _! B4 t+ g) q" p5 C+ }% |
insert_cus(&q,name,air_num,p->total-p->left+1);) t ^: X% @+ O l7 b! A7 O
p->left--;( [9 j. Z0 A9 U# t( |7 J) }" r
return OK;
& |1 ~; d1 `, @2 f3 y }
" Z1 a+ ^8 m. f else8 H) ^& D$ x% C/ [6 c" E/ [
{6 s+ t X# ~2 X' Y
printf("seat is full");
. ?. x0 C2 _/ D' ^/ S" m) p return 0;/ o) c D% V& [7 j7 h% R' v
}
# g' \& D$ d. y. p/ [ }
0 Z0 M P4 x9 d0 a- b$ jreturn OK;
$ r8 w8 M' H0 Y) J( i9 N/ [}& k K Z$ r; D
int del_cus(customer *c,airline *l,char *name). ^( ?% e( v: C! j
{
& y& r- B* c8 ` customer *p,*pr;
- a( b6 x$ D( a9 Q$ y5 \; K" w char air_num[8];
# `9 x9 V! b0 h( Q8 K pr=c;* p/ I: P5 i6 K8 Q% @! O2 A$ y
p=pr->next;3 D' T8 n; j' G0 r. j, M3 L. C
while(p!=NULL)/ Q( F" d. T- J# ]
{. Y' O% i/ k& u: I) g+ L( i8 e
if(strcmp(p->name,name)==0)
! v; _( z1 N/ G: ^$ R" q0 Q/ | {+ \. Z; ?( ~! C6 j7 p* }
strcpy(air_num,p->air_num);
% [% E0 O. c1 W; v5 V( D l=modefy_airline(l,air_num);5 J S& S9 x2 G7 J3 `! O: ]4 s0 |
pr->next=p->next; G7 o4 s# q; d7 A, K4 \
p=pr->next;; D* \3 X- n0 P( h' w) B4 A
printf("finish!");
: @: u: z3 X/ E: Z2 S return OK;
9 y+ O$ I( u. o4 U$ R; {! \ }
& F1 @3 L3 @, ~& M1 j( j7 H pr=pr->next;+ P5 w: ]. [+ H n& G; U' V! w
p=pr->next; l0 o- b2 b' U
}1 V$ j- L f& h; l3 j
printf("NO the customer!");
. T' g: l" @. A7 K return ERROR;% Z# d% Q* l* H1 c- O
}
; \1 O* B* c- h6 }1 Tint search_air(airline *head)5 N5 p3 O6 \- J6 m' o7 L S
{
) z2 h8 T$ o7 q2 o airline *p=head->next;
. S5 X3 f4 G% E. i/ {2 D printf("air_num plane_num end_place total left\n");% \+ U: C9 Y8 l% |3 l
for(;p!=NULL;p=p->next)1 g, ^' O8 b6 s. l6 F5 F j
{: X7 N6 |" b* {, j3 f
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
4 v1 Q; j3 \2 Q |( L+ s }
t2 P4 a! C. R4 }$ Z4 o. n0 N- ~ return OK;
3 Y$ @' y/ z" h9 y" s5 E}
; _1 E7 l. b7 S1 S) Bint search_cus(customer *head)# Y, j6 }: g, J9 ^) e
{; N+ D( f# C! o! i3 C
struct customer *q=head->next;
% X8 s' D, q6 o! \8 m% ?* U, n printf("name air_num seat_num\n");3 O. h8 B8 `# I3 b' \& Z! [
for(;q!=NULL;q=q->next) j6 L9 ~ `7 |! s0 Z0 e
{9 I8 N: a0 T' @+ \# I' i
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);* O, ]2 g# }) r& \
}
: ?0 \. |6 o1 `6 e return OK;
z/ K4 k2 E/ ]: ^- Y}
3 L4 y2 F/ o1 M5 \( h0 z/ Aint creat_air(airline **l), Y5 m- K8 A& p/ x5 |# k. b1 p9 _
{ ? l2 |/ S6 z1 }/ X" R3 Q0 X
airline *p=*l;% H7 X$ N) z5 u7 k
int i=0;
- }; |& Z2 Y! y7 V; y char *air_num[3]={"007af","008af","009af"};9 x' Q4 q+ [8 R# e
char *plane_num[3]={"plane1","plane2","plane3"};
& F; P& L7 N8 J& ?6 x& G% t4 F char *end_place[3]={"Beijing","Shanghai","Tianjin"};8 U2 _- L- g e& Z* {; o$ a3 S
int total[3]={100,100,100};
; d3 A4 l- ?7 v& Y; Z: `5 w9 | int left[3]={52,54,76};9 Z, L) n* S1 t) q3 i' n
for(i=0;i<3;i++)
8 _. h/ l$ }0 x4 I insert_air(&p,air_num,plane_num,end_place,total,left);6 {: k% R: s* p u6 P$ S& T& Z
return OK;
) S! e; E! z4 W# r3 K0 p1 ^}6 h. _4 T6 u9 ^4 Y8 g! A% Q
int creat_cus(customer **l)
) A2 g8 P, r8 I$ U/ X0 h) u* J{' x! ]9 o, C0 c* a6 t# L- d
customer *p=*l; J% z! r" U, J) g( K3 @
int i=0;6 }9 k- N2 k, L! \; T
char *name[3]={"zhsan","lisi","wangwu"};
! ^. C5 g2 N& A9 | char *air_num[3]={"007af","008af","009af"};
* A. z- U% D) V+ m9 h int seat_num[3]={2,5,7};# z8 G0 V, K2 X1 _8 A
for(i=0;i<3;i++)! ]& a9 X1 P4 S2 X) O
insert_cus(&p,name,air_num,seat_num);
5 U7 R$ `0 a3 }3 U: W: n& H n& O return OK; o: ]8 B2 W5 T' d& ^; M! T! @: ^7 O
}
/ U4 }3 d; T4 C' Yvoid main()
7 F d; A/ ]! E1 `# c* N4 @{9 F% @: H% X) f; | k2 Z
int t=1;9 X% F, b1 \: x. h, y
customer *cus=start_cus();
; x6 _( Y( G0 {: @* f0 w airline *air=start_air();7 V4 v9 r( O C9 C$ i
char name[8],air_num[8],ch;
# J- e0 c. g1 m' l& p8 g creat_air(&air);! Q9 V4 `, H2 g1 k& n& i
creat_cus(&cus);+ {1 y9 ~( J- t6 b) c. [! N& {
while(t==1)1 \! v( N/ \/ u# J7 L5 C3 W
{) Y! x7 \' F% ^+ C5 p. x
printf("\n");
0 _4 J4 r8 V7 ~3 }: l) q+ i3 V printf("*********************************\n");
2 o! a; {, K: q printf("* Welcome to air firm! *\n");/ o" c5 g0 d2 z b
printf("* book--------1 *\n");; I p& | }; ^! Z6 a
printf("* cancel------2 *\n");
c4 l. L) k1 @( _( _* f3 p printf("* search------3 *\n");* @4 H, f: H$ {
printf("* exit--------4 *\n");
" S7 C8 ^; o" y2 t: }8 E printf("*********************************\n");
0 r- e! g, B$ M8 i# M) J# v: W! C ch=getch();
$ V ^+ A9 I' \* W* O# O if(ch=='1')
$ ^/ @3 |' _( Y {
! p% ~8 O. ]# K+ [) L: { printf("Please input a airline number:");% z$ z" Q7 O' y4 J- j
scanf("%s",air_num);# K; Y2 L& j( q1 A3 h2 t) N$ ?, Z
printf("Please input a name:");1 x$ W2 S, v; j- p2 V/ d
scanf("%s",name);, @6 E* `$ e( w5 W
book(air,air_num,cus,name);/ K+ o, _6 G1 z' O( |
}
4 O6 S. o! n% x, m9 v else$ d. _0 u( L- V" h4 i
if(ch=='2')
6 f! S) ]" i3 i9 {* q {
4 h% X' b* I! t, N; I; y, b0 i printf("Please input the cancel name:");; k* F8 f! m( W& m$ E
scanf("%s",name);3 ]- X& s: a, `! `( B1 r
del_cus(cus,air,name);" e2 u! _3 {6 W# S
}
" J# j/ ~5 B8 D- S else
/ Y2 Q$ C# C: @* d. h if(ch=='3')
9 x, C, s! x p {/ x& r0 A. g' C: x( n0 L
search_air(air);
2 t, ~8 N! s+ l printf("\n"); ' s- }: W4 J8 e {! `! C% \. y" L
search_cus(cus);$ F9 t1 h4 c, F, z
}
% T4 o! H( G# ^) H7 |: M else' }! |. w1 k$ D8 p. \% i/ @
if(ch=='4')$ [3 ~! _2 _: m
{
, F# q2 E' B" W; H) x+ T) g: e% O t=0;
$ R) U3 t- K, b; y$ v }
. S# N Z9 i( k8 D }* _. i& v4 s( }' t5 y
}. P* ~. x( b0 F; D& Y: Q$ L9 g
/*任务:通过此系统可以实现如下功能:$ q3 H8 ]" I& z# i$ Q* i) o
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)% X# \! p7 [6 h/ p6 F! r
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);! T" _# j4 R$ G3 n; m2 {$ \9 ?; T) M' [
可以输入起飞抵达城市,查询飞机航班情况;0 z' T( s" y- B9 E4 M- N
订票:(订票情况可以存在一个数据文件中,结构自己设定)
. z( ?+ [! i( U( E( d' ^# a可以订票,如果该航班已经无票,可以提供相关可选择航班;1 J" y" X) l( ~4 q- x
退票:可退票,退票后修改相关数据文件;
y+ N7 W# g% c. [- ?1 X& D0 ^2 |( t客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
. |) F0 w5 X! u6 A5 }修改航班信息:当航班信息改变可以修改航班数据文件
$ A6 s' {- j+ a5 |, r0 O要求:
( D- u3 B% R ? u% K; p# Y3 Y- \1 }根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|