|
#include<stdio.h>0 L; d! m. S2 R4 K9 z
#include<stdlib.h>& U& H4 a8 x+ L) F! C! C' D6 p% C
#include<string.h>4 t" a$ [* A7 a; e
#include<conio.h>
6 T' L6 k. q/ E* C( k6 S5 l+ h#define OK 1& @# G6 }4 }# L! A
#define ERROR 0& \4 z& d2 e# C c
typedef struct airline{5 K( t) S! T9 R% o& m
char air_num[8];
! S- \4 H( a& i) } char plane_num[8];
5 d$ O8 B- Y, ~2 A: \( e0 Z+ r% z char end_place[20];
5 w- b. U1 p5 ~5 ` int total;
* O# R" f4 u8 r! g" V8 j" V int left;
0 ^5 C7 [) j$ n struct airline *next;
* h# m1 c6 v2 e. w0 ~4 R}airline;
?9 B) V, I5 F" d/ ytypedef struct customer{: C0 T/ x6 g7 d% }
char name[8];
/ O# D. ^* C6 _1 ` char air_num[8];
5 [$ s, G0 F+ N0 S5 B int seat_num;
4 O* f9 B( d/ B+ c struct customer *next;
: e) e1 ^6 ]( Q/ v}customer;
% Y" i; L# P/ W% Q' }) R& Qairline *start_air()
5 Q" M+ p, @- ~+ C% t{
* U9 W: |% b& g0 h) w3 d. Q airline *a;- ~* Q* @. ?3 Q0 h
a=(airline*)malloc(sizeof(airline));, f3 }) D, c. }" C
if(a==NULL) r; V3 J+ N9 E: i8 x1 `
a->next=NULL;
% i/ ?- ^7 Q' f1 e return a;
5 `2 X, L; f, }0 G/ H}
9 o/ b2 U: Z! G, v2 C1 `customer *start_cus()8 U% `9 u3 U5 E! v7 X
{( j2 w" n1 u- T- ?, v
customer *c;
+ x9 v! N4 m) x) ^ c=(customer*)malloc(sizeof(customer)); f/ i5 ~" i5 d5 ^, |/ R
if(c==NULL)
1 c' v$ @4 R( c) r, I% r$ ` c->next=NULL;
) r" }9 u/ T. x6 [) p- { return c;
$ d# } L# [+ d. O3 M% c- l' u6 W}
* o9 p' f6 h5 t/ `, p u7 Zairline *modefy_airline(airline *l,char *air_num)
* H3 J: R( i4 `" o0 K6 }) F{
/ i% p+ J/ Q) X3 V$ [ airline *p;/ t. _. P7 ~/ T6 d( Q
p=l->next;! N0 B" Z! P/ y- ~2 r
for(;p!=NULL;p=p->next)+ [4 w4 r/ | @9 w) I; ^' H
{+ N2 r8 _* i) b
if(strcmp(air_num,p->air_num)==0)6 v% c. J" c9 ]6 K" k6 {
{% J* Y) A8 I8 U ]
p->left++;
& N9 m0 t9 Z- Z return l;. L, u3 {0 Q5 z i7 j' A# B
}
0 F" r8 i; q# v: Q' w printf("NO the airline!");
; L2 B! F ^6 }) |: } return 0;
3 O. z, T5 t9 i }
3 y- K% }/ t3 q! B6 w' I}( c1 c* V* Z% @9 V
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
) j2 o6 x \/ E3 Q6 C' n{* ?2 E# k8 t" I' y- u
airline *q;
7 N2 w2 D: w1 M% S9 o q=(airline*)malloc(sizeof(airline));
3 J1 u; o: y" r- e3 r strcpy(q->air_num,air_num);
- [9 Y. B$ ~* o3 D2 x( Q4 l strcpy(q->plane_num,plane_num);' ^1 q0 p( B V& { Y T" L
strcpy(q->end_place,end_place);
0 q6 S' X# Q* Q! u q->total=total;0 T H) I0 N6 C* H" x
q->left=left;/ W9 y4 A- i5 L$ O# Q6 N( |% D
q->next=NULL;8 G, @7 e4 ?$ U! o4 x3 G: K3 ~. m
(*p)->next=q;
4 F9 c2 e. F' k1 v% V (*p)=(*p)->next;$ n! K; ` _0 e# T7 t4 I% e
return OK;: U. m0 G/ g# D; Z7 c6 [6 q
}8 D% L- s$ w6 m& y% r
int insert_cus(customer **p,char *name,char *air_num,int seat_num)
' a [7 M% _+ b6 I{7 M5 k+ L0 S- F" U$ W5 h3 m
customer *q;+ A D0 [! M8 u" C
q=(customer*)malloc(sizeof(customer));
: z) s2 A# c% a# f strcpy(q->name,name);' P% D$ e% O" {; p+ t% m
strcpy(q->air_num,air_num);! n: ~1 [9 D' a" b8 x, b) Z
q->seat_num=seat_num;
' ~* N% W/ B" k, e8 M2 E q->next=NULL;% H) P. w0 Y4 ` c
(*p)->next=q;* A1 o3 m- w; }2 n' O1 j4 t* l# J+ \! N
(*p)=(*p)->next;5 K w' Q# J0 e4 v) C( X
return OK;
+ \& [! T s2 h* d" }2 ^}: t& ?4 T4 d, g
int book(airline *a,char *air_num,customer *c,char *name)3 C! f5 z6 z, Y/ s
{7 E( Q+ e- J2 n6 k+ C
airline *p=a;
5 O3 p( S2 I8 T" v, @. `) _ customer *q=c->next;" `2 E! s" z p/ r; ^5 Q$ Y: E
p=a->next;' m' ]; ~6 q& V4 x. J
for(;q->next!=NULL;q=q->next){}; `( H, i9 E5 y$ k
for(;p->next!=NULL;p=p->next)3 _/ x/ C6 ^: g- n$ c
{
! ^$ w9 v5 P" _& c( R if(p->left>0)
/ x+ F4 y! E$ @+ \' R: s: A3 C { ^7 I6 ]7 E8 ?2 }: [
printf("Your seat number is %d",(p->total-p->left+1));
, e0 T8 H: {' H. a* Z" `7 d insert_cus(&q,name,air_num,p->total-p->left+1);
9 v/ X$ H% d" W p->left--;
& O+ P$ b1 y0 C" L% `' C return OK;9 _5 `! l9 Y9 [" I/ P) r9 j0 S
}
% o- K% j* v, Z) C! y0 f. W else( b& @4 r D. Z$ s
{
( E' r, N% i3 y printf("seat is full");
) x& M2 e' R+ _5 h) y' u, h return 0;
3 Q9 D( B4 J; p f% O2 L% E8 {9 J }
2 t' l' G; |& X# |3 Y" \ }5 ~2 y+ r" ~( M" A$ |" B! b0 n
return OK;5 Q! s# C- I4 ]8 _1 z7 I, B, L
}# I: G1 O/ ^5 i- m: @5 V8 I- \
int del_cus(customer *c,airline *l,char *name)
& l4 }) s, z, S8 A( A# Y. k- Q{5 O' ?9 v6 @( n' a1 t, }
customer *p,*pr;6 S @+ \- p9 I. f* F7 ?; ~7 \# r
char air_num[8];! R" R5 T5 U( {' Y
pr=c;
* \% U% c/ Q7 b* t" B) g p=pr->next;) o9 e* `1 u0 ?: ~- R5 h7 ~
while(p!=NULL)( r, u$ E+ Z3 }) `
{
7 i0 o. B& B! ~5 G if(strcmp(p->name,name)==0)( s; R' { _! {
{+ {0 `2 N: Q m1 o& J; s; m
strcpy(air_num,p->air_num);# g. t9 n) Y$ ]' p
l=modefy_airline(l,air_num);
- O; M/ D' N8 h, j- U pr->next=p->next;8 i) y6 e. t. ~3 F
p=pr->next;4 M1 D4 S j3 v7 _
printf("finish!");
! u7 i" Q" r8 m/ _$ j9 e& F; S return OK; . z, E2 |1 c0 W$ [ T: u
}
: C% m+ T# ~) }, k/ N' L7 e( g pr=pr->next;
4 t6 }- O3 d: Y9 I p=pr->next;- X( G" z* V5 |; D; R( X
}! s. I, h" Z6 c
printf("NO the customer!");
1 B' i/ ^& r" N6 S. b- e return ERROR;2 f/ a, C6 M4 |! ]1 B9 s
}- c- p& x" Y; P6 |, P
int search_air(airline *head)' c0 {8 _) b' G% y2 D0 M; Y' F
{; V3 H7 e4 g2 B) R; ~: u
airline *p=head->next;
3 o. P1 n, A1 b: @* B6 ? printf("air_num plane_num end_place total left\n");
1 p# i. i# T7 @0 e L9 A. P# L3 M for(;p!=NULL;p=p->next)0 _% n7 m* q. M9 b1 d
{
6 b+ k9 S0 r: M* P' }4 Q" ]0 o printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
5 @ r1 p% G9 _: a/ C$ S }( f% A' `$ L: p5 H0 O* b
return OK;& w* c0 |9 N6 k+ I
}
, G+ I5 P8 X4 t ?0 {int search_cus(customer *head)/ E. d) Z5 |7 |3 r/ L( H( S k! m
{, K. A/ a9 L( w* H- y2 U
struct customer *q=head->next;0 @( V1 l* j5 |3 H1 V5 N' J# c
printf("name air_num seat_num\n");* ]2 b) R, b# p
for(;q!=NULL;q=q->next)
" w8 K" r3 y3 Q7 J0 m: }$ S; q {' g2 C, A$ }( g' @, {
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);9 s8 @3 P. {3 }+ o# M
}
: L0 \: p& z4 ]( o return OK;0 m P4 @: A- P# |- `
}
3 l" p& u" L; }6 x' lint creat_air(airline **l)
7 w0 H) l7 y9 C" b8 Q8 S{
% B/ `: e- ?+ L; g( b airline *p=*l;
+ A5 O- ^- J9 a+ ~ int i=0;
3 R5 i7 D3 a" k# a( w7 h- U. j char *air_num[3]={"007af","008af","009af"};
( F( T1 m, K3 c- C1 y. @ char *plane_num[3]={"plane1","plane2","plane3"};' C* K6 U! ?1 ~; @! ~: W9 W
char *end_place[3]={"Beijing","Shanghai","Tianjin"};
# t! v# u- g2 K. V) H int total[3]={100,100,100};
" H3 R' G9 A4 G int left[3]={52,54,76};0 }6 Y9 R, \0 j3 S1 R4 S k! k
for(i=0;i<3;i++)
8 Z( T/ C m% R insert_air(&p,air_num,plane_num,end_place,total,left); _. [+ W1 y* k; h, e
return OK;; y6 P+ [( S0 L
}. k1 C* I; H+ X5 O. e/ C! \
int creat_cus(customer **l)$ \2 E3 ]$ Q- N. m- y, m
{
1 P" z' z0 W- D9 |4 p- Y customer *p=*l;
' @6 e; Q8 H: B) d9 r) f1 y int i=0;
3 P" u4 ?! V9 m) L+ t char *name[3]={"zhsan","lisi","wangwu"};
# m( \3 B6 _5 l" ^/ C1 T char *air_num[3]={"007af","008af","009af"};' g! i% u* \, q6 P
int seat_num[3]={2,5,7};6 \) R# B. v* Z
for(i=0;i<3;i++)6 l1 |* n' y6 n7 Y$ X
insert_cus(&p,name,air_num,seat_num);8 e, O* H0 J: n: ^) ?0 b
return OK;
* b, {0 Z/ x3 j1 O0 `0 p}
% G' [+ |' I( D7 }. V/ tvoid main()0 A" A9 `# b: Q A% ~4 u
{
6 B7 f& A; `3 b5 w% f( l+ } int t=1;! o4 h" E7 i: |9 y- s
customer *cus=start_cus();( B c; B& i4 @% u
airline *air=start_air();
! M; K" g J6 m+ \( v5 ^' _" r char name[8],air_num[8],ch;7 h, H8 c# ]& g5 b" B$ O7 a
creat_air(&air);
# O# X4 r1 T, w4 [" j3 Z creat_cus(&cus);
2 L1 x: q" b3 p& v: P while(t==1)
) U0 A: i- F: ? {4 R+ g' n$ m9 _) k( K0 [0 Q% g7 y
printf("\n");
7 l, \; f. P& y0 @5 \ printf("*********************************\n");
' t w% w* d. K/ ]- \ printf("* Welcome to air firm! *\n");
5 d- l) r8 I! m# z- z6 n printf("* book--------1 *\n");3 j2 A) w; \. E6 I+ ~; v
printf("* cancel------2 *\n");3 n9 v0 q2 a; h5 { V
printf("* search------3 *\n");, R/ s! }+ m7 W2 w/ y. h* v3 V
printf("* exit--------4 *\n");
h" A5 _: q$ X- r% I. Q! w) B printf("*********************************\n");2 ~ ^2 j. l F9 ^* Z c6 I
ch=getch();
( X" @3 \; H4 |, L: k if(ch=='1')8 D" `9 u5 {9 M; l
{! C2 r( }6 v! E
printf("Please input a airline number:");
, r7 e [! }' H$ y scanf("%s",air_num);
7 v0 v& Y# D" s& z printf("Please input a name:");! U# x% y/ C' z K- R
scanf("%s",name);
) Y5 W" M+ b8 t8 h9 i# l2 i7 h* I book(air,air_num,cus,name);
/ x* ? c3 N3 [+ J }3 C) c' @( B3 Y, W6 _) Q9 G
else* O, K& V7 C! T
if(ch=='2')/ a2 p) g8 S$ Y
{
2 D! p7 A, U: E W printf("Please input the cancel name:");
4 j) ?! |& T( r scanf("%s",name);: b& I1 v) u" [, r0 v' R+ |
del_cus(cus,air,name);
4 r/ p5 J& o& e' b- | }
/ x, l' R0 I6 w2 v else
& W# n9 t8 @# O( l% V6 V if(ch=='3')7 g [8 Q* V: j9 v! r; a1 R% g6 F
{
$ r5 U- a% R8 x) N, D+ P; f search_air(air);0 a( o/ g( d) p* S6 D }) N
printf("\n"); 6 W: @, |$ M$ D1 u" _9 v- h
search_cus(cus);' ]0 e( y# W: l* ^
}. p3 `9 p; X; A4 q* U
else
: j" J( S$ P9 l. z if(ch=='4')
* k% N2 E2 B' Z" `7 k {
' x) r7 K2 D5 p2 \& ?2 q, w t=0;
: o0 z2 m5 \3 b/ b( S8 x4 w }3 a' o, x1 y( R/ `. r
} B/ r0 E7 u I% L1 T6 B& P
}
' v+ S3 S0 r. q a) T4 v5 l/*任务:通过此系统可以实现如下功能:1 L& |7 |3 a. j# f( X# L
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)4 I1 m' W: q/ ~4 t- I2 n
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
. X( D! i( A3 ^" Y3 c4 _( ]可以输入起飞抵达城市,查询飞机航班情况;% n% d1 m; F5 q: O
订票:(订票情况可以存在一个数据文件中,结构自己设定)- u' H/ E& f* }2 M
可以订票,如果该航班已经无票,可以提供相关可选择航班;! r' C( w/ w5 N, f
退票:可退票,退票后修改相关数据文件;" Q% N/ }& H0 S- e
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
, K9 s9 {7 p, v4 f2 r; z) F修改航班信息:当航班信息改变可以修改航班数据文件8 M! I# i3 Y" z [
要求:
/ m& s* y% H& z' {* q8 T根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|