|
#include<stdio.h>+ w% _# s3 I6 `: |, @
#include<stdlib.h>
6 f+ Q: ~1 B- T' v7 J#include<string.h>
9 s% u o* \& {+ Y" y#include<conio.h>& |7 |5 k# Y$ F2 a+ I
#define OK 1& B9 ]0 {) p9 V2 o. Z
#define ERROR 0
) T2 M9 C; }1 n9 v) u2 J- Gtypedef struct airline{
( d' T* h6 j5 a$ c2 h char air_num[8];, |% t+ j9 y U* z# \
char plane_num[8];9 |/ |# e& }2 o0 p- D* a
char end_place[20];2 I' {- ~5 H& a, c9 s: r
int total;0 ]; @; ?. @ L( _8 h% N
int left;
, o+ c& N- U" @3 |4 n struct airline *next;
( e; L' ?; ^9 v0 c}airline;1 O6 T# m f, I. G
typedef struct customer{ E+ H+ A( ~. s! ]
char name[8];
- Q' O; n1 T$ R0 {, t9 R) t char air_num[8];
% o3 n# ^: `7 N, | int seat_num;- v! y4 A# M O+ c( ? p$ M) f
struct customer *next;
; E3 Z) E8 H# o5 a' Y9 [$ d/ [}customer; F+ _( B- j) p2 f# M. n
airline *start_air(), d! v0 z. ^0 P
{
|/ g2 @" e2 u [1 D+ f airline *a;
- W, ^ m! }. h& l+ u# {. ]* B a=(airline*)malloc(sizeof(airline));
5 c1 _! l! \. y if(a==NULL)
/ r& e% Z G; e f+ F% q8 @ a->next=NULL;
/ h% v, m* s$ i0 F return a;
3 {# w: J/ ^2 [}2 I7 i, p+ M# W/ h* T/ Q
customer *start_cus()$ x' d5 b9 [1 ?4 o- B3 V) e) F5 M# U
{
9 Z( f7 W# |2 [ Q$ I customer *c;
: \, b' {6 W" X* c2 y: C& y$ j c=(customer*)malloc(sizeof(customer));# \# E6 ]( H4 a! w
if(c==NULL)
9 y& ?; D1 |! s; s c->next=NULL;
0 Z( Q; z( E" d2 q3 r return c;$ \- _# ?# {; J5 F: n. }# Q
}
/ B B8 h3 g/ `- C* M6 yairline *modefy_airline(airline *l,char *air_num)* I( ~+ `& P8 `
{
/ J- B5 G, W0 o* M, y, f airline *p;
+ q6 R6 p A6 I: U% |3 a p=l->next;' A- o8 \# f0 o7 b' q0 ?" ]& G
for(;p!=NULL;p=p->next)& ^+ A, y1 _% m
{, G" P- L8 m. L: R
if(strcmp(air_num,p->air_num)==0)
0 D' S( t0 q9 Z4 p3 _9 N- n {" o# ^* f" h8 w5 ?* |4 o# g
p->left++;% v* E2 ~, U! F3 l
return l;
8 G% C4 w8 U: `; M+ L: W }' D, n0 G& G$ p2 x7 \
printf("NO the airline!");
6 `# ` `+ ?6 ^% j0 O return 0;" T7 H" `% n+ f7 h
}9 q' h' G4 n5 Z- z
}
- o3 J1 @ \' v( y) Y# uint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)5 g7 S5 d9 J V) M- P+ Y+ d
{. }0 A# M4 u T& {: ^- o
airline *q;" R! \/ f1 M: \+ P
q=(airline*)malloc(sizeof(airline));6 x! L2 q: k) L ~+ i
strcpy(q->air_num,air_num);
! ]1 K9 |$ I: Y3 L strcpy(q->plane_num,plane_num);- F- L# d! k7 o6 M
strcpy(q->end_place,end_place);1 V. X% w) }4 i
q->total=total;: d4 j {, z' ~+ ?7 n* `
q->left=left;
+ F# q- s: o* ^4 d, B( @5 x q->next=NULL;
. W" f: O: E7 k [! J (*p)->next=q;0 M. Z+ n$ G. w2 Q+ n- v- S
(*p)=(*p)->next;
1 v% t! O% o6 o ~ return OK;
/ [0 [8 q2 L2 g/ b2 ? }. v. x' V/ |9 H$ ^$ Z
int insert_cus(customer **p,char *name,char *air_num,int seat_num); a8 k! D. [* @; y# c- J
{- V( D. e/ E! o. Z# w
customer *q;
, r* r- `6 l6 C2 v% \0 H' Z q=(customer*)malloc(sizeof(customer));
+ i6 ]$ p% m2 d4 A/ y% q. V strcpy(q->name,name);
2 N6 A- w0 ?! w z% g5 \" e9 \ strcpy(q->air_num,air_num);4 C: u) D2 Z' h' C
q->seat_num=seat_num;$ g' L8 D! y- o6 t+ X" A
q->next=NULL;* G: @- a6 Y2 q$ ^8 c; ^% F
(*p)->next=q;1 G" \; ] R0 C& H
(*p)=(*p)->next;
1 f1 z. [' X4 Z( @ return OK;
. v& \- a6 V Y L; {}
. G$ [8 w$ v; R8 O2 g- D0 Jint book(airline *a,char *air_num,customer *c,char *name)
' t% M" ?3 {5 \" ?6 k% A{
; w8 O8 T; d' c7 I1 z* O4 p' T airline *p=a;
* V1 B: G- z# z) M) v customer *q=c->next;
2 C+ |2 G4 @. B9 K2 ^ p=a->next;
$ E. K7 j0 Y# \& G" |/ e. z9 K- a for(;q->next!=NULL;q=q->next){}
2 C1 E# t9 }5 P0 [2 {+ y; c0 }. ?( k for(;p->next!=NULL;p=p->next)1 o* w: r3 b( L8 @5 v2 D
{
6 @% K; H. S* E ] if(p->left>0)
) a9 O! a$ b- K, S1 l8 p+ s+ W {. f$ D1 n! b0 ]1 y" u
printf("Your seat number is %d",(p->total-p->left+1));
+ ^: A C* ], d5 O8 F9 K insert_cus(&q,name,air_num,p->total-p->left+1);) L% B% N |* c, I
p->left--;
! c+ [" J$ q. v& T. X return OK;( a1 F# h& B. z" t8 m
}
: t& C9 I& D# X. L F else
0 Z, D9 M+ |& c+ W {& i4 |9 E, o1 [- S
printf("seat is full");% g) d* `6 b6 P" \5 @. ^3 o
return 0;3 v- a! e" A& ~
}# r% n7 Z7 Y9 p" r' z! ^. q
}
. _9 f3 c* @+ Freturn OK;% W2 w& e0 n$ U& c. _) h4 r
}
7 R6 M! }: S5 Jint del_cus(customer *c,airline *l,char *name)9 m3 C2 N' |, \/ J
{( d; n- Y* F) S" `5 |+ L
customer *p,*pr;
2 f0 R# p* O# f F/ f' G char air_num[8];" }& R, B* f4 V# s2 L
pr=c;( ?$ r7 ? M' g y# d% _
p=pr->next;
/ r1 M/ M! d7 q while(p!=NULL)
# g) L0 j) P; y* f9 s5 J0 X {5 x2 E; L r' k5 _! Z3 \" f5 @1 h/ L
if(strcmp(p->name,name)==0)
5 h0 g% f2 L7 w2 i8 E% B' R {
* e9 S, \ o, y4 K strcpy(air_num,p->air_num);
& ?' S" m# b, J l=modefy_airline(l,air_num);
; S# D6 H7 E7 j pr->next=p->next;
: S4 j9 H/ V* X' s. `" U p=pr->next;/ V' A; }+ s" J3 l0 B& B Z- R. {
printf("finish!");/ P- U1 y3 P9 C2 c$ \
return OK;
. U' X. {) Q1 L3 ^0 ?+ |. e" N. ^, W }5 P$ g# p! Z( w$ A6 a7 o
pr=pr->next;8 o0 K& ]5 b. N# @
p=pr->next;4 B+ [+ ^0 {% A* S2 e" ~7 _( j5 s
}" I) Z2 ~. ?# H& _8 i# e
printf("NO the customer!");/ i8 ^* a s6 d: R3 {- U
return ERROR;; _( o. N# \1 Z4 B
}$ E! J# |0 X( c0 {$ h& e5 l
int search_air(airline *head)
% p8 z9 v% B# w8 `{
6 D6 R l# M5 |9 k airline *p=head->next;
- C6 u7 [( x+ X printf("air_num plane_num end_place total left\n");
& }* l( Y) Q0 V/ y9 ?' L" S for(;p!=NULL;p=p->next)7 E; B$ {* R6 H4 W
{4 ]! Y, r8 ]# K
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
# n+ `- a8 L$ r+ t/ Y }
0 |1 U |4 n1 ?3 X4 u0 Z return OK;. b8 B* G3 X. F. J( Z. P% h' J
}
+ ~$ l8 k+ ]1 J: Dint search_cus(customer *head)/ W; Q6 `3 b) |
{7 {2 a/ j* V7 P& Z
struct customer *q=head->next;
# p( Y2 G* }- I s( I4 C4 T+ W printf("name air_num seat_num\n");) N9 n+ a, N8 y+ z+ T( Y" E4 x
for(;q!=NULL;q=q->next), v- V$ T! K. }7 ]3 z1 ]$ d e5 j
{
) h2 J3 s+ L; Q printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);8 U6 u& S3 C/ k# z
}) W- P& ~: l. s) ]- {
return OK;
! `6 O0 S u+ G7 {0 Q, {}
3 y+ {3 U4 v J& ?) M) @! }* @& ^int creat_air(airline **l)
% b. r `2 D+ o{7 b# O9 m# O. v# D* y
airline *p=*l;
- U% W& U$ z% t9 c int i=0;1 M, t$ B, B% U' p, ?7 }
char *air_num[3]={"007af","008af","009af"};
g. M* ^' j* u* x; [( Q& ? char *plane_num[3]={"plane1","plane2","plane3"};
, E0 V, ?- K9 _& E' [9 f# s char *end_place[3]={"Beijing","Shanghai","Tianjin"};7 H/ a2 R& u: H! C
int total[3]={100,100,100};
# T* \& a. `6 }! k/ Z int left[3]={52,54,76};- V# A) |9 Z' }
for(i=0;i<3;i++)
. E4 { j0 ]! a, k) r3 O: w insert_air(&p,air_num,plane_num,end_place,total,left);
* _! U& @0 [0 k( x3 O5 f# H return OK;" |2 D: _. K$ ~+ u: \! b
}7 g+ ]: W, Y3 B9 P4 l0 [
int creat_cus(customer **l)+ o8 d7 @: q9 O7 _4 D
{
: c9 W1 j1 y$ n# V; P } customer *p=*l;! y- e+ \& v+ \2 r% J$ @0 f
int i=0;
+ _0 Q: O. _3 R$ m/ v! `: a char *name[3]={"zhsan","lisi","wangwu"};
c' [/ f0 @0 l$ r6 x char *air_num[3]={"007af","008af","009af"};
; _2 Y# |- K3 a6 I9 k int seat_num[3]={2,5,7};) X% x* q& R- K( u. f9 d
for(i=0;i<3;i++)) f* a$ P" r1 F" P6 @% ?3 T
insert_cus(&p,name,air_num,seat_num);" m5 a5 l+ D; N) M/ G
return OK;
, N! a: D Y( I F9 ? |}0 C: k K- g) Y% x) w O
void main(), u( S5 {6 L" C
{. f5 N, a- @, B/ F
int t=1;. w6 a' L8 @7 @& W' {# s. e# H4 y
customer *cus=start_cus();
- _# w% i' D4 o: [0 Y- \4 O airline *air=start_air();2 s: b3 z; p/ O4 ]
char name[8],air_num[8],ch;8 x: t3 L+ [+ P+ j0 J
creat_air(&air);
8 B3 [' O- C+ @* n) w creat_cus(&cus);
& u: y, `4 Q) x1 o9 Y% ^9 p4 s5 K while(t==1)/ G2 D' m1 r1 w v: v$ i
{# V( W& g8 x B
printf("\n");
r2 r# O1 q8 e7 T printf("*********************************\n");
7 ` d' r% T5 q printf("* Welcome to air firm! *\n");
) Y" a: b. O* J( B printf("* book--------1 *\n");; k: s9 w/ Q, _% ^" a/ [9 w9 M
printf("* cancel------2 *\n");
$ z! n4 _2 A# L# C2 {$ D( } printf("* search------3 *\n");
, ^/ _! G1 n4 @0 Y0 `" A printf("* exit--------4 *\n");/ P/ g; D8 L5 Q7 D% c8 p" g. V
printf("*********************************\n");, O) W8 ~& o( X; q* b
ch=getch();. E8 m$ i2 J! R% E
if(ch=='1')
% i+ L' e" y$ E$ P# I {
+ I, X( U+ ^- E2 H printf("Please input a airline number:");
$ \% ^$ h. w1 J X$ w scanf("%s",air_num);$ P3 w; P$ M; M1 K8 s
printf("Please input a name:");
. V$ \) U x: z U3 @: @# |- { scanf("%s",name);% B) [" a, U$ C- N0 j+ |) m9 T/ C
book(air,air_num,cus,name);
, r- a- U% x: L1 e. l& \- W }
! M- r0 f% z a& ]# e else0 l; c! n0 R! y+ t
if(ch=='2'), D* ]. E) _* |1 z4 i1 V' L. b8 p2 T
{
( r+ | Q' @/ J8 L( {- A8 k" v7 l0 B printf("Please input the cancel name:");
- Y: p3 ~% Y1 a; N9 m4 w/ w scanf("%s",name);
2 B7 t0 _( T' @$ E, a" s' w( U& M del_cus(cus,air,name);
; ^, w, L" [$ y7 W2 d }
9 q+ `+ i+ e- [7 R else
# J& p: C1 }9 i9 {3 Z" Q c) Q5 |3 a0 n if(ch=='3')
) m8 X; Y; l3 r" j: P% H4 Q8 R {5 B7 g% \) F& K% j7 z
search_air(air);& o5 Z3 j0 \' }6 `: \6 `
printf("\n");
7 M* P9 d' Z/ I, f& a2 r2 } search_cus(cus);' {; P: ]" U; g1 H0 F: |/ ]
}
9 F) C# ~5 C- P3 ~# B( a7 f else
9 l& i9 X3 ]# B( W! ? if(ch=='4')
1 M) X1 i3 H y) M3 g+ n/ L {! P' H; I+ ~4 i: E1 Z5 C+ q
t=0;
7 ^* A5 b2 A% A6 T& W( y }6 ^: \8 ^' z; B
}
8 N- x) a$ {" o8 A8 [' `}, k5 @0 E }3 `; K9 l1 u
/*任务:通过此系统可以实现如下功能:3 r3 v5 q# P4 R
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)* {8 f. Q8 C6 x2 g- S" y+ l) b6 G8 W
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);$ K7 t: x9 \$ [; x0 U2 m! y
可以输入起飞抵达城市,查询飞机航班情况;6 U7 f0 r) V3 _1 r. D \2 ~
订票:(订票情况可以存在一个数据文件中,结构自己设定)
: I% `$ E% Y, r. O9 k `1 [可以订票,如果该航班已经无票,可以提供相关可选择航班;9 k; z6 H! Q9 H$ G# I: n
退票:可退票,退票后修改相关数据文件;2 H& r7 G7 N6 G) P m
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。& ~4 T) s. n/ K/ J* r: D% w
修改航班信息:当航班信息改变可以修改航班数据文件
1 B- W' E& W1 P: c: `; F' F要求:
5 y) c3 o- K) X, I. y2 ] q0 ]7 y根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|