|
#include<stdio.h>
0 M1 Z' ~/ y+ @4 q0 y( y8 S#include<stdlib.h>7 E) E$ h1 G2 Y- l
#include<string.h>, |( B3 |2 H/ y( s+ n5 s
#include<conio.h>
9 q$ i5 S& h1 }4 t |4 ?#define OK 1
7 f- u& i# t# _#define ERROR 0
! D8 y( b$ M) c9 j/ Qtypedef struct airline{
0 Q A: u% U' J! ]2 Z char air_num[8];' P$ L% _( h$ P5 ?
char plane_num[8];
$ }- }+ k4 m0 r! |! q( A char end_place[20];/ C2 O! x7 E( O6 j( `% k
int total;* ]( d- R) M$ }& `# V
int left;
$ k# `: s8 |* j struct airline *next;; O- L6 j( \, U3 Q# m/ `
}airline; E8 f# [. H0 O) M* S& d
typedef struct customer{) R/ w, ~5 ~3 z0 v& H
char name[8];$ _3 l! }& U j- O
char air_num[8];
7 s, A- O `- L: c6 ] int seat_num;3 ?0 H3 e6 h5 i! F) H0 C
struct customer *next;& [: c8 }2 o1 c0 b/ `9 V2 E
}customer;
# W6 ?# J) q; \5 P2 Sairline *start_air()0 v. Y' V; B. A$ ?* U- c
{
+ b! F+ D, O: j- N! T5 m" l! y airline *a;5 O9 A0 K0 ^9 t( \2 L
a=(airline*)malloc(sizeof(airline));* j- ?9 w3 N0 Y
if(a==NULL)9 W& c. r9 t& G
a->next=NULL;
1 w: j8 E% H+ J return a;
0 I) M! E# H: w* o}# N: }2 R- }2 K# }9 f$ m4 f
customer *start_cus()& O/ o& k+ n/ k3 q
{
$ j" O9 n5 _9 f customer *c;5 E4 d* B6 z- R* `
c=(customer*)malloc(sizeof(customer));3 \2 z i* A2 I* Z8 l: m [, p) a
if(c==NULL)7 H) Z1 u7 f( M- ~2 N2 `
c->next=NULL; J0 H4 Q, d- p* v u4 F
return c;
, P9 t/ z- p1 r$ x}! ~ V# T+ O4 _0 Q2 M
airline *modefy_airline(airline *l,char *air_num) ]3 Q5 K. n; t& a* E
{
4 F) c' G- G: [" G/ K; B airline *p;, B4 f( C$ @- ^" L
p=l->next;
5 n6 \, I; q [1 p( O8 k for(;p!=NULL;p=p->next)1 T2 b6 s% C2 U! U' v
{
J& ?4 N+ d/ D7 @ if(strcmp(air_num,p->air_num)==0)" A( V2 V, N: _* ~; _
{
7 H) o7 L" n, a5 Z5 {6 b p->left++;2 w+ O9 A9 s6 B, {/ _
return l;
& h: T& C& W1 o: u6 [# l }
' r" g8 I I* j4 |# H8 q' u printf("NO the airline!");$ E2 z7 |; H0 b: W* Q6 e2 Q! K
return 0;
, B& U9 W+ L) R6 h6 R- n2 @ }
, k# V7 f: G1 b}4 m6 q* a9 x: ?/ ]& d
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)3 Q. q) y$ b% y- t6 j0 v! i
{; h- g, f7 G7 {
airline *q;
# ~( u: I9 Q8 r; C. ? q=(airline*)malloc(sizeof(airline));
* [& [5 W3 N, D" B# c1 i t strcpy(q->air_num,air_num);! \% J' J; x. G- \& F7 U9 g% \
strcpy(q->plane_num,plane_num);
* }% r# z/ F3 Z* l3 g5 u3 h strcpy(q->end_place,end_place);. ] A/ B( Q3 ]
q->total=total;6 @0 J, q) [; N; b5 t
q->left=left;
. \+ D$ k7 D, u4 V- _ q->next=NULL;8 Z4 ~: R( b8 D' a" x: }4 Q
(*p)->next=q;
% n+ r9 k4 y2 C0 j/ d (*p)=(*p)->next;( Z1 G1 E0 `. x6 Z
return OK;
4 Q2 i( a, b! @5 G$ d0 F1 i+ k8 G) y- J* s }$ \- K" P" c3 t0 x7 F
int insert_cus(customer **p,char *name,char *air_num,int seat_num)
+ o5 [. h, {3 |( s; e/ w* k- ^& x{
m+ { P2 x$ r' j P customer *q;: ?/ f1 T# Z& a1 \2 `" G7 E: S
q=(customer*)malloc(sizeof(customer));
( @1 n* ]" \ o* o! a. I" _1 { strcpy(q->name,name);
. s7 T& n8 [1 ^" g( j/ E1 \ strcpy(q->air_num,air_num);: ]3 J! |( e9 N: \ Z2 q+ N, V- V- F8 c
q->seat_num=seat_num;6 d% b. V' _5 ?, F5 E
q->next=NULL;
0 h3 h8 D! d8 @$ A4 U- | (*p)->next=q;
2 W2 d+ }9 w+ H, U+ U% G! k9 o (*p)=(*p)->next;
# Q5 _0 t2 A: P; Y1 O return OK;
5 U' P; \" V, Q6 g9 ^- r; p}
* ]9 A0 ^1 @0 J" r% f9 X fint book(airline *a,char *air_num,customer *c,char *name)
1 B% r- a3 r, {3 L; L{6 j( k7 H9 e* n% [6 S
airline *p=a;
0 O4 J/ ]3 i. \* s2 k customer *q=c->next;
3 A* B+ u! y C+ B4 m p=a->next;
! n& ~2 d- c% z( M# V for(;q->next!=NULL;q=q->next){}' j( @- \ L" o, U" S2 Q4 |. w
for(;p->next!=NULL;p=p->next)
* K2 j S1 B( w' k {
6 s/ V: \$ w W) r if(p->left>0)
2 ?. [$ q7 B1 i$ G {: X8 [ i1 @$ N7 d3 w! b
printf("Your seat number is %d",(p->total-p->left+1));$ ~6 ^9 W: j1 b( ?" S
insert_cus(&q,name,air_num,p->total-p->left+1);4 ^/ v! y. ~6 ~2 ^, u+ x" t
p->left--;
% j' c2 i8 X! L* `0 w$ \6 _ return OK;
9 [9 f6 o) y* u( u }
" e1 a+ E/ A. p else
% M3 Z; N# Q- U s! G9 O {
( k$ q# T1 g9 J printf("seat is full");7 F" v4 E4 l- ^" e8 h
return 0;; V: q6 W6 R9 D$ _# e; A; v s
}
; { o4 L0 p- `5 X9 Q8 \ }
( R; {8 m. l+ h- C( Nreturn OK;
; w( U' g& u' s- n}
' _# l& K% J1 e: c. Q: xint del_cus(customer *c,airline *l,char *name)
0 y3 i+ b- W! [{
6 U: T6 ~0 h% Z0 f/ L& A* n customer *p,*pr;
, L6 U7 a; \8 l1 T char air_num[8];
6 A. \' W( y- c1 E pr=c;5 e1 u7 c5 i3 m3 l2 K0 `1 W# T
p=pr->next;0 g9 {" S/ C9 }5 l3 [0 i3 v& O
while(p!=NULL)9 w" I+ @2 P) E
{/ \& K, ^8 {" l5 y) U8 Z
if(strcmp(p->name,name)==0)
( v0 \" ?& Y$ S- L0 H( V( j$ }9 { {
1 j) C3 {" P" x1 z& z& D, g4 M strcpy(air_num,p->air_num);
8 u; I& Q( D/ ?" N% Y6 ` l=modefy_airline(l,air_num);
4 E( K! s9 f# _/ s pr->next=p->next;
: r! A* @* @. G; | p=pr->next;
1 s: ^* H2 A8 g. R4 C6 q* r1 C printf("finish!");- u% n$ D" D% ]9 @
return OK;
, ?. e' H5 ~1 Z% G' ~ }/ A$ _2 S" F4 M' ] a
pr=pr->next;( O: R5 y1 Q- K2 w- G
p=pr->next;* j! F; `2 V( n# K) U
}
4 ^3 D5 x5 Z5 W" w5 ?" A* e$ F* J printf("NO the customer!");! J5 R/ `- V7 P4 _3 C
return ERROR;
. X1 Y2 P! e6 F( r% `}
* l- g9 `( [0 f' p$ \$ `% Hint search_air(airline *head)4 R: @ D% ]' R7 p+ A
{; V$ j" g9 E9 g: x A( P
airline *p=head->next;' K7 X1 @- C+ u, M# X8 g. Z
printf("air_num plane_num end_place total left\n");
+ i7 ?; H1 a$ H \/ T, x for(;p!=NULL;p=p->next)
9 U8 x8 ?9 `' A2 r+ c {0 K+ F2 ~$ ^* a: U0 K
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);! }5 v8 L7 z1 z2 V' o
}
- Y" r6 F4 e( s3 e4 t return OK;
/ q7 H! z, Q" K/ s7 R* |# Q}
( q5 U1 s8 R" A- A6 `# p# v+ r* I8 Jint search_cus(customer *head)
9 G& A* T' r1 |" `{+ N2 X" v. a* b! B3 H
struct customer *q=head->next;- |" O7 j: q5 ^( c4 K, C" b
printf("name air_num seat_num\n");+ ^* Q& z) @: D5 l L
for(;q!=NULL;q=q->next)# |- w/ z" o3 [8 ]3 y$ a7 g
{
. }: s% M3 {' }5 P5 S: o) X printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
6 n5 \4 p. n: o3 { i: Z }
& F: @/ W& C; ]/ Y return OK;
. N% b3 Z6 X" E5 T+ |7 h: o}
0 ?1 }8 Z0 D0 zint creat_air(airline **l)
, e9 ?# u2 b) ]3 Y3 m5 \{. a( z: g! O7 g
airline *p=*l;) }+ m; q1 |- ?% c4 i
int i=0;9 I, ~ ~/ H* ?7 g
char *air_num[3]={"007af","008af","009af"};
: X" F' F) B% @( J) p+ a& F8 A char *plane_num[3]={"plane1","plane2","plane3"};
6 ]. J% f+ e$ ?1 M* O char *end_place[3]={"Beijing","Shanghai","Tianjin"};5 t' u1 R$ L; Y( r/ \
int total[3]={100,100,100};
) q+ E7 M* a- n t2 K5 u. E int left[3]={52,54,76};9 p. o' J" B% o4 e" C0 e# r
for(i=0;i<3;i++)' |8 k; l/ r1 x7 x" C2 n
insert_air(&p,air_num,plane_num,end_place,total,left);
- l- c" Y( x( k {$ |2 j) d h/ D return OK;
2 a8 a" G: R( s}
$ e; @7 ?4 X7 Q! k( k+ Yint creat_cus(customer **l)
$ d9 g" D* m9 f u{* l- r) i' a4 c+ s: `- \8 \) j
customer *p=*l;! D' N; D. N5 h& N+ G
int i=0;9 U$ g7 ?4 ~' C
char *name[3]={"zhsan","lisi","wangwu"};8 x( n, `0 i/ o# j; \: [
char *air_num[3]={"007af","008af","009af"};( ]- t0 S- `# A( }$ r4 p* O
int seat_num[3]={2,5,7};
) R4 R5 ^7 {- t2 Y* Z+ ~+ U/ w) H. N# H for(i=0;i<3;i++)
5 n' w5 ^; j. n! x: t insert_cus(&p,name,air_num,seat_num);
- F9 T7 V [+ `" Q return OK;
6 ~% N) G0 r+ n# ]! n}; ?, X c: E" e, V
void main()
+ m! r! _# u9 i- A5 y7 G, f' J% `: `! i{
% Y$ W: e, m& S" a* q. x8 | } int t=1;3 Y$ G) y: @. B' o$ D" K
customer *cus=start_cus();! Z% u x4 j, d( M/ u' E" q
airline *air=start_air();3 k/ j$ u# u; |) _ L3 v
char name[8],air_num[8],ch;
# E ^6 P' b$ |' R5 @3 ^4 E' l creat_air(&air);6 U# b c+ L- J' H- M& r* f. ?
creat_cus(&cus);! K4 ]% I x, M) S! ~& T) V
while(t==1)$ W3 i& Z [6 k3 N" d# p
{* K {' g+ C' J b
printf("\n");
6 H; Q, Q' E& S( c$ ?+ ] printf("*********************************\n");9 K( ^! Z# @+ _* i% e: o7 @; {
printf("* Welcome to air firm! *\n");: d* I @4 e7 @
printf("* book--------1 *\n");
% b9 S% R0 x. L! E) l* X$ ]; D9 J7 ~ printf("* cancel------2 *\n");
0 [* e7 R8 U+ P5 { printf("* search------3 *\n");
^6 C6 Z8 x/ n1 G' w printf("* exit--------4 *\n"); c6 ^+ w, B+ o( d2 r/ C
printf("*********************************\n");- Q, X+ P+ g$ C x) m* B- G
ch=getch();
; l% G. r$ o1 C& ?9 b, f. h if(ch=='1')
) T) H; t# K5 D2 ^) _0 g( Z% o {1 {5 E2 p7 v* t9 E G
printf("Please input a airline number:");' `4 | a+ W! M M' d- v5 G
scanf("%s",air_num);
( j) H9 o- ?6 p/ v$ O2 x printf("Please input a name:");) x! Z8 O- M( l5 {1 ?
scanf("%s",name);! Y3 F- e9 p. P# J
book(air,air_num,cus,name);
y4 ^3 i+ X7 \" I, [( p" a+ a/ | }
6 Y7 [: i! Y/ i) V, U7 k else2 n O! N+ d! [* h9 y7 z4 q1 V& ]2 `! e
if(ch=='2')! T( t& b$ F; x( K
{
2 E1 m. L/ }4 k, G2 A printf("Please input the cancel name:");, J o: z6 L6 ~4 [- U7 K0 z- b
scanf("%s",name);
+ \6 r3 d5 Z* |3 I2 y% D del_cus(cus,air,name);, {/ n# }. H: d4 f4 k
}
h A" d* m v# `/ F else
: A) N/ v" d& ` B' R: Y if(ch=='3') v% v7 m& j& R, C- f& c, q& `$ Q
{& ?/ O4 w' H$ w" Q; o t8 G
search_air(air);. Q/ b& f( R* P7 l8 U! t
printf("\n"); 9 I* W5 K2 [3 P" I2 ]
search_cus(cus);# n7 F, ]/ s" O' v L) \' e8 L r# H
}7 G e$ z' p% S/ ]
else$ h+ `9 y1 J; B0 r
if(ch=='4'); X# |$ B% w, V0 F
{
& M1 S/ f' E6 l* Z. X3 } t=0;+ l, \+ {( ?0 g; @2 C; y
}4 l7 T6 a3 B2 u4 h' p1 t( H
}
+ a, ~5 s0 v. y( q- \4 X' N}, x' I4 L9 ]3 J R8 ~! P
/*任务:通过此系统可以实现如下功能:/ e/ v- w- t5 [5 W+ E+ H6 s
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)6 }/ o+ R, K7 S! o' \
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
/ H; J8 A' f) a# \. E可以输入起飞抵达城市,查询飞机航班情况;
+ }8 [# Y8 D4 N) o: L; q( @% T订票:(订票情况可以存在一个数据文件中,结构自己设定)1 C& q% q u( O8 p: J- v: t/ B, J
可以订票,如果该航班已经无票,可以提供相关可选择航班;# M5 J. h5 a. ]" x& [7 v+ l
退票:可退票,退票后修改相关数据文件;! O- _6 ~. z: R
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
$ d" b2 U2 ?8 f# D2 ^6 V. Q修改航班信息:当航班信息改变可以修改航班数据文件) ]) L/ |' C1 a
要求:/ x! v# S. M/ s0 D% s0 M9 r3 I
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|