该用户从未签到
|
#include<stdio.h>
]* x# T, S3 {# S* E/ J4 ~#include<stdlib.h>- _6 U7 j5 a! M* q, u* [$ l
#include<string.h>! ?9 Z! t" F Z' I4 c
#include<conio.h>& z+ S! i7 j3 k2 {$ O+ j n
#define OK 17 O3 S* i4 n2 Q- a5 r2 w- f+ S# v
#define ERROR 0
) @, D0 ]2 _2 G- qtypedef struct airline{. w4 E2 i3 A$ [
char air_num[8];
3 W/ V3 j: W9 [& _! c char plane_num[8];" W; f2 J" a ?
char end_place[20];) R7 L/ k( t! v! v7 y5 H
int total;
7 Y' s4 U* @3 D) T7 i% d4 U" i }% z( k int left;6 m& }7 z' F8 m$ ]2 u6 I7 K8 u
struct airline *next;
0 l) x) g9 a! r- u* P- y6 K1 E}airline;; h4 }% _; e3 v* R# ]
typedef struct customer{& r( b( D7 Q i+ c. S4 C: r
char name[8];
/ Q5 v0 _8 N8 y% _" o char air_num[8];4 Y z( h8 w. P R! W! e. Y( Z
int seat_num;! Z0 w! e4 M* m& }/ x3 S
struct customer *next;
. E# u3 z- r+ \7 W0 u( h}customer;2 n' N6 z! F: k7 y) y& l7 ?& A3 u
airline *start_air()
. x: o4 w7 l! p{
6 Y. y& L8 F: P6 W/ U airline *a;& n1 v8 O4 O8 a, y! I- W
a=(airline*)malloc(sizeof(airline));
6 _# d& r) p. J2 `: O& I if(a==NULL)
9 v7 k$ e& p1 j6 N' [& T- z) ? a->next=NULL;% Z7 t3 f$ G* p. h) C! ]
return a;
! T( p$ {( b. u' u}* G0 i, i5 s! [% d( r
customer *start_cus()! Y; [9 _4 I& y7 P2 j. q6 |
{/ g+ W! U4 F" x& S j. o
customer *c;+ S* t `* L% q' j% t
c=(customer*)malloc(sizeof(customer));# b. k% Y a- @2 o/ p% y6 `0 ]
if(c==NULL), M8 E7 e4 L: Y7 {& `
c->next=NULL;$ C8 R0 p% ~6 N- t5 }& g
return c;& _; N: W. L$ y! q( Q
}$ B$ J) w( `7 g) M z
airline *modefy_airline(airline *l,char *air_num)
- r- d: s& R6 I2 b1 h0 v{3 W$ `9 G4 B5 y+ [5 F
airline *p;+ K: x% X: |2 z& Y, f8 t$ y J4 v
p=l->next;& q; p) u( _8 k9 [1 ?
for(;p!=NULL;p=p->next)
' z8 H! l- N9 X; W& m {
' F0 d1 Q0 Z# I7 Q. v9 L if(strcmp(air_num,p->air_num)==0)1 g; `. m6 h; ? C
{
( s$ \9 V8 z- a3 L P2 a p->left++;
. X, i1 o8 ^7 w* N7 y return l;6 S) r4 T' s4 H# q
}
3 K4 F( O1 D+ `5 g- T; G9 w- O printf("NO the airline!"); G5 r. x0 F$ V+ c. y/ t6 a1 p3 F: x
return 0;/ r3 A& \% _6 C! [. k9 p
}
4 q0 _, t |+ N9 q r6 P$ e& l6 B}
5 U' w$ s |. [( V, H* Q. Y. bint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)+ Z2 r( h; w* L) d% [
{
' o: O1 B0 P* c airline *q;
) ~3 S* a* i' o; s0 I q=(airline*)malloc(sizeof(airline));0 P5 Q- E n& X7 z
strcpy(q->air_num,air_num);0 M; E5 `6 d4 X
strcpy(q->plane_num,plane_num);3 o) C" B6 b W+ J, E* N$ X
strcpy(q->end_place,end_place);2 a7 v1 }. O, z" [) ^- E
q->total=total;& p7 A- q# H6 m( f3 S6 y- v
q->left=left;
9 f" K0 e" `- |# H0 i; n, k- k" @ q->next=NULL;
& t' M8 H6 v& v% C6 K+ k (*p)->next=q;
# h) [. y$ P$ V1 P J, q! v (*p)=(*p)->next; h4 R& N1 p, T* }) m
return OK;# e. A0 a1 R( v c; `2 f- Z+ t
}9 |) c; g, t& J4 G e7 f3 O% P! u( M
int insert_cus(customer **p,char *name,char *air_num,int seat_num)* `3 }3 `9 m& d! e6 V2 \, I
{+ P( L) W8 Z9 x6 _
customer *q;
% w2 }9 s- ^3 K9 [$ E; ~8 ` q=(customer*)malloc(sizeof(customer));1 e! s7 V) g7 G. U0 B
strcpy(q->name,name);
3 v' _. l- S6 p6 o: |2 I4 [4 T strcpy(q->air_num,air_num);
% d- |& i# e* x9 P q->seat_num=seat_num;
$ Y) b# c, \7 S8 {# {! P& l, H q->next=NULL;
/ X) { s' Y8 i3 ~1 e a1 v: _6 q0 W (*p)->next=q;" p2 T" N, i9 X$ _4 D7 C
(*p)=(*p)->next;
8 c# P$ b& I) }8 p- u return OK;
8 e: u1 F0 q" H}
3 P3 t' B Q5 X( Eint book(airline *a,char *air_num,customer *c,char *name)
* ~6 q8 A D, |1 [, J, x{8 [- ^( u/ ]( ~/ X9 _
airline *p=a;9 w9 `& I) F4 t7 U: |* r
customer *q=c->next;6 p$ Y7 q7 E7 T, h C
p=a->next;; J7 d* z( |, K8 g& k, Y7 N
for(;q->next!=NULL;q=q->next){}/ U+ A6 |' Z$ b
for(;p->next!=NULL;p=p->next)6 b& t+ j; A1 s3 x5 G6 o$ p8 w3 f
{, ^ a- D1 C; q7 ?$ a5 x
if(p->left>0)/ b. Y f3 H, j
{# G( q3 R2 X. f4 D
printf("Your seat number is %d",(p->total-p->left+1));
4 H# _) A/ x4 N" Z2 m# b insert_cus(&q,name,air_num,p->total-p->left+1);% }: T; F5 z: f6 o* w
p->left--;
6 e# b7 S* s2 o u+ f0 ?, a return OK;
+ P6 y3 E2 ]; L P }
. H- x, r4 K" L1 E7 k0 U5 c else" G; ]+ n% p: D2 k/ `
{
" F& u4 L B1 \7 h( m; T printf("seat is full");, D: W6 M( \9 \7 o: G6 d/ ]* e( ?
return 0;" V8 x/ P; a: h; N% K2 w# K3 s
}: c. r! c1 z1 B3 }
}
$ f7 D: F: b# {return OK;, B: `; q$ t9 t6 h* k3 o3 n
}
( B [! ]! p0 J3 G1 X, T- T! vint del_cus(customer *c,airline *l,char *name): D/ o8 n/ A+ t+ w7 l! r
{
6 z$ X4 t; ^, A customer *p,*pr;; z3 O9 ]9 g' n/ c; w
char air_num[8];! d6 y- x! P1 c
pr=c;
. c v; i+ |+ _ p=pr->next;
; ]/ G. O. H! ~ while(p!=NULL). F, G9 l7 b: ], R
{( D3 c- t( M/ E0 g6 k. v
if(strcmp(p->name,name)==0)
, {7 a! Y/ c) x1 ~5 ~1 [ {$ J, Q# f& w- U; R( N6 w
strcpy(air_num,p->air_num);
# i8 i, r) c: I% R! V l=modefy_airline(l,air_num);) v# L" c1 _+ L6 f; R
pr->next=p->next;" `% F: I0 a- O+ x5 }/ F' R
p=pr->next;
1 `6 V# o, j6 y$ ?5 j1 ` B5 D printf("finish!");
, ^5 | e% H! L7 S8 r$ B# v# S. Y return OK; $ P0 m# o2 \& r: ]. W& g8 X
}' _, R0 N9 G; d8 T7 J
pr=pr->next;1 x; D% U! Z1 P0 b3 n
p=pr->next;$ j/ F2 y+ z0 d* {$ ^7 ^. z. a
}2 K9 I- i9 `8 i- F( @
printf("NO the customer!");
: C* Q; o) Q1 n return ERROR;4 m& `3 D4 n0 e5 x! w. d. U& ]
}
* g# V3 I- h6 K0 I; n( Vint search_air(airline *head)6 T4 ]1 \7 M/ x, _# K* c0 ]2 C
{7 h* L: k* L( ^# p" L
airline *p=head->next;
7 x: p6 O8 y( X- N# ^$ n printf("air_num plane_num end_place total left\n");
! Z |& \/ P3 l) |, w for(;p!=NULL;p=p->next)& s0 D! v* b2 D/ Z
{, J. A( |- Z, Q) }- l( b; C% u
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
' h! }% Q" j' ]6 B3 Y3 k }
( L2 z! E( y" c& i return OK;
`' z) [% _/ d( g0 h+ R0 p}
$ B! ?- V, k. W: |6 Y( {int search_cus(customer *head)5 K; f1 ?* A1 v4 o" P/ E
{9 j# u3 _! a- `0 J0 C u- R3 T: l
struct customer *q=head->next;
) g2 b5 ]( f8 _ t printf("name air_num seat_num\n");
+ z3 O4 [8 Y) `6 c for(;q!=NULL;q=q->next)
* p. j3 v9 Z- ~9 ~2 Z {- @# L( q- H. e" @1 p
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
; \: {& n& h4 K( } }
`& Y/ u- _8 q/ N4 I9 L return OK; Z! U" w0 ]7 h3 g- _5 A. ~# l$ h
}
' e# W ]/ T" F, ^6 B, \% gint creat_air(airline **l)& {4 T) `% J: X V1 J# e% r
{# b h1 t8 [$ u& X5 g
airline *p=*l;
' W: V( ~1 S8 x, y int i=0;( b H# M* S2 m3 @% V, R
char *air_num[3]={"007af","008af","009af"};
" z) L+ x# _% W& v( Y char *plane_num[3]={"plane1","plane2","plane3"};
# k, ^: ~. ^' h7 N, R3 ?3 T4 B% U char *end_place[3]={"Beijing","Shanghai","Tianjin"};5 F* C1 b) c# y2 w4 H
int total[3]={100,100,100};
- i* }0 C `% z3 _1 X3 @ int left[3]={52,54,76};8 E; q5 `" F: M/ A! J
for(i=0;i<3;i++)
( ~; K: ?1 c" O0 ~/ v5 {* E insert_air(&p,air_num,plane_num,end_place,total,left); h* F6 G1 S/ j
return OK;6 f2 W, E/ N( o' u
}
5 v9 R' B1 \$ y! K# q1 j# @7 _+ bint creat_cus(customer **l)5 S/ I- g1 ?& O- ]# H4 Q( y
{0 @' r- M- K7 m" h; _- ]5 A5 S9 b
customer *p=*l;
5 G _+ y6 M8 f" p" D0 h int i=0;, P H: S/ B$ A- A1 b
char *name[3]={"zhsan","lisi","wangwu"};
3 o. b. H/ h5 a; O6 T char *air_num[3]={"007af","008af","009af"};
0 n: r+ Q* L8 x8 {3 T8 g int seat_num[3]={2,5,7};
3 @, G' U9 l v7 E5 _ for(i=0;i<3;i++), X* f0 H) v, G3 @2 o
insert_cus(&p,name,air_num,seat_num);1 A; P+ _1 _, q1 O. p; z
return OK;' `! Z6 M2 g, q# ^ k1 _
}
. U* C& @% d% [8 I, s' L% `- Rvoid main()
7 a$ a) C7 R7 A+ Q{8 I) H7 W- y5 L( L1 f' X
int t=1;( }% M {" |( `/ M& z6 F4 B! M
customer *cus=start_cus(); p3 k0 n5 t- L2 p. ]2 E1 ]
airline *air=start_air();' ~$ e u i+ T( E \
char name[8],air_num[8],ch;( J" ~* I3 P( U, \5 c1 j: W' g
creat_air(&air);( |7 b0 P b6 l i0 W
creat_cus(&cus);: ^/ O S1 ?6 h: H% {
while(t==1)
6 M' L# Z7 Z( h7 B8 L {: Q1 ~* d% U7 ?+ l7 a/ q" G) p
printf("\n");. m8 C. ]/ F# ~7 j3 K) Q h4 X' e
printf("*********************************\n");9 J$ X7 x" |$ E& Y7 h
printf("* Welcome to air firm! *\n");- B7 I5 I) Q# W
printf("* book--------1 *\n");
6 }$ N7 ~( l, C$ V# ? printf("* cancel------2 *\n");* H) T8 h/ h+ B# h
printf("* search------3 *\n");9 ?$ P9 w7 M V& a
printf("* exit--------4 *\n");" V( C( {9 A0 i
printf("*********************************\n");9 z; y( X2 |4 a0 @
ch=getch();6 \4 p+ F" p# E" x' t2 l
if(ch=='1')
: z# p) _/ H/ \$ u {
7 R1 V0 L& X9 E& F8 r; P printf("Please input a airline number:");( S3 @+ P( q2 `: a
scanf("%s",air_num);
/ K1 C: e/ x) x- o printf("Please input a name:");
' M% a4 }2 @ @9 B; s scanf("%s",name);" r; X: [2 _; W" D
book(air,air_num,cus,name);
8 \( P8 o& ~( ~* B }
) F: }5 T& v8 i- \ else
" t9 `# Q) T% F- r& I if(ch=='2')
" L! u- s) J2 q3 z; B/ Y. l9 v7 m4 n7 b Q {
- I: B7 Q" y3 _2 H5 [ printf("Please input the cancel name:");
" ?# N2 F, l7 R scanf("%s",name);+ Y6 w) s- p- ?& T9 Q
del_cus(cus,air,name);
: y' A' w( ?3 s. G0 P }5 R* w& {" \$ I0 O3 q
else
( h( n3 d- d: |4 n/ F f if(ch=='3')+ U0 F7 Q! e; V( b p
{
" N$ e+ Q. C; w0 ?4 \ N search_air(air);, N) \8 v$ q2 Y1 V9 d
printf("\n"); , a8 w/ K: }4 [+ r
search_cus(cus);
% ~6 r l& D* k6 c9 D- @2 ]) y }
( \& r6 ^3 d' e, }+ {5 u else; E; b" W) U- _; h3 O" q
if(ch=='4')& Y7 Z% C3 }# A4 V# K+ Z" }0 z; U5 P
{ }' F; Y9 t' Q9 d+ q
t=0;, f* i# _- J W5 }" \1 u
}- K" c3 K& Z2 W, `+ E) V
}8 t' U7 ~: [& x$ \3 |
}
) I( g" b) R$ g# m4 u5 a5 r/*任务:通过此系统可以实现如下功能:. P0 i0 d' f% d* e0 B+ A1 D
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)* F' _; o. T" B. }" C% u
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);5 \1 x6 A1 }* W& t* v0 q
可以输入起飞抵达城市,查询飞机航班情况;$ Q# _4 w. H% f: i! z
订票:(订票情况可以存在一个数据文件中,结构自己设定)
, c. O; S# j* B+ L/ U6 O, g可以订票,如果该航班已经无票,可以提供相关可选择航班;
* C& `* H1 @( J# t: _退票:可退票,退票后修改相关数据文件;, }2 O1 Y* C2 Z" R
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。. X5 ?6 B2 M+ c' [1 l& x
修改航班信息:当航班信息改变可以修改航班数据文件( Y! g \( `* e# U
要求:
# ?+ H7 j. Z+ Y. O1 s8 w, j根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|