|
#include<stdio.h>5 I9 @ N p* j, A; T+ c8 O2 O& [
#include<stdlib.h>
% d3 p& N! K* S: N/ G#include<string.h>
" p! i, z( K% w# {6 ~#include<conio.h>( m7 ^6 |. V* n/ W; x7 r
#define OK 1
! b$ m8 J' T3 U6 r1 `#define ERROR 0
Q+ i, B5 X, Q- @+ H8 ytypedef struct airline{
: f5 t/ B6 W4 z: A char air_num[8];: d8 s$ p5 I- g/ d' ~4 K
char plane_num[8];/ }: ~6 U1 _9 ?( w1 t: m
char end_place[20];
1 U* x. [: V& D; Y int total;9 j+ y. J. ]3 |. P! z5 _$ ]; ^' j; V
int left;# _: c2 }5 l' c
struct airline *next;
- @( z& S! o! X3 x8 ]}airline;
0 @, b* D. C' G. g9 _+ u+ B; Y! Stypedef struct customer{8 o7 ~+ |7 b6 V# G0 W" K; D
char name[8];; R T) }2 g$ t. l2 v1 S) I
char air_num[8];
# \' v8 }. u! \! ^5 X2 o# A5 O! L+ ~ int seat_num;
( L( P6 N; }& n9 F% U* A struct customer *next;
- V8 n8 r B: l# N) h! h}customer;
/ f% n' F9 e; u+ ?1 ^airline *start_air()
, a' H+ r9 o# u' z{) X' T7 x3 `& ^3 _$ }9 h$ ^
airline *a;
5 b( y- d* q5 \! m a=(airline*)malloc(sizeof(airline));
' i4 c9 h- h$ [: h( | if(a==NULL)$ m: N# O' B( O
a->next=NULL;
$ w* c9 ^% l q1 c return a;
; y& G+ D( g2 x8 q' t}, G- D7 B5 M& ^# ?. c. L* N- X
customer *start_cus()
! E# N% g# X# Z$ U/ v, r{
; ?, _7 h! \9 j7 {( p! I m) V& { customer *c;
% Z$ C0 j. M( p6 w7 o* Q c=(customer*)malloc(sizeof(customer));
A4 B6 T0 ?: d8 R- |! q: r if(c==NULL)- F' x: k, @ T6 f
c->next=NULL;
! m1 E5 O- o1 x return c;
; U( w. t; x! B/ ~. w" Q# ]}- n8 N/ W7 s4 ^
airline *modefy_airline(airline *l,char *air_num)
* J$ C% c0 M/ P! ~, l" F: X{
1 q# K: A4 {3 @% H; f }; Y0 K9 @ airline *p; q0 d7 I, R1 j$ ] ?% @
p=l->next;
' a4 j9 z5 i+ x( z for(;p!=NULL;p=p->next)" c2 y) j7 h: r! K
{
, C6 V1 k/ [" g if(strcmp(air_num,p->air_num)==0)1 M6 c+ E+ z% c
{% ?( c& \2 d8 [# s
p->left++;0 k7 N: W0 f9 P/ K# H6 \" p# C
return l;
2 s$ ~' Q5 s% e* R }* V. M6 z3 C8 e! ^: @) |* b E
printf("NO the airline!");
) {* P6 R$ x+ m, d3 } return 0;
( |5 A" ?# K. K# }* \2 T' v @ }: W6 o7 n0 g& r) Z
}% x: `/ F( V$ d% U- [
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
. q. S: e4 O; N4 H, I2 ^$ Y{
4 N" w' j8 M) U8 K airline *q; |- \ u, v; A/ t2 R, T$ ]8 g
q=(airline*)malloc(sizeof(airline));
: a2 X K2 b; H/ L9 N- T* [/ m6 X strcpy(q->air_num,air_num);
/ e' v* O0 o% {5 k( k1 m6 \ strcpy(q->plane_num,plane_num);
: g' J! H' [! u @+ V strcpy(q->end_place,end_place);0 W7 J2 W& ^9 ^6 |# H
q->total=total; I" Q/ b, X( M7 z0 ?" d
q->left=left;
* B) R# Q- Z4 B: W/ N: m5 R! c q->next=NULL;
4 u: }8 K j1 J3 x1 R (*p)->next=q;/ {8 `7 B! e7 j6 e) c: z
(*p)=(*p)->next;
% k: o4 y- a6 o0 O" A9 U* T return OK;) M9 N& H2 ^: h; L, l4 x
}
/ ?0 @3 |+ h8 X- P8 J! vint insert_cus(customer **p,char *name,char *air_num,int seat_num)
" L: o2 ~5 b' b: H{
7 L* q ~9 J/ O: i7 B. s7 b& L$ r customer *q;
. B0 j( m3 w+ u q=(customer*)malloc(sizeof(customer));9 w# |5 q/ O, J" `) m
strcpy(q->name,name);* g# t( S6 v* X$ K; q: z: @
strcpy(q->air_num,air_num);
6 `# I% V1 H( t S' r. v- W q->seat_num=seat_num;6 Y" p, C: ]$ D ?% _
q->next=NULL;
# l2 B+ T0 Z4 g/ _! ` (*p)->next=q;
. F% _$ \( @# j% L$ O" e (*p)=(*p)->next;2 w& R, e1 X) W; l
return OK;' _5 Y- ]; v1 k. [" }! e& G \
}
9 A$ u a' }, a6 G0 ]( i( F6 wint book(airline *a,char *air_num,customer *c,char *name)7 @! A Y) u1 |5 m4 |
{6 H1 s* H: K; F7 M
airline *p=a;
" y0 n; b! d. W# _ customer *q=c->next;
( [' m" U$ O H8 c: s p=a->next;
" n$ } C2 r3 D% A% E for(;q->next!=NULL;q=q->next){}
/ `8 h# F6 z6 q6 M3 _9 O1 K for(;p->next!=NULL;p=p->next) C# x, E! _" V S* X7 Q
{/ ]& A/ U" {' k" s
if(p->left>0)3 O6 _8 I: J4 w& @% ~7 {5 c# L
{
& }- ?+ |9 D6 \7 C printf("Your seat number is %d",(p->total-p->left+1));' s6 ~' @' \" x' u% i
insert_cus(&q,name,air_num,p->total-p->left+1);
- Q1 ^3 `' B) {2 T) X p->left--;
6 x* C2 G8 y: B+ @- y return OK;9 O" h: H+ F% g2 C" g
}
+ T! W% c, w) L6 r+ }3 Q else
% H7 v O$ B& p& E/ }7 h {
3 R' l/ U' D0 y4 p6 B& k7 H @4 ~ printf("seat is full");
7 z, V( i% r9 o0 w5 F; e E. Y: b8 K return 0;
! B0 q }3 b3 `) z }9 ^: j* y8 d( Q: R- |/ Y
}
+ z# ]0 A* w0 j- nreturn OK;
" q( y9 R" O2 `4 m8 i4 f# p0 S}
g& z! l- J$ ^# k' W Aint del_cus(customer *c,airline *l,char *name)! |/ I; L: W0 w, I1 T
{$ N$ X$ _! Q; P; ]+ ^, o
customer *p,*pr;9 `" x. N+ s- d+ y
char air_num[8];
" o& L e) O0 q. [, X) i pr=c;
; u q3 [& w2 x p=pr->next;
1 A7 [# Z- J( @1 h while(p!=NULL)
! ^% {& m! j/ ]/ Q1 |* P/ V% J! | {
: h9 V' E# W4 l5 N5 D& ` if(strcmp(p->name,name)==0)0 Z* D e5 W. U: `# U: r
{$ Q5 P/ Q3 E8 G' e
strcpy(air_num,p->air_num);
7 E3 h; n, C4 |+ d+ ?* J0 M l=modefy_airline(l,air_num);
7 x. _9 v8 T* u# z) p) Y6 J, F) Z pr->next=p->next;
4 R- C$ e- C: N* }$ V9 M/ x- J: C# ^ p=pr->next;" @% g5 l* L2 i \3 C
printf("finish!");
' M) d- x/ V2 D0 E% z. H$ u. \ return OK; ; t' J5 k8 _7 g/ e' v6 l
}8 t' ]7 _( ?4 |, O' e: U" ] J9 H
pr=pr->next;
( G% r1 ~, L4 I5 `7 H$ l4 s p=pr->next;
) Y# s& e/ C3 j& w }0 F$ |6 C" K3 Z J# O( `5 J
printf("NO the customer!");$ W; a, j- g8 J& Z/ Y
return ERROR;, X9 f8 i4 n# D: q0 H9 K
}
q5 c# a3 ~2 H" z! i$ {" c' i9 sint search_air(airline *head)
5 f5 A. u, h4 t$ n, q1 h{% `' V% W# I2 E' ]0 L9 H7 \
airline *p=head->next;" O( g( A# t& n" B
printf("air_num plane_num end_place total left\n");2 D# u( g7 L0 C8 T+ W3 I: z
for(;p!=NULL;p=p->next)
2 A) v4 _5 Z; [. e( K. A {- o: {* H& W4 o6 g1 s/ f
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left); F7 Z2 C! {2 y, P+ u
}. f1 n( I7 j8 V
return OK;
% I# Q; g2 c o& N. u, ]}& z+ ~! V" X; U7 H7 w, v
int search_cus(customer *head)
( A$ m, f) u; J- h{6 q: u0 k: k! [- U- [" h
struct customer *q=head->next;+ j, O1 G6 w9 ^. d1 }. M
printf("name air_num seat_num\n");
8 \4 T7 k5 J. Q2 s- Y$ d+ o for(;q!=NULL;q=q->next)2 L$ l; h+ p, \- Y; U V4 X) H
{5 G- M% ?: m& B" V v
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
& @! A' k# d! C; z9 d6 x- r }
4 r& L3 i4 v" s1 m8 C. Y$ i return OK;1 J2 Z! j7 F/ T7 r% l# n' e" V
}
4 x0 g( t) Y5 |* D1 T# L$ dint creat_air(airline **l)! G( U8 z- c+ t( p
{9 Z& f8 ], j1 Y+ s
airline *p=*l;, _8 X' R: ]( W+ B. M4 p
int i=0; J" ]" \% K% f
char *air_num[3]={"007af","008af","009af"};' m0 c) r, c9 O/ Z2 S" s& ]2 D
char *plane_num[3]={"plane1","plane2","plane3"};3 J0 N0 ]. i) |0 L8 O, R
char *end_place[3]={"Beijing","Shanghai","Tianjin"};
3 V. b: M" L' n! F int total[3]={100,100,100};% ]" g j. Z" v) ^
int left[3]={52,54,76};
* P8 E- r2 A' R for(i=0;i<3;i++)
" ]0 b, [6 j5 A insert_air(&p,air_num,plane_num,end_place,total,left);
/ z. c& i r9 n5 V k" H1 [ return OK;# R( N0 c3 ^, r: J5 }) D
}
9 X/ N2 s! \$ I$ sint creat_cus(customer **l)9 U6 F2 ]4 N$ S3 P
{
( v0 ?9 I( m# r& F customer *p=*l;4 ]6 p$ U6 U3 {9 Y
int i=0;
: ? l$ s: m; d9 V3 b& [( M char *name[3]={"zhsan","lisi","wangwu"};, p% C) a+ d* @1 J% `. [
char *air_num[3]={"007af","008af","009af"};
1 T" y# N& j. v9 h8 ? int seat_num[3]={2,5,7};: `. j4 R! i* x2 r i
for(i=0;i<3;i++)
1 l) \9 l) q8 J5 H# }2 C; Y7 j) x insert_cus(&p,name,air_num,seat_num);
) c% c/ [9 D/ u! ] return OK;/ [ U+ ? @; ?2 M5 K9 w
}
2 a. `8 o, x. A$ ~) Lvoid main()$ f3 z7 `/ {% O" N& E9 f! K
{ O1 ~) J0 I/ F0 Q) G( f
int t=1;! Q/ M$ S' r# u3 e3 p
customer *cus=start_cus();* i& u( S' a% ]" S. E# v7 B) S% a
airline *air=start_air();' h# Z) K+ @3 f) x
char name[8],air_num[8],ch;
3 F- E4 f- r2 | Z. Y: k creat_air(&air);- V. V( o- n1 H0 E1 _$ F% b
creat_cus(&cus);
. m2 p5 J' [/ K4 N while(t==1)
$ `8 @8 Y# R6 S9 k0 N+ O {. o' s6 _. l4 [
printf("\n");0 h$ `" ^* @4 @, h/ g
printf("*********************************\n");7 Q2 Z8 T* t$ ~% W; Q
printf("* Welcome to air firm! *\n");4 r2 c/ ]# l/ X9 W& u7 o
printf("* book--------1 *\n");
2 @: u& h# E. O4 m printf("* cancel------2 *\n");6 t0 V5 k! j6 O6 W: S+ J* G
printf("* search------3 *\n");: N% v0 k4 ^- G. _4 D
printf("* exit--------4 *\n");. f& ~, f2 ^9 g$ D' @9 R
printf("*********************************\n");" W4 c( E4 C! D/ g- Y
ch=getch();
# {( s6 m/ @! U& j if(ch=='1')
; @0 A- ~4 j& p5 ^$ h {
B4 t7 }! W) ~2 f3 w. }7 n6 j' {' D! } printf("Please input a airline number:");
1 R+ L: b3 M# S scanf("%s",air_num);* d3 o- K- y6 N" @" D% j: ~
printf("Please input a name:");2 V+ F4 |% G3 z, q$ l/ V1 m
scanf("%s",name);! G m7 p" t, o
book(air,air_num,cus,name); _5 Q" ~0 W5 X* x5 V" S+ g
}. `% U4 V7 J) v+ i0 Z6 W; s. {: [
else
7 m* B4 s' r$ n: p if(ch=='2')0 s! Y5 W+ i% q0 E9 f# p
{
* `9 }$ J' s) l* Y printf("Please input the cancel name:");9 \" I6 ~8 i! Y7 A' Y2 Y4 y3 k- m
scanf("%s",name);
2 M6 H( C- D% b2 a5 r. h- { del_cus(cus,air,name);3 i7 b$ k$ g! Q# a
}
9 C3 a8 W+ t6 q3 {; W1 V else
* b# R; \2 }! i9 A; P& F% e1 p0 [ if(ch=='3')- ]- S: e0 j+ R' m+ o
{
- u7 V* N* W5 u$ F/ i, \+ ` search_air(air);
" Q3 @7 L0 i4 T) S: t E printf("\n");
! V3 M! f/ M, I3 C search_cus(cus);* K) K9 L- [) V. i% v* a# Q3 i
}2 {0 ^* x5 z$ b" E/ f. U6 i
else
! k4 {6 w, \1 L+ i% o+ i if(ch=='4')" `3 q5 w. a& \) ^7 |& [$ l
{3 D9 W% e8 L- n! @# W0 v! a
t=0;
' C6 y8 ?* u# `" U0 a" _9 W/ A3 U }+ x6 ~- @ ~# n6 w: |
}( O* K6 d, k; t( q- T
}3 m8 @! V4 L& y+ A2 Y$ }3 R
/*任务:通过此系统可以实现如下功能:
+ v6 f* T- J' M" l! @0 d录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)6 N c; f2 l# ]/ D& V6 _( ?
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);! F* [1 ^) p6 z- Y
可以输入起飞抵达城市,查询飞机航班情况;4 }7 h: C! I- m! K# h
订票:(订票情况可以存在一个数据文件中,结构自己设定)+ R2 Q0 B, Z1 L
可以订票,如果该航班已经无票,可以提供相关可选择航班;
6 _, B/ r9 ^6 m2 y1 Y0 _7 [) x退票:可退票,退票后修改相关数据文件;
* ~ Q. o" W& Q+ j' g" U客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。" V. Q' _# p. ~2 l3 {
修改航班信息:当航班信息改变可以修改航班数据文件# V4 c# ~: z# [5 U! ^1 h
要求:# }" q8 l3 Q9 O3 H( G' g
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|