|
#include<stdio.h>
: T( e; z. I' n: Z6 I# v/ _#include<stdlib.h>
1 h/ a: U, `) ~( g& e#include<string.h>
2 p3 q. V: E$ v8 h* M8 n, ?#include<conio.h>) u1 b* `' I* d" H0 P1 ^! V
#define OK 1) g( D$ k8 O/ N7 A# U% A
#define ERROR 0
' [4 Y; i9 x* K/ [3 w. ]) @7 L. v; a. Utypedef struct airline{+ b8 V( H) ^8 b s9 g+ s, j
char air_num[8];) @' a$ Y+ @5 P: N% i* }
char plane_num[8];5 B2 B0 J6 H" J B; a
char end_place[20];! Z, P r; p" w% L: G
int total;5 M4 n2 T7 t! w6 {9 ~0 w
int left;
$ ~5 ~! c) k6 j+ \. ]! }! W9 q struct airline *next;5 E$ K8 v5 G% s+ l3 o, H
}airline;* O$ ]) _& a2 i; E: ?. T
typedef struct customer{
' P& L. |, r, h, a! E char name[8];' O; g( `4 @- ?
char air_num[8];
$ M7 |* |( B4 l h int seat_num;8 D% u5 j8 a- \" m
struct customer *next;4 U- y5 M! V5 `5 }
}customer;
* s2 M b/ D2 D) W: N5 pairline *start_air()5 n6 I' A8 \, I" _, T# V& x. |
{
' T6 j! ~0 r+ e9 i: S airline *a;
0 k5 D+ ] @. ^0 o a=(airline*)malloc(sizeof(airline));
2 k6 {& S0 B: D& @5 [" ]& o3 S) { if(a==NULL)
+ O! `' v9 T w. r3 e a->next=NULL;
- M" F- \5 E' ~) l8 y( D( Q* Z return a;
) z; q' `% H" H1 M# X. a}
9 _% i5 P' P/ r* W' [! W' \customer *start_cus()
y( c; @: _0 ] A3 Q{
: d; l- Z2 I/ C0 v3 T+ M7 P customer *c;$ X+ Y1 Y, m c$ {' f
c=(customer*)malloc(sizeof(customer));5 J J# r& B+ j$ S V
if(c==NULL)
' F/ b5 ~( w9 C: q! V c->next=NULL;) e" n! s6 x. u8 @! u7 R5 U% B
return c;% b1 ^& @% n! g
}! r% G! _4 f1 s: s
airline *modefy_airline(airline *l,char *air_num)
0 K8 R$ H% L: J4 U{
/ j6 B/ e; W6 i& X1 r ] U# ` airline *p;% e% V2 ?1 ]. L. a4 |. _# j5 X
p=l->next;
" {8 M6 D! [0 } for(;p!=NULL;p=p->next)
6 S) Y# S6 M& Y( F {( x0 z. L+ W/ c' m; ]
if(strcmp(air_num,p->air_num)==0)
2 L. Q& {2 G4 A5 ]% T" { {
8 ~# N) z! l& ]7 m8 }& k0 @% D p->left++;
$ p" e) I; d6 y4 m return l;6 L; }7 o; o; d2 `
}$ g" Q" x* Y% G
printf("NO the airline!");
# [0 x- i1 n; ?. y return 0;$ [. C+ G1 `/ _+ t
}
- t) W8 A: i0 x% p; ^}6 C% T9 B; B6 v% E
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
! o: ]' i6 @4 g" A' E' L8 Y' o{
& d5 q# {& q2 z3 m airline *q;7 N3 w- b; t" M9 m, ?) T
q=(airline*)malloc(sizeof(airline));
" c; Y7 H+ d3 f% T+ H3 e strcpy(q->air_num,air_num);, s! p) g& k- p8 i2 f0 S
strcpy(q->plane_num,plane_num); A4 i6 G5 U+ V+ }- h6 F B* p
strcpy(q->end_place,end_place);, P L6 l4 }. ]: h2 i
q->total=total;
2 Z" r2 a; {! H0 c q->left=left;5 F& c- q/ i0 v
q->next=NULL;
5 V6 |6 T3 V# `# L/ d7 X8 z8 O$ i (*p)->next=q;* M2 `( ^( ?5 M2 O* t5 {9 N3 n
(*p)=(*p)->next;3 n3 r# V0 d( Z# |0 m/ F$ Y0 u
return OK;
# E/ O+ F7 M4 m! ?" J0 Q% U* t4 z5 `6 u }
. {, ^1 Q& r, x9 t/ Xint insert_cus(customer **p,char *name,char *air_num,int seat_num)
' }' r$ h9 |- N" }{+ j* m% u; B! K, f! i
customer *q;8 l. H+ A. j) \! H! C6 b
q=(customer*)malloc(sizeof(customer));
& Z( p! M9 L9 r% {3 f strcpy(q->name,name);: Q% `, q. H1 T$ W4 d0 W2 v6 \ {
strcpy(q->air_num,air_num);7 M) Q. A% G3 g& j2 M' R# y1 i
q->seat_num=seat_num;: ?( Z% M9 J) i$ S
q->next=NULL;
' k/ W, d0 Q2 X3 }/ z! K, K: R L& n* n (*p)->next=q;* b8 M3 [" Y3 b* g. e2 E9 g: b
(*p)=(*p)->next;) p2 Y, F0 C: K4 \" y4 I1 r# m
return OK;
+ O# Y% }+ N H/ r9 ^}
1 z$ o4 B% z0 N4 a* @int book(airline *a,char *air_num,customer *c,char *name)6 s1 F% o0 p* E) H! p
{3 b3 E* i9 [- z, g1 t
airline *p=a;
5 u6 \+ e \% \- {$ `+ @ customer *q=c->next;/ f+ U$ s5 f# r) B2 T* I
p=a->next;4 V: d) j3 J% X* Z7 b
for(;q->next!=NULL;q=q->next){}
' o9 J7 P0 \ d6 P0 y2 F for(;p->next!=NULL;p=p->next)
% ~6 t8 b, c/ U2 k {# M1 e. H1 ]8 |
if(p->left>0)
4 ^3 W& R" h# B* U, l1 {- i2 a {: G) u/ V1 @2 N2 k
printf("Your seat number is %d",(p->total-p->left+1));
+ k2 ]4 W* L: z% v! U3 i+ e: ]( n/ e insert_cus(&q,name,air_num,p->total-p->left+1);
. r1 {& e8 N3 T p->left--;
! `- }/ h3 n4 t2 a [' Y return OK;$ r- l; H; p; C- r2 G, a" _
}
4 x) o r$ E3 e' i. ? else
7 x/ a3 P, ]9 i' a$ C2 T M {
' r& r! z% N+ m3 Q printf("seat is full");
! ?9 n7 ]/ h& |$ e* h4 l g return 0;7 b4 i: L. O0 {" f4 t: |3 K
}
3 n& x: N2 T2 A! {, M$ [" E6 O" u7 p }
' T n7 b8 v- _' L) z" n6 h2 Jreturn OK;
2 ?' g) M& f' e* Y}
4 g( D/ k: A, o0 k- e& o V2 s9 sint del_cus(customer *c,airline *l,char *name)
: f. z+ j5 Z) z{
; y/ w$ J+ L2 c customer *p,*pr;
% I" J/ r0 W* f9 s; w$ ?* ] char air_num[8];7 ^7 N) i* Z# H
pr=c;; C3 n) M! t4 T
p=pr->next;
) o9 M# }0 g9 M& T while(p!=NULL)+ ~* j( D& K7 G" i( z
{. x' f6 k: ?7 H. ~# y: J7 O
if(strcmp(p->name,name)==0)8 `- H. Z$ f* i: a0 `5 {8 `: w
{
9 l9 r4 q$ v+ u/ s strcpy(air_num,p->air_num);' E$ c5 g8 k- V, M( h% m7 \" Y
l=modefy_airline(l,air_num);
, F6 V- \- |7 x5 ? pr->next=p->next;- R! ^2 |' N. z
p=pr->next;- T+ D, B+ p1 [3 H
printf("finish!");' v0 B" \+ V7 T
return OK; 0 O& E% ?0 ~$ _% s i
}) W8 |' I; y9 x+ Q
pr=pr->next;
$ ^1 o" t+ n* E% T6 a p=pr->next;9 ^+ V) V- V0 F" J- m; F2 a
}
8 M0 I& v" ?2 a" Z/ R) a printf("NO the customer!");7 J! R9 o1 l1 W8 l
return ERROR;% y1 t* w* I, h, z6 o
}. e3 f. H3 G8 {2 d! T7 S* F! e2 P
int search_air(airline *head) I; c2 [5 i: _; L& `
{
. Y8 I+ l; W% @ airline *p=head->next;
( r2 p# r% r' e. N* U" ? s% ^/ A! Y printf("air_num plane_num end_place total left\n");% F( F9 \0 a7 ?. ~
for(;p!=NULL;p=p->next)
: q! \2 ^: l$ I {5 b8 ]( G. Y6 \+ w3 Z% |
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
- z& \0 J7 C: H6 K }7 _5 t7 i7 `2 ?9 m. d9 G; o; k, w
return OK;
* \2 R5 t: S1 N8 _( }( y3 f}
* X, h0 o/ `: \3 T( j) ^! A9 rint search_cus(customer *head)
" q3 c1 b8 @ i& d/ {7 S{
2 t0 r" A( C; m# o struct customer *q=head->next;1 n' S; Y# A" u5 \# h6 E6 A
printf("name air_num seat_num\n");3 B. ]. I) ~5 Z% j, X: d
for(;q!=NULL;q=q->next)
- T( k9 x) d3 a7 `- e0 \ {* y' k- e1 P( C! f
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);1 U$ a; [8 k1 m- n: o2 D
}
& p& i8 i n/ @4 d return OK;
* J7 W8 ^9 T7 [. `! i. e}2 H6 r5 H* @" U4 Y* z( V% @
int creat_air(airline **l); b5 v* |5 h5 g2 d* g
{" y) l9 P4 R d' W* |5 N
airline *p=*l;* E7 s+ e8 d% G) P2 f- ?
int i=0;
" ?' ^/ C. y" A: T2 y3 Q char *air_num[3]={"007af","008af","009af"};* z4 O0 {% G3 u0 f% l$ S6 P
char *plane_num[3]={"plane1","plane2","plane3"};# E) Y( a5 _7 Y6 C; }
char *end_place[3]={"Beijing","Shanghai","Tianjin"};
# m' y# ]5 O- b$ d2 { w4 f+ ]% L9 l* G int total[3]={100,100,100};
, w3 P6 j8 a; j9 m int left[3]={52,54,76};9 L k. L- t1 q
for(i=0;i<3;i++)! b0 C, i& a/ G; E! o6 k( U- [0 _
insert_air(&p,air_num,plane_num,end_place,total,left);0 @7 V+ c5 a: a# v
return OK;/ W+ [' O. ?0 p, B G" F
}
. d; `3 ]9 { H$ Gint creat_cus(customer **l)
! p7 l6 H) A, D{
: k3 g$ S. w9 V E* n |' s customer *p=*l;
5 ]8 T- {) c9 }- m int i=0;/ Y3 r) h( X: s- j
char *name[3]={"zhsan","lisi","wangwu"};
1 E }+ h- v- J, }0 r char *air_num[3]={"007af","008af","009af"};) x9 p: l8 d' i$ ^) J0 D P
int seat_num[3]={2,5,7};
$ N; U* e7 m3 U5 m6 W; ]& Z! d for(i=0;i<3;i++)5 [$ [# Y$ A. G P
insert_cus(&p,name,air_num,seat_num);$ N8 ^0 B* U4 _% I. o9 a9 M
return OK;
5 b: q4 Q% t( {0 H: v}1 H0 ~/ ?, e6 W4 t
void main(); I+ G) S9 z! c, a" R- x# I
{
+ p; N# O6 d4 B" k; D# p+ D int t=1;
; z! ~2 f! }% {8 I customer *cus=start_cus();
* a7 p J! l E# j; M. z' J airline *air=start_air();0 [% U1 J; U% U9 v& o5 v0 H
char name[8],air_num[8],ch;
9 ?! U, [: }* q& |" y creat_air(&air);
% F. [+ c. z5 S, i creat_cus(&cus);
: v) L4 L- m- Y while(t==1)7 g, o0 o& N. W) @% D# Z' f9 b
{: d2 i+ V2 e( \
printf("\n");1 s5 K1 i/ V) D6 ?3 C7 {, o/ N
printf("*********************************\n");: e7 ^! W: Z& S
printf("* Welcome to air firm! *\n");
& @' U K" `2 ^- @ printf("* book--------1 *\n");4 J) X8 G0 H1 K
printf("* cancel------2 *\n");
- U: z& T2 J3 W1 u: v% w' D8 t printf("* search------3 *\n");9 h( g/ ?/ B G
printf("* exit--------4 *\n");
- y' P- {, _+ X0 W printf("*********************************\n");
/ `0 }1 [- M4 C" ?& | M8 A( W ch=getch();" l! H+ `& p }% \
if(ch=='1')/ e1 e2 n$ @7 Z' l6 G& x5 I
{; F1 z0 T% } C7 B& x
printf("Please input a airline number:");
3 o2 F2 H* F: q8 e- {$ u0 u& S scanf("%s",air_num);
# `5 ~# A' [7 A1 e& c5 L printf("Please input a name:");6 f$ f: U# z5 B( p
scanf("%s",name);% r- v' O5 c% A$ j' D9 h1 q
book(air,air_num,cus,name);$ R5 s/ h8 P6 `7 W% h( z2 j! o
}3 Y; E2 {5 V! k
else! _$ k8 L& ~3 T
if(ch=='2')- c7 e1 }3 B% Q
{$ K% q; q! b6 p
printf("Please input the cancel name:");
* g8 z7 h. r/ y* W5 w scanf("%s",name);7 C+ E: c; x' k7 O" m) R; u' Q
del_cus(cus,air,name);0 r8 G/ r. o6 g, P
}+ H7 F8 V6 M! J. j; Y1 c% h
else8 l" q8 Y/ O0 B- S. d* L( n. h
if(ch=='3')
- A0 ?; U5 b' t4 z {9 n6 c4 X- ^5 H: {3 }
search_air(air);( J% A3 [" L5 z
printf("\n");
" [8 X1 @- ^; T+ b+ t search_cus(cus);6 z/ ^8 d6 _2 W/ D/ Y; A: P) F, Y3 X
}5 C) s% Z; g/ X4 B4 q n# G4 @
else
/ t3 A2 ]" N2 |: G& P7 K# V if(ch=='4')4 N5 _, e% \0 s+ O
{ o) ?! m) [6 d) u1 r
t=0;
6 w8 n* z! }1 g& ^2 @ }& N% E9 W1 b A- v6 G
}
: n" F0 O7 w! f}
( U5 z! y M! _* r# @2 |* A4 }5 \/*任务:通过此系统可以实现如下功能:9 X+ i. j* c9 \# q
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)9 Z9 ]- v) U4 h4 I/ c
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);7 j+ E" H! J$ I( z$ ]3 X( o+ |6 ?% z
可以输入起飞抵达城市,查询飞机航班情况;
7 \, x! p$ ?: Y- i3 C0 G5 ?订票:(订票情况可以存在一个数据文件中,结构自己设定)) M i8 }) [" J) Y% _
可以订票,如果该航班已经无票,可以提供相关可选择航班;
/ X: N9 _5 i" L a退票:可退票,退票后修改相关数据文件;3 k- r s/ Y. y7 Q& `
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
! ?! C0 _: ~' H( [修改航班信息:当航班信息改变可以修改航班数据文件
% b" o5 x Q3 f$ m! c要求:. I) E, c1 k, r
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|