该用户从未签到
|
#include<stdio.h>
( Q+ o% [; R. B) ]( g4 {#include<stdlib.h>% p' `& q* ?$ S* b
#include<string.h>
8 k* L# w6 s& o% ]2 d0 }- T" e4 s Z#include<conio.h>
- H$ E1 R }$ n# N l/ C#define OK 16 b9 ^" P+ g2 T- F: Y
#define ERROR 02 x, M) o) c8 y) t4 W& U9 {% C
typedef struct airline{
/ ]; I( c& J1 b b! v3 R1 i- \9 M0 }; l char air_num[8];& S5 c# _ O3 s, X% _9 P
char plane_num[8];
# p8 P/ P2 H( D* J char end_place[20];* {+ P( R6 _" I9 q6 l% U" C
int total;& E2 F& w2 i @5 B, Z; G8 Q
int left;
/ D1 X G8 J) m% Q# A; D, E struct airline *next;1 g8 R2 {9 N: a
}airline;
( Y) w1 s1 |5 n3 j8 itypedef struct customer{' e$ T: G% D. R Y4 g
char name[8];( ] ^/ |' G7 p, I
char air_num[8];* b6 @0 u1 V7 t. H: T+ ]" L
int seat_num;
' F. q7 x z3 L7 O: x. F, O struct customer *next;
2 c( t: o2 B+ Y5 n& l' L. _% }" L6 B}customer;
9 q$ C9 J& k9 h, L/ P _/ ?airline *start_air()
8 ~; f5 K9 b5 ~8 {{
; g. c2 }$ X: G airline *a;
7 ]0 Y3 F4 W' g+ O0 @8 N2 T a=(airline*)malloc(sizeof(airline));) L2 Z# E. |2 n
if(a==NULL)2 L A7 E' S* ^) m' f
a->next=NULL;2 Q N) |/ [' E" I/ c
return a;! a$ k3 [& H2 d* Z4 x6 ?, ]* \3 r
}$ P2 \" b% `6 k& A( E
customer *start_cus()
; t: ^- u; G3 ^) }{
9 r# @4 o+ T3 ?6 P9 w; i3 ^ customer *c;
" W- F! \! u9 m1 O% B7 U. @. F c=(customer*)malloc(sizeof(customer));4 j. C: m& t; Y8 z2 n
if(c==NULL)! D7 _5 r$ ?5 S# o9 O6 `% |
c->next=NULL;
+ A2 E# y/ w# e5 @$ ? return c;
U8 C! I& P7 r* m}5 f0 x* M" _; `0 X
airline *modefy_airline(airline *l,char *air_num)
& g/ g; c& a: e" _( @/ J% \( N{
+ q. U4 c' ^0 q- k( ^, ~ airline *p;
% {) E$ r' }2 t p=l->next;* N2 P2 ?& k5 b" ?4 H$ N% H( n
for(;p!=NULL;p=p->next)5 S1 n m" r/ F. U/ z$ e
{
5 \& \3 A8 m0 m if(strcmp(air_num,p->air_num)==0)
$ X. k# Q$ v, Y. Y {
5 X* X; a, F3 h# n, J- ` p->left++;' }: ]- f$ F+ m6 p1 _: _
return l;; f1 r! U. f' R4 I
}
* m. U* `' V8 T8 [/ y; T printf("NO the airline!");
1 G7 ^3 ]7 `* E% x return 0;: k8 ~0 R7 K% e
}9 x5 w+ i, q! f" u* j
}
# L* B I" Z- @4 A g! z. Q% [9 Lint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)8 d5 C5 i3 X" |" e+ {' [' ^
{3 {& V6 w* a' y+ Q% o* f* ]# r
airline *q;* E2 L3 p+ l6 j
q=(airline*)malloc(sizeof(airline)); c( u8 A7 o* _9 l* t
strcpy(q->air_num,air_num);2 j# X& D2 G& a# l* e
strcpy(q->plane_num,plane_num);
6 v' q& Q) J7 U0 C strcpy(q->end_place,end_place);. b- }% i9 Y! h. F7 b2 ?
q->total=total;# l' r. n4 ]3 l2 x
q->left=left;9 K& V1 O+ e* K- o
q->next=NULL;
/ j, O+ y, H# O: `( L$ t( [. a$ r (*p)->next=q;9 G0 f/ o- z* \- I5 [
(*p)=(*p)->next;
$ ]0 b' `2 s; x0 U' y return OK;3 ?- y1 R6 C/ x+ l1 Q
}! t- u8 Y O2 `$ D/ f6 ]+ x1 h. a
int insert_cus(customer **p,char *name,char *air_num,int seat_num)! X$ Q e: e& f( W4 k$ v* w7 U
{8 i1 S& O- a3 a5 `3 J
customer *q;6 p6 S( e( V% L7 y3 Y' W$ }" ?
q=(customer*)malloc(sizeof(customer));
5 o$ |3 z. Y5 T9 p* K! P, I strcpy(q->name,name);
& f2 W2 _% Z! i, x strcpy(q->air_num,air_num);# R2 R0 }1 F4 L8 J$ g) V
q->seat_num=seat_num;" E- v7 K e" J
q->next=NULL;
$ K' {' G D0 u9 j( z' Q (*p)->next=q;( Z, [% T `1 U" a7 }' I
(*p)=(*p)->next;5 x' b0 c; C6 I8 K0 c* |3 i0 P6 l# I2 E
return OK;; i0 X3 J. \' ?5 K0 h3 W
}
* b/ j, \: n) q' y4 W5 h4 zint book(airline *a,char *air_num,customer *c,char *name)7 u8 }( J8 j0 d2 I
{) N- l7 K, n. z* q# |; T
airline *p=a;1 G# W+ L5 @% v
customer *q=c->next;. D" B4 k# c' ~
p=a->next;
b! y& d3 X) K; Z) d6 c for(;q->next!=NULL;q=q->next){}# ^0 \. D8 [9 k
for(;p->next!=NULL;p=p->next)
6 P2 B$ x& S) A( n6 {* A5 @& f7 d {! c( j- M3 B6 a3 L0 A \' C. B- @
if(p->left>0)+ u+ m& h8 u+ y" v; ], m6 {
{/ ?8 k; [/ C+ F
printf("Your seat number is %d",(p->total-p->left+1));
; H2 }# W/ @5 c6 F6 h5 Y, ? insert_cus(&q,name,air_num,p->total-p->left+1);* g; ^/ [: C" m6 p" R
p->left--;4 J/ k$ A5 C" l
return OK;
- j5 g) Q. v% ~ }; s2 [# G C2 {, t1 }! g# s0 a
else
* h+ R( @! Y; ~6 i8 E7 x" o4 |: E {
% V; y8 b# l1 N) m: t- C: ?: D printf("seat is full");% a6 P8 h0 ]$ ]0 P
return 0;
9 q; K% q- D" m% M }
8 @' _7 ^/ d* l3 u" }) g( x4 | }. k& [1 F/ T; L2 J* t
return OK;' D& s* Q+ x, N
}
. J; U6 n6 \: l3 L) Xint del_cus(customer *c,airline *l,char *name) b, Z% w/ n# g# e3 F U
{
$ ~( s6 c, e7 o$ a7 g$ [ customer *p,*pr;
& O9 M! m* ~+ G$ T/ ^& U; |$ z char air_num[8];5 T) i$ p+ L" y" Q* H
pr=c;0 Q9 |4 ~3 F1 T' k
p=pr->next;
( C1 u1 S4 I' U4 H' R while(p!=NULL)
7 O8 D9 t3 s8 W {
+ x" J# `" L, {3 ?1 t5 o if(strcmp(p->name,name)==0)
: O$ z' B/ {- _2 g: l6 o" h. W" B9 B! \ {* h9 E9 n' ]1 e {4 }; A
strcpy(air_num,p->air_num);
7 E3 j$ E( R4 W$ u, o l=modefy_airline(l,air_num);% R# B1 I$ N4 E1 g
pr->next=p->next; @- h* |6 n. y% f
p=pr->next;
, s$ G2 x# u1 p( Y' _ printf("finish!");) J' [; {( o' O/ f
return OK;
" r) Q8 {% a* E }
: ^8 g: Q, j# k! Y pr=pr->next;/ `8 e* }% Z' s$ l/ b
p=pr->next;
I, |$ {7 }0 T& Q }. ~$ S. b q/ D
printf("NO the customer!");2 D) p4 ~8 @( c" B0 U b
return ERROR;
e9 B4 u' x/ c+ o0 M. f}3 c9 \: r/ @1 k* D0 K( D& ~" a* c
int search_air(airline *head)
! S3 }$ C! j8 Y3 X! ^{- Z& m8 s- \8 [+ M% ~& S5 h
airline *p=head->next;" {+ Q4 e; u2 K% b7 ?; m. h
printf("air_num plane_num end_place total left\n");; t$ R6 U% Y( f# c
for(;p!=NULL;p=p->next)
3 \* V* e# n4 D2 r( y& y. M {
3 f- I2 T- V7 ~# w9 p printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);3 m# t% u8 v; {& v6 E8 l2 G
}5 T$ |3 ^: i$ }( p3 Y
return OK;
5 H' X' C2 K2 X% u9 N}3 z. [4 ?- I" H+ e0 J1 a
int search_cus(customer *head)* d1 ^+ N/ n5 j# e5 ^
{1 ~4 k3 |! \& ]$ |" W
struct customer *q=head->next;* A% }% J2 l$ R! D/ z2 {8 p! L
printf("name air_num seat_num\n");
" P( ^ d$ I9 k; c9 X for(;q!=NULL;q=q->next)8 _6 N" n& s* h+ M& y4 z$ W
{' i) I+ j. l( {- U; g
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);3 v8 F$ q5 ? [
}
! e' Z6 {) q- V return OK;
# G4 \+ P4 C! v* R1 G. Q}
) S% Z/ f/ V' Uint creat_air(airline **l)
4 k! H" b. Z/ ]9 `. O0 I! s{( _% _- X8 l" B( q8 S; R# r
airline *p=*l;
0 x2 X, C: E! ?9 r w4 g$ o; ^ int i=0;6 C: s3 M* z8 s
char *air_num[3]={"007af","008af","009af"};
: } n+ y" n6 Q$ u$ i0 U char *plane_num[3]={"plane1","plane2","plane3"};# J+ C: G3 Q$ n' q, f( b4 S
char *end_place[3]={"Beijing","Shanghai","Tianjin"};
* o N4 d8 G1 b/ g, U6 w int total[3]={100,100,100};
1 o: u7 O4 N- e- W3 \$ c+ Y int left[3]={52,54,76};0 v; p1 e" Z5 C, B
for(i=0;i<3;i++)$ A! W H! T4 T! p: Y: B
insert_air(&p,air_num,plane_num,end_place,total,left);
' x3 D$ g! @: P0 b; o return OK;
]7 s0 W" S* v; @3 ^: [}8 R3 _) |- j/ P% K3 Q& D
int creat_cus(customer **l)
3 Q& V* u' f* i* ]{
$ P% K7 R6 X6 n0 A* z( C customer *p=*l;
; k: ^+ x a) H, [& Z; Z" N& Y8 L int i=0;
& ^) {' D2 x& @ char *name[3]={"zhsan","lisi","wangwu"};
( K# C8 }" H$ `. b0 I char *air_num[3]={"007af","008af","009af"};
; i. H% A1 O6 T& _8 r8 `; g int seat_num[3]={2,5,7};* V1 [( J( I6 u& h" X4 E' `
for(i=0;i<3;i++)
1 |2 p2 n8 G) ~/ z$ \% b5 ~0 i insert_cus(&p,name,air_num,seat_num);
) y% S7 H& k( d return OK;8 \. K& q: i5 e4 }+ S
}5 T9 t: Y0 v" |( ?. H6 y$ S8 F& ^
void main()
4 E# m8 I- i/ M3 b{
, q2 S" R& L* M int t=1;
! \% R4 _3 `0 o3 J. m customer *cus=start_cus();
; A- k- f0 \$ ~ airline *air=start_air();
; G/ E* P; @ {3 K char name[8],air_num[8],ch;, \- T a3 I r. \7 t
creat_air(&air);* u1 I' ]7 Y3 b- v$ e( ?
creat_cus(&cus);
4 B6 t% D$ ~/ D$ y5 w while(t==1)0 [: Y1 G, Z, h7 t6 s
{) i& d+ A2 f4 o& r: }5 y* n
printf("\n");
' m/ @+ p% j* }3 a& r% Z printf("*********************************\n");5 ]: t* F0 `- k! Q8 f2 ~2 e
printf("* Welcome to air firm! *\n");/ T: `- R8 P' k8 O& ]2 F6 H! G
printf("* book--------1 *\n");4 _* r8 l* H' v1 }; |
printf("* cancel------2 *\n");5 ]5 m6 u% w# z
printf("* search------3 *\n");
6 `' x6 G8 Z/ L* _& ^( o$ @ printf("* exit--------4 *\n");
; q1 \3 }. }( l0 L8 U( @# ^3 w printf("*********************************\n");+ U& J2 `5 R Y, |1 V
ch=getch();7 G( e: Z2 O* z! {( y8 X
if(ch=='1')+ f- y2 G- |* d
{
/ p/ C* T( C0 B+ m( R: p! E- F printf("Please input a airline number:");
0 ?# Y* J- x* E. B scanf("%s",air_num);
2 w3 o; t* C) t9 U printf("Please input a name:");$ h, M, `; u2 T8 Q$ `# `8 S
scanf("%s",name);8 h U& A9 s$ D% v7 \+ H
book(air,air_num,cus,name);
: Z- x+ P8 r% T4 K9 P# X# G }8 ]4 r, C# P h9 a6 T9 d. d
else
0 e! K: Q! t$ s if(ch=='2'): d9 Z( z+ d+ E% ^1 a
{) Y+ r4 T. `$ h. D j
printf("Please input the cancel name:");
$ \# }3 _1 s) U scanf("%s",name);; C7 e4 f2 C8 p2 u8 e0 Q9 E9 P
del_cus(cus,air,name);( w% `/ W+ f2 C( N3 c
}
1 ?2 l3 T4 U. E2 r" v: V2 t, C else& Q9 O$ I: E/ p* j& A% ?9 B
if(ch=='3')
# N+ Y. m# H4 T. U( P1 B* X, k {
) l' t! f1 j% ^0 Q search_air(air); L, o! S" P9 b' X% A: c! G) m7 E
printf("\n"); ' w4 Q# j; m- m" B
search_cus(cus);! K' q0 a' D- y) O& P
}
9 a1 e8 z4 n# s6 O/ Y. ? else
+ y( a& @/ U! m( I* |- F" D& F if(ch=='4')
! t) H6 r* M6 G- ~. U- h {7 [+ o) l! i( W5 X7 v3 e' {
t=0;
% \+ n# D+ f- [, I }. ]* E7 i8 w& L1 ^/ I4 q; s
}+ u4 ~& m8 h+ Q4 M* j
}
& P/ L3 [ U0 k( H* M) E/*任务:通过此系统可以实现如下功能:
" u- P# w5 M M0 r8 N. J录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
2 }- Z4 U1 c) x: s查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);2 f- ?+ G$ T6 J, Q9 s/ N
可以输入起飞抵达城市,查询飞机航班情况;
+ s5 t: e$ Q7 _! K2 O( T0 `订票:(订票情况可以存在一个数据文件中,结构自己设定)
}. c N/ h/ N R; |可以订票,如果该航班已经无票,可以提供相关可选择航班;, b* S( b- A8 C5 w# @, E
退票:可退票,退票后修改相关数据文件;3 C' h2 y: T$ Y
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。 \7 D0 Z) v* o# b G6 U8 |7 u+ E' P
修改航班信息:当航班信息改变可以修改航班数据文件
' g! i. V* j; A4 H' E3 A5 Z& Z要求:! z! H1 h% B+ d) K
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|