该用户从未签到
|
#include<stdio.h>
5 ]/ J& j. ], S/ G% x#include<stdlib.h>
( i( i9 X6 N& O; r. X#include<string.h>* h# P+ ]: h- `2 K
#include<conio.h>6 Y, c- h) x. ]$ z9 s& u% h+ t
#define OK 1- c {+ `% f) @( ?- X5 I5 b
#define ERROR 0
5 K% x1 u9 {6 M8 @; f5 K% d, U' btypedef struct airline{
' J' [1 x" U* t char air_num[8];8 S) }$ m E3 N
char plane_num[8];
1 L8 d) m# f7 F$ |# H% M char end_place[20];
: f. }8 }- T& q! C. |* ] int total;& i8 V% y4 p9 ?6 h/ C$ i/ M( O
int left;
3 b7 ` N, g8 i- C. X. T" h6 m" {. q" j: J struct airline *next;
5 T3 e8 V9 ]4 K- F}airline;
( c+ d7 O: z8 k6 m8 {8 {typedef struct customer{' m: v' e! v& M3 @5 @6 f6 y9 Y
char name[8];
1 F( O6 U9 Z- ` `( s& H char air_num[8];5 \( D# x9 Z% R2 i
int seat_num;
) o. n$ x( Q J" p* B) F! m3 I: a struct customer *next;
$ n+ e& j- D" k4 d$ U+ D$ h3 u}customer;, y- i8 O1 l4 ~
airline *start_air()' h9 {3 B* o4 \9 G9 H5 {
{
+ r; Q* _: \( a( {# R& M) Q airline *a;! t4 U6 A$ [& H% l
a=(airline*)malloc(sizeof(airline));
) D, I2 h4 q: ~ if(a==NULL)- s! U+ f) w9 E
a->next=NULL;
5 {' p1 _9 x) A2 e9 ` return a;' ]+ Q9 X* t1 n6 n5 y- L4 T9 r4 n
}" ~9 M8 U$ \0 v$ k% N' E
customer *start_cus()6 ^" O# y& @) w: k6 O) X9 J/ U
{
$ r& _. M" G. `% T& D7 u customer *c;$ a4 j$ {; X" M& g& X
c=(customer*)malloc(sizeof(customer));
4 @% Z' f+ Z9 a$ h( k if(c==NULL)
8 j; k6 q( N$ F1 Q) Q# R0 Q c->next=NULL;
9 h: H' [6 U- M2 C. V% n$ u! k return c;9 \2 i9 A& e/ X/ e& W$ K% _
}& ]& K; A; R7 I" M3 v
airline *modefy_airline(airline *l,char *air_num)& P7 v4 H9 V# m! u
{
! G# {; r2 H2 D. Z8 ]" l7 x* f i9 @ airline *p;
1 B; L. B- @. z* n$ t p=l->next;# w, Z3 S+ k- J" M# e3 K, W
for(;p!=NULL;p=p->next)! y1 @% z# o% T2 X1 k% Y- {0 V& a
{
+ G& Y2 a, W$ ?! X; Y if(strcmp(air_num,p->air_num)==0)
S9 v0 }5 g; n+ D {
) a3 U/ K' V- i5 e* u4 l+ ` p->left++;
5 N1 x" T6 w; b, m3 q2 r0 S return l;5 P+ z+ {. h1 ?. N2 g7 A; X& e
}# M" B7 L, C$ r( e
printf("NO the airline!");
4 y) \" _4 w. B& X' _ return 0;
: N+ t" A5 V/ Z6 M }
) i7 p0 }- E' t I}8 P. ^+ d: D$ a2 k" U$ [
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
* o/ P+ ^: F4 R5 V{
% ^' L7 d+ Q. u& ?- z airline *q;
M, z Q( G4 Q- V* P( k q=(airline*)malloc(sizeof(airline));( U- O1 h1 V" H
strcpy(q->air_num,air_num);. r) ]! {% o$ J1 u9 s6 b9 s1 L7 o
strcpy(q->plane_num,plane_num);, U. O; i% B' M y0 x
strcpy(q->end_place,end_place);
& O; T( C, n. j3 n4 S q->total=total;8 Y1 t9 V1 j: ?1 d" F" |
q->left=left;
! W% z) D- i" P q->next=NULL;
7 F4 \! i+ D5 Q4 X. c! Y (*p)->next=q;9 s. d9 C; Z& T1 O3 [
(*p)=(*p)->next;. b, j$ G0 J- k5 E& T
return OK;
3 P) K0 f# }3 N" r' `! } }3 d$ Z" D" U: @" N
int insert_cus(customer **p,char *name,char *air_num,int seat_num)' O( n1 S z; V" `5 U
{
! O" H' L5 o4 _9 | customer *q;+ D% n3 T6 M# ]3 J4 @
q=(customer*)malloc(sizeof(customer));
& C0 e5 a5 w" l strcpy(q->name,name);4 S4 l4 H- M, R* l1 v: w
strcpy(q->air_num,air_num);8 _/ q/ J) y* P( H1 {% b' |- ~# u
q->seat_num=seat_num;% Z. v2 u4 A, M8 f3 R( Q2 e0 T
q->next=NULL;3 i2 ^9 j& H* l( X( z! r
(*p)->next=q;
; Q' d' v7 _# r8 X$ F (*p)=(*p)->next;$ p' f3 G* c4 ^
return OK;; i7 b s3 R) t# U
}1 Y5 X( F1 j! {) A) k0 t6 V
int book(airline *a,char *air_num,customer *c,char *name)
- S& Z- K# t4 y3 g; r{
D3 M3 h2 T( s: h* p airline *p=a;
( l- J# l4 y" W: E! \ customer *q=c->next;1 o! H1 f) p) e8 Z
p=a->next;
( |: }2 U& u- X/ @ for(;q->next!=NULL;q=q->next){}
# y, k$ Q$ d2 n3 ^ for(;p->next!=NULL;p=p->next)4 P( ?: k' V+ o8 u/ p8 c$ ]5 E# q
{+ W7 x* Y) c( R# W0 o( M) H
if(p->left>0)
8 {+ p( X4 E% ], G) h8 f2 B% S {
f t& E# y3 j4 J printf("Your seat number is %d",(p->total-p->left+1));6 i# f! ^! k# @- z
insert_cus(&q,name,air_num,p->total-p->left+1);0 h0 s0 Q8 Y3 A. g3 f/ a3 K Z3 J
p->left--;) E. z' R; A4 x1 P% O
return OK;
; C0 z5 w& m( b; U: F4 v* v& v* D } g/ o+ B1 K! c! d: j
else
+ r# u9 t1 A- ^5 J1 Q {
' r; ^$ M8 K+ d printf("seat is full");
/ n0 E+ @; x- p7 i& x' j7 m return 0;( @# d6 p9 t" d; h
}: W4 h6 t9 U; ~" n
}
0 t- y" c# y8 I8 a4 E0 treturn OK;
9 W! D. A: L- i5 T3 G8 p+ z}
) ?- j4 a/ m6 m6 q* L6 Z7 i% D! T) _9 Lint del_cus(customer *c,airline *l,char *name)
4 S P+ G+ U* f9 ^{4 i, o6 Y. a; e9 x$ L& Y9 l
customer *p,*pr;
m. S8 _. _4 G' { char air_num[8];% B' o1 x! Z, y+ _
pr=c;
8 }' v% [5 r9 W) l8 Z: C# p p=pr->next;
4 I4 C6 R. u5 J( Y/ U2 Q while(p!=NULL)+ C: T1 \ Z! S# d6 z
{
5 l* S& y% R8 L4 ?! |* M if(strcmp(p->name,name)==0). ^+ C4 h/ Q4 ]2 P4 h+ h
{3 b& } y. [5 p: ]: W+ i( z
strcpy(air_num,p->air_num);
, W6 q; I$ f z, j Q9 d l=modefy_airline(l,air_num);
7 J+ a& ]3 a1 a- v' i pr->next=p->next;: ~; S5 q2 a+ {/ i% z( ~9 l, V; Z
p=pr->next;/ h9 t* B7 C- I$ Y: d& j* ~: W _: |% _
printf("finish!");1 i# S) t9 E" {7 f, Y6 p, O, g" c
return OK; ' x" q3 B+ z/ T) T/ B+ ?9 i
}1 |8 N, X0 i! b5 X! f) M# N
pr=pr->next;1 I+ X0 e. p6 U
p=pr->next;
& L! B6 K' O( }; n2 i' j0 M* L }
. q& H2 ~7 H0 h; ?/ w8 F( G- L printf("NO the customer!");7 S' h& u8 g& F) a: ]) F, }
return ERROR;% H' J1 Q w3 z
}1 ]* c+ Y4 d7 C, C0 r/ e1 e0 }
int search_air(airline *head)
+ a5 v) J8 o8 A) \3 V{0 P! d& u5 ^$ @
airline *p=head->next;
4 A/ ~5 m/ o1 n printf("air_num plane_num end_place total left\n");
9 X$ B% K* c! P! i R for(;p!=NULL;p=p->next)5 k2 q" U8 X) ?$ j2 w: [" h
{+ Q9 f# c% n; a3 N' D* O
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
, [7 _9 B9 A$ _" j3 I4 {% N: ^& M6 \ }. g0 W5 _$ R6 C$ ~* I
return OK;8 |" C9 @ c/ O# y4 a# i
}
' ]. [. G# e, Hint search_cus(customer *head)8 z V m8 V8 I0 U u( ?
{
: Y' q8 O+ z7 q9 Q$ R struct customer *q=head->next;
+ R* ?+ L0 c' M- d3 P8 h) x. ` printf("name air_num seat_num\n");8 p: ~+ x" W4 ~/ k+ i; c7 ~
for(;q!=NULL;q=q->next)' z0 W" d E1 q6 ]5 h! \7 V. w
{+ F7 X; x$ L4 h d, ~3 K! g
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);: Y8 `8 W2 v6 N p2 l4 h
}8 b- i/ ]1 i; F6 l0 E }
return OK;$ _6 R2 D. R* C* e
}( \" g' ?$ k7 n0 W% t, a
int creat_air(airline **l)
( ~( ~3 b) w8 p{
7 H2 w# x' F* B6 T/ X1 P airline *p=*l;) N0 Z1 M" r3 Z0 H2 e
int i=0;4 e" y1 \4 \/ ` `$ O
char *air_num[3]={"007af","008af","009af"};9 |# v, Z0 v% t( ?2 J. d$ y
char *plane_num[3]={"plane1","plane2","plane3"};
0 @; Y% m3 V. J$ H) U! g char *end_place[3]={"Beijing","Shanghai","Tianjin"};
' \% _& c" i. ?7 M7 ~/ v* m int total[3]={100,100,100};+ C6 K# X: Q. L
int left[3]={52,54,76};5 y' }9 [$ p' d6 G! U6 w6 S" a1 Z5 D
for(i=0;i<3;i++)
x2 S, i; S' L: j0 f* h insert_air(&p,air_num,plane_num,end_place,total,left);
! X6 {3 N. c6 `( I* j return OK;
) R7 f" z8 u) z# l, x, i, B# k3 v: u2 ~9 e}. s3 D0 d, V8 v$ Q- {$ Z$ I7 k; S
int creat_cus(customer **l)6 Q" I0 E1 {5 ^2 Q* A; e8 |
{
! g1 ?. L' y# y6 W5 X customer *p=*l;
" ]' N1 J2 ], |+ W& q: y' ] int i=0;
- ?! H) _+ X. `9 Y% p6 f3 l: M3 f char *name[3]={"zhsan","lisi","wangwu"};
! T+ u7 s0 W2 B2 S% y! a# L char *air_num[3]={"007af","008af","009af"};7 x- Z4 g8 G1 I1 G( A- K8 w; i4 y
int seat_num[3]={2,5,7};; T8 e Q- T! v! E G
for(i=0;i<3;i++)! p5 @1 J( H1 m9 P) I1 W
insert_cus(&p,name,air_num,seat_num);! m! `8 a6 ]9 q4 i. _& F
return OK;
8 Z1 {2 T/ E; h: a}8 z& I0 z. J+ _) n6 L
void main()* B4 k/ N! S: H) \
{
" L" E0 |9 A4 j0 k# d int t=1;; s* e6 J$ [1 y
customer *cus=start_cus();: X, `% m' ?$ Y& |' P) e
airline *air=start_air();
n& M; I% i m8 B char name[8],air_num[8],ch;8 h- X0 d* t1 D2 T
creat_air(&air);* w: `. F2 G9 ]+ H
creat_cus(&cus);
; V3 U$ c' S) c1 B! p while(t==1)/ E2 T- ~3 @& C) c
{1 s# V, C6 g3 i2 N
printf("\n");0 Y- b7 u! | j# q& j
printf("*********************************\n");
" @. X/ U9 a! `8 p printf("* Welcome to air firm! *\n");
2 a7 c D& P5 N5 ]6 C: X3 U" d printf("* book--------1 *\n");
8 D5 H d) I0 r. r/ D) Q) i1 J printf("* cancel------2 *\n");
! ~6 \! j4 i4 \3 {( J( R printf("* search------3 *\n");
3 v" a; L3 B4 K9 {, _7 o printf("* exit--------4 *\n");
5 L) \9 v8 l" |' e$ J! }0 s printf("*********************************\n");
# q2 l/ [) z: C ch=getch();# S8 b+ J4 u, }. |
if(ch=='1')
6 N+ h. L5 q, r, L {
3 s' j" E1 y( ^; a' X2 N i printf("Please input a airline number:");" x& y9 d- M3 P$ R c+ Y
scanf("%s",air_num);
) t6 W+ h# g+ F' m0 X( Y6 B) X printf("Please input a name:");6 V0 y9 T. `0 I% M
scanf("%s",name);
( M" w: ]/ e- E' a0 o) V m* G) s4 t book(air,air_num,cus,name);
4 ]5 q: |5 |8 s5 n7 y }1 Y- a# O' l5 Z9 y w D
else$ R# Y9 T# W& x" B3 P) L( T
if(ch=='2')% d! R9 L- g5 _( `, h
{
) W: m1 z+ S( Q printf("Please input the cancel name:");
4 Q' l) d6 J1 x scanf("%s",name);
, Y# ]) T+ |7 l0 {: p- t del_cus(cus,air,name);
$ d8 O+ L! l7 z! ^" D }4 e8 [; h) {" z9 t( ^% _
else
& p6 u* _2 p$ w9 V7 q% x- [+ ] if(ch=='3')
8 e) R9 N" A/ X: E! Q {' ?6 s% w1 _; _. b
search_air(air);& N \% Q4 ?+ i- o1 k/ X
printf("\n");
: S* n8 M. D1 b9 y$ p: ]+ k- l3 z" L( w search_cus(cus);
, F7 w4 \5 [: U- U+ C }
; ^( i- E' z5 E- Q& e9 r" P, p* S$ o else
' \, L, O" ~+ D6 A& u9 k+ p7 D if(ch=='4')
7 p+ i* R5 @! O8 k. p {) R4 K8 G% C5 ?% h7 i7 }2 c) K
t=0;
. S$ N; T1 M+ S& R, L }% [* K2 [% L( |2 {
}
5 ^( B* A! Y0 }) a8 y# {}
& h0 X/ h& g. I/ e$ S* t, X/*任务:通过此系统可以实现如下功能:
s- r' U" u- T7 L" |录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)1 r; e- E% f- h' n, Q
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);5 J y2 ]4 l8 @8 [" m1 l; o
可以输入起飞抵达城市,查询飞机航班情况;* H1 Z; i F, d6 @7 d6 o0 Z2 u) N
订票:(订票情况可以存在一个数据文件中,结构自己设定)* U# m/ |8 E3 }
可以订票,如果该航班已经无票,可以提供相关可选择航班;
$ i: {2 r0 M% g6 w' |退票:可退票,退票后修改相关数据文件;: [' A" a/ ?- f' z/ S7 B
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
. L5 N7 n& a& O- L1 i: y修改航班信息:当航班信息改变可以修改航班数据文件, _+ [5 _, J: q( @2 A, h0 y
要求:
' n2 h' d8 n( }# x7 }. ^根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|