该用户从未签到
|
#include<stdio.h>
$ \7 k! z% v) B0 k% A6 n#include<stdlib.h> P7 b* ^' a6 Q9 N- |7 F1 o- l
#include<string.h>5 @5 i6 j! \# R) j3 c9 ~7 ] |
#include<conio.h>% ^- }9 _- t% d; D3 K1 I
#define OK 1
1 S( ^% F% F* ?: _#define ERROR 0/ p0 b* f% @# p, r* E5 z( Z
typedef struct airline{
& C$ }: [4 v" i# g$ L4 ?0 j char air_num[8];. I. j( r- `0 g) a2 x+ I+ M( @6 t
char plane_num[8];
g; x8 Z) r) a) s/ m char end_place[20];1 F% ]3 Q' D- k! L
int total;/ ^: W7 W( e4 }) c
int left;& n( \3 H% N: p9 Q6 j# C
struct airline *next;/ j7 N, i# s# m/ T+ I! m
}airline;# r0 I5 m4 A0 f$ l- Y1 I0 _) }
typedef struct customer{1 |# x2 s5 g. L6 c0 T, z
char name[8];
4 H0 M' L M! Q9 s u char air_num[8];$ s( N r1 f W( a8 M
int seat_num;- v% V' e2 S, S( Y9 N+ p
struct customer *next;0 @$ c8 f- Z1 W* F i- E* h
}customer;
) Z5 @3 g3 V' Q9 A. I: q9 {' Tairline *start_air()
0 o. R( i! ? c G. O) m* E' M{
, M8 d; _# A/ \; N airline *a;
: {; N! E3 d/ V a=(airline*)malloc(sizeof(airline));
8 M# Q/ Z; a+ t% J if(a==NULL): w- L) W5 I5 w& v1 S6 `. j
a->next=NULL;
3 z$ S8 P$ I% C2 g8 g return a;& r5 ~: U( P) W' F2 y
}
, |7 Z1 X7 h9 s" G$ u& m: P7 Icustomer *start_cus()6 d1 ^* p b$ B; n# l; e% f
{+ O5 l! @8 l! W1 E" m
customer *c;& M2 |2 y/ A& m/ T( j. p
c=(customer*)malloc(sizeof(customer));
: Y; J9 l$ J$ r if(c==NULL)( Z3 T8 ]( @; i$ B, V
c->next=NULL;( U5 C0 v/ ?. n; Z- k, h/ N
return c;9 I5 \; ^) {# F6 K
}
+ n4 A7 v! w: [# w" e _9 @7 sairline *modefy_airline(airline *l,char *air_num)# N1 m5 l4 Y9 g3 Q% N
{6 F5 a: N$ w" Y! }' C
airline *p;
* I. U! ^; v2 Z6 q5 t6 W/ \ p=l->next;
) _& W% ~/ L/ v$ N$ O$ L for(;p!=NULL;p=p->next)
, X6 Q, |( m- k' M1 n9 \$ g {0 R8 L% A- q) K
if(strcmp(air_num,p->air_num)==0)5 a$ h+ \5 R8 [. j8 u$ d
{
# U: Q) \# _0 J6 a( o) Z: ?( @. c p->left++;" m* w2 S- T; g
return l;* Q5 A T! o: ^
}8 J, I* b/ j& {. _5 `
printf("NO the airline!");8 C' y& K: b/ w4 ~! W L
return 0;9 T2 n7 r( \& J+ d9 Q# S
} X( a3 z0 G+ x/ O3 [
}) a- h1 ^1 y1 H( y1 Q" b
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)7 ?& i$ r; K; i% M! D0 |
{) ~6 e- x4 m @7 o0 B7 r+ T
airline *q;
7 n( l0 W2 | c+ x. U* @ q=(airline*)malloc(sizeof(airline));
3 C( I2 U* Y) Z strcpy(q->air_num,air_num);
9 i% t2 b8 y C0 f+ o strcpy(q->plane_num,plane_num);
3 g9 g0 \1 k; n9 g9 k strcpy(q->end_place,end_place);
: r9 s$ d9 Y* J! d* N# F q->total=total;7 H" F* c3 o* { G& i2 [3 k
q->left=left;
0 ~/ f- m, K! A# w% z q->next=NULL;
# N4 v" [/ b3 p% ?, Z (*p)->next=q;2 i9 F7 A/ N& r9 u4 p4 M0 d
(*p)=(*p)->next;% S5 M& a m5 W
return OK;/ e0 `6 G' k, t; \0 O
}! t- K3 K5 i- b
int insert_cus(customer **p,char *name,char *air_num,int seat_num)' R& J! f; m2 t* q6 v
{, A( f6 d: d& g% T) y$ R* r, q! O
customer *q;/ Y/ \4 N9 l4 j( } L
q=(customer*)malloc(sizeof(customer));4 q8 o" L, r0 ]8 \# K& X
strcpy(q->name,name);' K! M$ h1 ~# E8 v4 c" y, G- |( \
strcpy(q->air_num,air_num);
# {0 j1 W$ U0 Q6 f q->seat_num=seat_num;: P6 J, D# p E8 O
q->next=NULL;
! y! l: t" S; S6 ] (*p)->next=q;4 R" u) S: D" a2 p$ E& U: V
(*p)=(*p)->next;4 N) p1 S+ C% Y# a; B
return OK;# D. \. @8 r% M0 z+ C/ W: T8 i# v1 G7 V$ u
}; A5 t4 @/ e6 [; [+ o
int book(airline *a,char *air_num,customer *c,char *name)* i! K1 m2 }$ @; U( N
{
& Y' w; x9 `& p+ d: F! k* f- y" f airline *p=a;
: e( M5 J4 {6 M$ }- d t customer *q=c->next;
2 n6 Q3 k! u7 S. R% A5 O p=a->next;0 H0 G* {2 q5 R7 P" I9 V- \
for(;q->next!=NULL;q=q->next){}! t; `7 a8 z7 @3 {1 f' |
for(;p->next!=NULL;p=p->next)5 S- j; w( z7 Q/ M1 ^( U4 _
{1 M. x1 [% ?) |" m( X; }9 T
if(p->left>0)4 c/ u+ k" O1 z/ |( K
{( o8 X1 p+ B' w2 I- U- ]8 F% ?2 m
printf("Your seat number is %d",(p->total-p->left+1));, |/ G' M/ w2 \( d( ~; Q
insert_cus(&q,name,air_num,p->total-p->left+1);
0 B9 }' C6 k1 H) J p->left--;
& w/ ^, M2 ~8 N0 X: M. X+ I$ z2 M return OK;
$ f5 E- C/ A5 N }
, G( v4 m! {2 V% _) s0 a% t else
. s1 c3 q' L* p9 d6 ` {3 m3 A% f m Y) ^; K- N
printf("seat is full");
9 C, x9 P) {- ?9 r! o* r C8 o return 0;0 w @5 n' Z7 ^5 m6 n+ E
}
, Y% G( e$ J, E$ l" A; e+ w }$ Y3 U3 N* k9 x3 z# [+ T+ s7 c
return OK;( d4 ^+ h/ T: @8 s3 l4 k6 A
}/ h; g' E0 t1 D. T
int del_cus(customer *c,airline *l,char *name)
6 o u: M2 Z1 t6 f! L{
$ }7 Z9 a7 Y: G4 c6 K+ e& t customer *p,*pr;0 G+ t! f' o X- ~# l* s# k$ z
char air_num[8];
7 F( R1 E/ Q% W5 w pr=c;' p% H' x1 q- R+ Z4 B' L
p=pr->next;
7 c; T7 S; d( P8 R- s. t$ E while(p!=NULL)
* n. n5 i5 m- J4 G# h {+ _ n0 J& G7 `$ ]) T
if(strcmp(p->name,name)==0)/ d4 @9 S! c" `- ~# u/ q W3 u
{6 k0 W9 z! m& F- t7 ~6 ^
strcpy(air_num,p->air_num);
- H' i0 S5 B, f l=modefy_airline(l,air_num);: v1 i N; X6 e$ |5 s' d
pr->next=p->next;7 N% b4 @6 R3 S; {' D5 X: v
p=pr->next;6 j5 m% X; x" V$ h
printf("finish!");
+ f2 Y3 a* v' R return OK; 4 m; i u$ ]9 H
}
9 n& q. V. W. L% O( ?/ q- d pr=pr->next;5 C0 j; s' ^& k+ @1 |$ q
p=pr->next;
* Y& B# P. }2 v( S& x& W }
5 D2 s) e4 W8 |- S, i3 Y printf("NO the customer!");4 v0 D5 p- H+ j1 N1 Y/ ?" p" W2 s+ h
return ERROR;5 z& p, k: U, W' I3 _$ N
}
5 C' x# o7 r& V2 i7 T5 \7 X5 \4 Z# Lint search_air(airline *head)
. F3 b5 e3 z9 l$ x{
, d) G% O6 S5 Z, i' q9 x: \1 S; c3 j airline *p=head->next;6 f" n! I" ?% E) x
printf("air_num plane_num end_place total left\n");
Z4 v: ^+ o' N: ]2 R$ X* h4 D for(;p!=NULL;p=p->next), \' Y3 G" R- G% Q. X
{
9 M1 @" t* E6 ^* W0 v- X printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
3 ^- z b/ D/ o$ f9 p }
d7 j8 f/ c3 M$ q8 I return OK;. d1 ]; {7 W+ [( A; Y. I
}
4 U0 c( g; O( lint search_cus(customer *head)' ?9 y$ N0 ~; g) n& g* g
{
: n0 `" m$ F! c) P( L2 n% n2 G struct customer *q=head->next;: B2 A2 p G+ b" O
printf("name air_num seat_num\n");
& }# j) E; z {6 \ \; R s* V4 l for(;q!=NULL;q=q->next)3 W5 H* @6 I" H' u4 ?% l7 k* w
{
& M# T& t. P: P! P& [ printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
" r# u8 Z$ h- K) h9 b }
& V, i7 |( H+ d7 p7 D! V! ` return OK;* N, ]- Y. | {! n
}
$ i3 J' o1 g9 A/ W9 bint creat_air(airline **l)& n+ A) [0 X* n: Q9 Q8 v
{6 a j4 ]% r0 u2 p6 Z4 D! _4 `
airline *p=*l;
. e1 [3 u% T2 Y# K& G3 O0 L6 `4 X# t9 Q int i=0;
: c7 g8 V/ c* l8 Q char *air_num[3]={"007af","008af","009af"};
; M/ w& s( p$ c/ X( E/ l2 G u char *plane_num[3]={"plane1","plane2","plane3"};
; }# ^0 S3 [& v char *end_place[3]={"Beijing","Shanghai","Tianjin"};
$ j2 r! p; j% R: p6 V+ A2 y int total[3]={100,100,100};: l0 ^8 P4 O7 n2 `
int left[3]={52,54,76};
$ V& W- H) [, g+ H& p for(i=0;i<3;i++); B* U, Z: {9 {% U+ U
insert_air(&p,air_num,plane_num,end_place,total,left);
- w8 A* U$ z4 N7 y5 ]- G return OK;
% ^' z8 A7 s5 p3 C}
( }1 u' U8 T! y; b0 ]int creat_cus(customer **l)
' w! a( [' I3 L4 r3 Y+ K{' L+ C4 K: I2 c9 Y
customer *p=*l;
5 `# H" F6 ]" l7 T int i=0;7 o v$ h) `4 f
char *name[3]={"zhsan","lisi","wangwu"};
. e; @' d8 T' P char *air_num[3]={"007af","008af","009af"};
; s+ h! K- l/ {% V: D int seat_num[3]={2,5,7};
, m9 c+ u; a' B. Q for(i=0;i<3;i++)0 T* L* ^7 q4 U, `( q3 @
insert_cus(&p,name,air_num,seat_num);
. W" R& B# w( ]/ }- z4 n0 g: p return OK;' e; D; u' V9 g2 U) J! ^
}
# ]& ?# D6 a- {6 X* j! uvoid main()5 p* E7 X: Y2 V3 H; i3 A7 w8 H1 d
{
( ^. o* H/ b5 a7 {# c1 L7 Q. x int t=1;
2 j5 m3 j3 y+ a, Y. D customer *cus=start_cus();
- {7 p2 p) B# j+ T4 q airline *air=start_air();, a c( N) u+ ?3 V
char name[8],air_num[8],ch;! V u" l' V+ x1 s, @2 _- n
creat_air(&air);
6 `9 R& e9 ~( ? creat_cus(&cus);
6 G# [' H' ^/ h8 j6 p7 W% ?. b while(t==1)
k: [8 ~ e& j& t' ~$ \ {; X5 J# l' W1 N2 D9 d) m) B+ A
printf("\n");% O2 V5 F% {0 f1 o1 I, m
printf("*********************************\n");2 x2 G$ [2 |1 \ A: ~& K
printf("* Welcome to air firm! *\n");* w3 m& S$ C- m V* b3 I- p* `1 u
printf("* book--------1 *\n");) k' l+ j1 e7 c5 J$ @) k
printf("* cancel------2 *\n");1 t1 ~: i# |" o Y* @9 I
printf("* search------3 *\n");0 f1 r W1 S' a6 [$ D+ \
printf("* exit--------4 *\n");
+ |0 Z5 T- f. ?+ R& j! ^$ D( S/ O printf("*********************************\n");6 e' G' b) X6 n: _, d
ch=getch();
2 I J: c3 [9 v- n if(ch=='1')# b/ w/ U0 V+ ?5 s
{
( q g2 r. Q$ A" K( |* k9 l! D! ] printf("Please input a airline number:");8 C. j9 y' a S( p
scanf("%s",air_num);
7 a+ g7 y6 P% k7 g1 l9 o printf("Please input a name:");
4 u5 x! S* V! C scanf("%s",name);3 v" V+ f& A- f | Y1 s4 c
book(air,air_num,cus,name);
d+ L, J$ @) _; h: c& } }
% O1 M! f6 k1 Y* h8 a b! S else# ]. u4 K1 L! H, u5 J" d
if(ch=='2')
5 a. T% ^1 R( V. w" z0 C {* G" A1 n% B: Y5 B
printf("Please input the cancel name:");
+ l# _9 E! e$ `7 z6 x* U4 U scanf("%s",name); U' G0 S" c8 U2 \0 y! P
del_cus(cus,air,name);
5 h: A4 |3 [: B p, q5 z }
+ T' U' t3 _6 O0 [- ?! `* S else
9 ]1 E: \1 R' W if(ch=='3')$ }* ~* k" V+ n
{
$ J& W/ P, ^. ~: m M. {- Q search_air(air);
" E J# E, y% e printf("\n");
3 X2 ~" R7 s( |1 m4 } search_cus(cus);
& @) G9 t- Y7 E6 N- N$ U- g }5 L+ x" y% a& ?' d$ q( v- x
else
+ b4 D: ?/ N4 a J l$ N if(ch=='4')7 k4 h; E7 Y/ A( Y# ?" }. C
{" c, l) K/ K' O4 R6 C j3 t
t=0;1 s" }! _& K& u8 E
} q. }4 Y3 }/ m; B) R
}
+ F& r' L$ T6 ?# @, t G}
) d q. r* l+ W+ Q$ ~& J/*任务:通过此系统可以实现如下功能:5 ]; K u- Z! u" i) P8 T
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
" q+ k0 f U3 K$ @% b5 l, T查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
. j) a- f% E4 N: A可以输入起飞抵达城市,查询飞机航班情况;1 h0 p, \! D% R: g6 n2 h6 h
订票:(订票情况可以存在一个数据文件中,结构自己设定): m1 [& c, g7 O8 C0 h5 n+ |
可以订票,如果该航班已经无票,可以提供相关可选择航班;
0 n4 y* A& O9 j5 b7 _6 ~退票:可退票,退票后修改相关数据文件; h" s2 i) r, m3 C
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
* X0 F Y' ]' q3 c8 A% A9 T修改航班信息:当航班信息改变可以修改航班数据文件
& r' C H+ P8 _: M; A, Z0 t要求:& C) z [, ~! Q3 k! T# K# n* p9 ?
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|