|
#include<stdio.h>
: {& R0 T5 X# g, L: w; W; C; [#include<stdlib.h>' f; Y g1 z0 T3 s# i
#include<string.h>
4 E; V& J+ W$ ~/ G#include<conio.h>" v. i0 m9 y; B! d) @
#define OK 1
4 E9 t% F2 j( }( p q6 U$ E$ I6 C#define ERROR 0- W/ s: w7 ]6 y
typedef struct airline{, {% u% j+ Y$ }& u: O+ |- W- U
char air_num[8];+ _* d0 A6 g0 V9 m b- Y; o
char plane_num[8];
" ?5 [. p3 ^& _: R1 v; ~% g char end_place[20];1 v( m. ~9 C; v
int total;1 Q, x2 Q$ E. G! i2 P' E" V/ X9 x) L
int left;$ i2 y2 _4 y0 A- p M; q e+ Q$ \
struct airline *next;3 c% R. T% l" t$ [/ R5 T3 R
}airline;% s y6 Z+ @0 h5 d* O* s4 ]# j
typedef struct customer{6 B' ?+ T* }' K
char name[8];" O- N! o6 f3 L7 o3 H/ F0 e
char air_num[8];
. ?2 P9 `, y4 h/ y2 y int seat_num;
: ~, L! V8 d p; U struct customer *next;2 u. S7 V& t6 s" I$ w) }
}customer;
: d5 M" [4 ~9 m8 l4 q3 tairline *start_air()
: ?& w/ F# p* R& C{
, s( T% I! | ^! Y) X$ L4 i airline *a;
% S' ~; v6 e: e, j H a=(airline*)malloc(sizeof(airline));
( m u9 F- L9 o* d8 I J+ z3 Z if(a==NULL)/ V& H/ e& t( {: W- A
a->next=NULL;( e0 B8 Q+ ~& I6 _- {
return a;0 _8 U/ ?3 _' [; F. R; v+ }: u) \
}0 i, ?. e/ T' @" M! H: B
customer *start_cus()& K, ?: M$ t: J% L5 M
{
6 r8 }& U: S: f0 } customer *c;' ~0 z" q4 O- `+ b9 `6 D! {" r
c=(customer*)malloc(sizeof(customer));0 h) W$ n% u. C# A) a5 p" u* @
if(c==NULL); x4 |- Q$ a4 O3 H
c->next=NULL;4 [( x9 y3 H/ q/ ^8 U# n8 ~9 I. F8 E. }
return c;
" A3 I2 B- |, N) \) f}: \9 U- h% T# X2 R8 X1 O9 }3 @$ h
airline *modefy_airline(airline *l,char *air_num)
+ ~% J0 R9 q) s{) R" ]# [* o. e- Q
airline *p;
9 E0 T2 M" B. @. S t" R* X p=l->next;) g/ J6 t/ Q0 `
for(;p!=NULL;p=p->next)9 j7 n5 t" u, F
{9 l( u# H0 e' l* r* x
if(strcmp(air_num,p->air_num)==0)& T, d7 r: {1 `4 r
{! L+ R# N+ t7 [ p8 n
p->left++;
0 K r1 U* H* z3 {0 _7 J1 E: U i return l;
' o. s! H$ D% {6 b6 ^( t }
+ [2 l' n( T" h# z printf("NO the airline!");
5 `8 D$ f% ^* v return 0;
) b* Y* S. C+ q! a2 ^ }8 b0 C3 c( S1 G; A' V* C! l+ p
}" g/ V6 F2 ^* d0 z8 F
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)2 w# T7 P1 X8 x" m; U
{7 H* G& w" q! I, B
airline *q;7 j- h3 r' o$ |% g0 \
q=(airline*)malloc(sizeof(airline));
" J7 R" h( E1 {0 j# ?- c: f; L } strcpy(q->air_num,air_num);
9 a0 p) I2 ~7 g( Y) P% p0 u strcpy(q->plane_num,plane_num);
$ _: E# i2 }/ r* P9 A) j strcpy(q->end_place,end_place);- ?$ S. l& T! q* }4 i
q->total=total;
3 [7 e5 B! S" }6 z q->left=left;
% E# I& t5 P4 r# ^ q->next=NULL;
1 Q8 b D* t" o, b6 k (*p)->next=q;
1 ?' v& p* O% R! X k5 X (*p)=(*p)->next;! @, o) M# _( j; \
return OK;
& _! q' y) W6 P( Z+ Q, `7 V. m/ G }
- O" ~6 }8 i1 U- T6 L$ ^: W j8 ?' aint insert_cus(customer **p,char *name,char *air_num,int seat_num)
$ S- N* f8 {+ \ |8 W6 Z1 P{
5 e0 K! L1 R0 Q9 N customer *q;# F$ [+ R3 f& X L' D
q=(customer*)malloc(sizeof(customer));
4 H4 t- y6 i- I strcpy(q->name,name); |. g, L) A1 l3 x2 D6 k
strcpy(q->air_num,air_num);
$ ^0 c( R2 n* N) }) ~ q->seat_num=seat_num;$ Q5 \; U( O( J' K5 W) \- x. n. j
q->next=NULL;
. a5 g2 `* R9 B! n, C; }$ J (*p)->next=q;
' H7 @/ Y5 H6 `( x/ k (*p)=(*p)->next;2 w! D. {0 j0 |( K. t( E
return OK;$ g8 I$ `* _9 T
}
s1 v$ |' G/ f2 r* Lint book(airline *a,char *air_num,customer *c,char *name)+ H2 [( Z" c9 ^# G0 l9 M
{
7 e1 |3 _5 e) _# ?% u airline *p=a;
/ }+ e7 k% G0 d" Y" p0 _2 U customer *q=c->next;
& n( r7 `4 ~9 } p=a->next;
# D' ~6 \ n* [2 b1 d3 K3 Z% n for(;q->next!=NULL;q=q->next){}
1 u6 _: A! G. I for(;p->next!=NULL;p=p->next)
2 U7 t6 _& @6 G. E3 ~- R: n: z {, x3 L0 `5 C$ Y5 Q0 R- j6 Y5 Y5 C, F
if(p->left>0)
- a( @5 q, y& x% [- e/ T9 n3 h {2 u- x) z( W2 c" C& \7 C
printf("Your seat number is %d",(p->total-p->left+1));5 [5 T% O$ G, B; |: Z' s7 Z( \
insert_cus(&q,name,air_num,p->total-p->left+1);* i, P' g+ W* I. \' p
p->left--;
$ X) ]- t- s2 I+ l6 \ return OK;
8 i( \. D: F5 a, X% u2 j } C+ j6 U+ I$ V* q3 P0 R
else2 ?) X$ B& c+ D5 @: I5 V
{0 z1 a# W; L1 p! N# k% J; ?
printf("seat is full");
, C6 W0 U) G; H1 m return 0;# m( s* Y8 E& J! M& ^- {' G
} R* n# x/ T+ D( h# L
}5 g5 x; S5 {" J- \9 I
return OK;$ e9 @5 |/ l+ l
}
9 ^9 \! _# u; m- s2 j9 m rint del_cus(customer *c,airline *l,char *name)
% e4 A' h6 m) j$ P$ p7 i+ O |0 O+ r{" y r, } T& M. G; h
customer *p,*pr;; F6 }3 A3 K% R& K% l
char air_num[8];
C) w. l- N. k: w pr=c;0 h: j- N9 N0 z% ?( @
p=pr->next;
# |( ~1 T& M$ C0 D% f+ g# @" I6 W while(p!=NULL)
4 O& v% U3 j% A+ t: Y& N" \* q# f {* Q# Q0 R* r! c- b! D m( F
if(strcmp(p->name,name)==0)
+ }1 }4 g9 c( F4 @( \ {/ j# t# r: r8 G- {4 Z
strcpy(air_num,p->air_num);; n- m6 T; I8 D1 N& L* D) L
l=modefy_airline(l,air_num);
5 s6 \- T2 T' m) D0 { X pr->next=p->next;+ b) Q8 z! k. k* N% [
p=pr->next;
4 K/ M8 e; ~- A5 V printf("finish!");' |6 l7 x8 F4 z" G$ ]
return OK; ' W# s8 {4 @. L' ]% l* P
}
# K: Q8 Q- h2 a' ~1 ^ pr=pr->next;
4 t! D' n% ~ A) A/ g p=pr->next;1 z! p# L4 K1 l @
}) j/ Y. V3 Z4 Z3 P! K( ` ~
printf("NO the customer!");7 T. o% Y3 Y i
return ERROR;5 A) y7 ~3 g, [5 x, T) u
}
/ ~0 K% j5 w& s1 T7 Uint search_air(airline *head)
8 F3 ^0 E: n9 s6 O5 }* o. K. g1 _; ?{
1 L1 X7 ]; R* c( U airline *p=head->next;
& H: W L: S/ {( }' D! U' h" Z8 f: F/ k printf("air_num plane_num end_place total left\n");
4 J+ R" E3 j" K, N for(;p!=NULL;p=p->next)
, n1 t* M a$ K2 }6 S {
" o0 p/ G: J1 W: F/ m, v, V printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);* M" g' F6 w- T
}
8 X8 @) `- O, D. W return OK;
6 o/ Z, s# U1 @# G/ k. d! t9 c( n9 ~}2 M& H n4 s! R: g
int search_cus(customer *head)
9 P5 z7 E' r. p. K) V# V% T{
+ Z) B8 j0 I9 `4 r0 ]8 {' M struct customer *q=head->next;3 h6 x& C! ^& n
printf("name air_num seat_num\n");; T" M7 Y8 D/ u; X% i
for(;q!=NULL;q=q->next)
( X% s' C& @; ]7 u {
( O, `3 y/ i# i& Q3 q8 ^ printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);# h5 Y O+ E$ |7 q2 ~0 q
}
) |2 z7 b1 |$ j/ k; t: n return OK;$ c N. {2 c. X- S6 H) S
}) P9 G2 p3 u8 g2 |$ O1 H
int creat_air(airline **l)
; U% n) h @7 T% X( J{
0 D8 } D% K3 i5 d% I0 Q% o airline *p=*l;
/ Y& F5 O, t5 \$ H1 ^+ B+ k int i=0;' g" D* _7 W# z* t
char *air_num[3]={"007af","008af","009af"};9 z3 K, c6 K/ H! w" x2 F) v! u
char *plane_num[3]={"plane1","plane2","plane3"};
0 X. T5 \# r" X- p char *end_place[3]={"Beijing","Shanghai","Tianjin"};
+ l! Q7 Z" x* ~ int total[3]={100,100,100};
! D& E p1 X9 ^% c5 p" e' ?# g$ c int left[3]={52,54,76};1 |. Q4 L" h& X' x' N% E0 D
for(i=0;i<3;i++)
9 ^' v0 _7 ?2 s* Y insert_air(&p,air_num,plane_num,end_place,total,left);* }& m; _4 N- j3 w/ V$ O% Y
return OK;
; C+ q$ X) E! D8 X6 ]}: x" [& @; ^; m& l1 }$ _; R" R# `
int creat_cus(customer **l): l- a* P1 w8 C* J8 l. p, l
{2 q+ r+ W; }& b. A
customer *p=*l;
6 Q& i" M3 L4 ~' Y% g4 _# o5 V; Z int i=0;
3 B9 b: R% j3 o! {. r char *name[3]={"zhsan","lisi","wangwu"};
2 U# o0 a( f/ P/ l) ^% t char *air_num[3]={"007af","008af","009af"};" q' D6 @' O2 T
int seat_num[3]={2,5,7};# t2 o. o, `9 y6 f; b) U
for(i=0;i<3;i++)' k) W2 v) a" T1 @* H3 f
insert_cus(&p,name,air_num,seat_num);
/ H' ^* B( K8 z5 @6 n2 c3 ] return OK;2 x/ O7 [5 l) n0 ]0 g6 ]
}1 G. z* L1 |9 j+ B2 }- r
void main()
$ m- Z8 V+ t9 ~{4 \/ O6 e7 w6 D; [5 U# l0 p
int t=1;
1 [6 U3 V) D3 }* G6 _ customer *cus=start_cus();8 z* g9 Y t0 t0 t
airline *air=start_air();
7 b2 ?9 V- d; S* y/ x1 R* S3 V& v$ r char name[8],air_num[8],ch;8 R+ ^6 n5 r3 z. d0 x( k& z# ]. f4 ?
creat_air(&air);, f7 |% |8 [7 ?
creat_cus(&cus);
& W0 Z0 R, M0 k3 E6 I7 { while(t==1)7 g- J$ @4 e) C+ V3 N5 v
{
0 t! P5 l1 c$ v6 b& s printf("\n");
! {! f* k* @6 _) T7 p* w printf("*********************************\n");
( S) z7 }4 F+ w. c, u/ o printf("* Welcome to air firm! *\n");
; C, \2 R' _6 C printf("* book--------1 *\n");
! n" E6 h; N& N. E5 L printf("* cancel------2 *\n");, B, U0 s( z! `" h
printf("* search------3 *\n");
' F0 B4 F4 T1 J- y& c0 @! M, P printf("* exit--------4 *\n");
8 M6 R6 t. Q4 p) m" w6 c" j printf("*********************************\n");
8 d4 S2 Z N* } ch=getch();
# z8 f1 k# h& m) U if(ch=='1')' w& _1 P. h: ^& [2 s3 v% H
{ H8 y+ `, D% n9 L! [$ X
printf("Please input a airline number:");$ z, E8 d3 x7 s" Z( J8 r3 H: y
scanf("%s",air_num);
9 q8 j) W9 Z- { printf("Please input a name:");
6 S1 ~. @6 q% ^! _3 A7 F scanf("%s",name);* _$ v& m D' v
book(air,air_num,cus,name);) I1 d- ^+ J- l. L1 P( m5 n2 \. b
}
# \- r- u& C2 @: p6 t- \ else+ S" W ~ w% I6 T, @: X' a
if(ch=='2')
, `8 s' s) K H8 ^: V {6 V, w( e. X9 t1 A! C% h# i0 r
printf("Please input the cancel name:");! j- N/ l$ \, z; X9 Z9 K
scanf("%s",name);8 L; N$ w2 A! X* r$ q7 y! q9 N. S8 z( M
del_cus(cus,air,name);
0 H" O6 L. \# R$ t, O }
1 B8 ~) @! c; _/ D else4 t* p2 N4 {- O0 K! ]* A
if(ch=='3')
$ @: G2 _. k. a' V" c) j& K {8 S6 S- n) ]6 v7 n8 n8 V$ U1 ?
search_air(air);
# z8 v9 I2 i4 B. V7 G printf("\n"); * i* n0 s: f2 u! v- `5 G# z
search_cus(cus);
) l; e: r, x6 O, v1 \* V+ F }: h! a/ c# B) H* J: `
else
2 C1 G7 j" L9 z ]- y! U if(ch=='4'); O/ {1 h: i; ]
{' n5 f- l$ n/ @
t=0;& i0 M1 k+ Y0 ^/ Q* b. F
}1 e7 w/ s. {) g0 M
}
( ?. U& A, H' w) T}
s4 s) t4 F+ s4 Q' X/*任务:通过此系统可以实现如下功能:
2 Z) i, ^5 m- |) x录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
: V$ |; A2 F n0 n5 `" w. ~0 q' S查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
* z% a4 d: B8 }6 S可以输入起飞抵达城市,查询飞机航班情况;
3 k A v/ g$ m订票:(订票情况可以存在一个数据文件中,结构自己设定), `- v" |1 S H0 u
可以订票,如果该航班已经无票,可以提供相关可选择航班;# K c. I& l% {% Q5 O& h2 B
退票:可退票,退票后修改相关数据文件;
) H# {4 a( [, l! N L/ I" {客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
0 @1 |+ D3 p9 t$ T8 a2 I修改航班信息:当航班信息改变可以修改航班数据文件3 H+ q/ X4 Z- J6 [- r/ `8 T1 W' ? v
要求:+ O- j1 B) J# U
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|