|
#include<stdio.h>% p' T z/ v0 m. s
#include<stdlib.h>
O5 @- q7 ^6 D#include<string.h>
7 \ K; t% O. b7 ^#include<conio.h>% `+ p/ b- I1 @6 @. ^: @
#define OK 1
/ f% G v! e* r# v' I! n9 N! \#define ERROR 0 C1 ~. `' ~0 U7 j
typedef struct airline{. Q! v! Y" q e
char air_num[8];
& Z; C) K: p6 j, t char plane_num[8];
' _9 P" R* F" y& o) m% Q! `9 K; F- { char end_place[20];
: G: b8 s2 T4 S8 D" V3 Y9 [1 [ int total;
" g1 Y2 _# O5 s6 Y8 p! A: ^5 s9 E2 b int left;
( I& S8 h& C8 g$ w. o* K; c struct airline *next;- a$ b1 w+ U2 ?2 f9 Y, ?
}airline;
% t- P* b2 \- L I6 I/ K) ntypedef struct customer{
/ {; m+ E5 q& N: f3 j char name[8];/ G! P F+ f! J+ x/ G( J! \
char air_num[8];& Q1 D" I/ h9 }$ g3 W c' l3 i
int seat_num;; b( u4 K# t; F* D- d2 X
struct customer *next;
2 z+ J* T5 j& p+ _! e7 G; G7 Q0 v}customer;! B* _3 g/ n5 L4 c" [ e8 A0 n3 a
airline *start_air()
& n9 r& u5 A# d; ]% x{
) n3 u3 q8 D8 C5 b5 e airline *a;
. F# j; j* S) z4 [/ T1 E a=(airline*)malloc(sizeof(airline));
& L0 t6 }! W, k9 W7 i" m8 P# h1 g if(a==NULL)' @' ]# H8 \7 S
a->next=NULL;
- _+ b- D* K7 G. V% y% k return a;; {+ _* y) d& ]* \7 M
}5 x& [$ h1 Z. `( P
customer *start_cus()0 [3 j/ L* H; J0 w; ^9 i, l, B
{
# k8 r( H: Z) \ customer *c;$ ~" `! i' K T
c=(customer*)malloc(sizeof(customer));
" z3 ^* f6 j; u! o) _% l% Y) I if(c==NULL)! z& x4 {; {$ O( T6 G) p/ v
c->next=NULL;
1 D, S$ X# O+ q return c;
( _$ |* Y& K8 e8 g4 J* m}4 q" @! R4 ?2 f5 A5 J9 C1 N; s4 N% V
airline *modefy_airline(airline *l,char *air_num)
9 _. Y5 u6 L. ~{
) n d u5 p3 C* {' v airline *p;: T$ H' _/ y* q
p=l->next;
! S2 g1 h8 p6 X( {1 }4 ^! f2 ]3 z for(;p!=NULL;p=p->next)" Q* V1 o- o" K4 x _% y1 {# ]/ j B
{
) v3 J; R2 n& n( M' m; b if(strcmp(air_num,p->air_num)==0)
5 T+ n P5 Q5 M3 `- I0 w {7 W! x" i, b& n- u u
p->left++;
( [; j. M8 G: o, L/ g* P2 Y( T8 u, J0 y return l;7 E9 U; T$ r8 T8 \6 \
}4 b% \3 ~& L( v
printf("NO the airline!");
8 T! L5 c" o: t8 z3 J" L return 0;
) t( \, v" u* G }
5 ~- [* l5 c- k6 J}4 |$ ^& M$ ]# o K6 e9 u" o
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)6 ^- \% i# r$ |+ W
{
, L6 X% ^! J6 y* ` g1 c) [ airline *q;
1 j% W" z0 _) Y# I; d q=(airline*)malloc(sizeof(airline));7 u5 G. O! a8 i
strcpy(q->air_num,air_num);: {0 b, I! ^1 m4 P7 Z8 q
strcpy(q->plane_num,plane_num);- x1 u; C6 z. ? x v
strcpy(q->end_place,end_place);
\, h, ^1 a. x2 X q->total=total;
$ p+ H) W! r' c. X, D, p" p, @5 n9 d q->left=left;: q% v) F) ~& k/ K
q->next=NULL;
: W0 e" I$ T2 z; h! R! i (*p)->next=q;) K3 p$ z F7 e" r
(*p)=(*p)->next;
5 M: ~! t7 `- w, T" O& F return OK;% z9 `# d+ {. i, {5 F7 z9 m
}
7 P+ T2 {' }" z, d- }* {int insert_cus(customer **p,char *name,char *air_num,int seat_num)0 ]8 U/ Z" g, e" U; }4 E
{
( m$ X3 ^0 J1 h2 u4 S$ W! y customer *q;! g b+ F$ n) Z! F& ]
q=(customer*)malloc(sizeof(customer));
8 y+ A& j+ r' N4 c: {/ d strcpy(q->name,name);$ h- Q- W3 y0 @/ l5 a! ^
strcpy(q->air_num,air_num);" D* b5 P2 R# l) \8 }8 d& `
q->seat_num=seat_num;5 q! g+ {) ]- e& G
q->next=NULL;
9 U! D. s: I1 X, o0 L6 n( T (*p)->next=q;
- b9 W1 n' ?* w% e (*p)=(*p)->next;5 r3 Q- C! s$ [" M. U
return OK;
- Y' A6 P2 L5 D2 N7 p( C* u}7 o7 z5 H" b$ Q' N- t3 }) c5 b
int book(airline *a,char *air_num,customer *c,char *name)
; F+ c. @, L! O$ ^! \{5 @2 k E; Z, x2 }2 ]# }
airline *p=a;
* S. ^# _+ D& I+ \) A+ k2 F customer *q=c->next;
& h. }+ R1 p7 D, q p=a->next;
6 u& ~! ~: A% m8 V6 _ for(;q->next!=NULL;q=q->next){}
9 M2 q# s; r- c" v for(;p->next!=NULL;p=p->next)$ t+ b# U" {. Z6 u# b0 S
{
& E/ m" }1 ?* f4 `0 | if(p->left>0)
}! o% a6 ?0 S7 \ {
$ i Q5 [) a* D |% u* W, `. f" p printf("Your seat number is %d",(p->total-p->left+1));3 E: g' h& O4 X/ I3 O4 A# D5 X
insert_cus(&q,name,air_num,p->total-p->left+1);6 E- T9 c Z1 d5 U7 x" x
p->left--;! Z% b0 z& g' R: `/ z
return OK;+ H6 A' g j5 N6 O! u( M
}
$ f# n. r% O. c2 p% K else
/ p. V0 }# C& S, z3 a {
8 Y( K: d' E2 Z3 h5 b' N/ h printf("seat is full");+ h: e X/ W, U! u5 x
return 0;$ X0 b" i" y$ {- V6 c+ y) ^5 D
}- ?- v2 p. a, w J, H
}; J& s) m; D; e$ j) ]7 L* y
return OK;. A: y6 H) M t- O
}
1 k3 I+ Z2 u' C' b _int del_cus(customer *c,airline *l,char *name)6 s& o/ [$ ]( v' ?2 l& @
{
' U+ d7 X1 u, W) t3 X customer *p,*pr;# l- M, `; | ]& N2 c
char air_num[8];
2 n, m( \- o8 T8 A pr=c;* c j" B7 o0 V, V( B0 f d
p=pr->next;# t% Y& f: r/ I5 V) S8 S
while(p!=NULL)
9 {9 F% Z" o7 h' r8 E) k {* g8 C5 m" i* Q) L. T, V
if(strcmp(p->name,name)==0) @: G. K; F1 e
{
: Y y: \ n' B strcpy(air_num,p->air_num);2 F3 k( v- t* Z! Q
l=modefy_airline(l,air_num);8 C2 W8 N$ i3 T. }7 B
pr->next=p->next;
5 O( R K. r m p=pr->next;& U9 n/ r2 J2 v$ c1 @
printf("finish!");6 T- D( u) k& L; T% O4 b
return OK;
2 w1 A, n! k% j! T' H; e }
9 j( Z, W) x: W pr=pr->next;$ x! [9 _; y2 A" u
p=pr->next;
9 y+ s% e7 |- c! B, @8 } }
5 o* k1 [. n2 C printf("NO the customer!");7 H0 n. B- ], {/ P! S* c4 S
return ERROR;
0 [3 U. q h- x4 L. v5 D}7 r" }) M5 |' P9 l! i2 r% u: }
int search_air(airline *head)5 P; r- D8 A; E) z6 `: ?
{. b! A4 n4 p7 T
airline *p=head->next;* d4 I8 o, M8 S9 [. n1 l6 `
printf("air_num plane_num end_place total left\n");
; E5 c: r) k6 ^) H' _* Z for(;p!=NULL;p=p->next)
7 E: E9 ^/ ^3 K } {3 s, f: k. k) |
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);& K% V% B* f! O; k" Y7 X
}
" |5 [# g) T& f return OK;
1 v" ~9 ~3 T+ V, D}( v) B% ?6 ?7 {) U) Q1 P
int search_cus(customer *head). e- x2 E; I+ q5 S" P8 h- |
{
# X q4 _4 D/ A6 x5 t struct customer *q=head->next;
$ @$ K! t4 `' |" {( M F6 g printf("name air_num seat_num\n");! A0 D1 Z, A: p
for(;q!=NULL;q=q->next)! [+ s& x, N( X9 ]9 F- w6 U
{/ I# | d3 U- P0 b O) B% j% [
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
1 x$ ~; n+ K+ }( [6 T& B }
6 v N9 p2 j- S return OK;& f8 a0 ?! A5 @& P4 T3 t
}
' n% A; D( b( V) E8 Rint creat_air(airline **l); q) P" `1 }$ n. j' j# t2 S5 k
{
4 ~6 I7 O: v& p- E- u0 b$ d airline *p=*l;
; n$ X# x/ Q" g Z+ ? int i=0;! x% t! o( _5 v; x
char *air_num[3]={"007af","008af","009af"};
& D% F& D3 Y0 y( u# E char *plane_num[3]={"plane1","plane2","plane3"};
. S) U/ G5 d% F5 U! { char *end_place[3]={"Beijing","Shanghai","Tianjin"};
) c( F( W; q( C5 g5 [ int total[3]={100,100,100};
8 [/ j1 F! A- z int left[3]={52,54,76};
" Y$ V+ P4 B9 D+ n for(i=0;i<3;i++)" Q' k2 u! j" e! H$ w* Y
insert_air(&p,air_num,plane_num,end_place,total,left);
! ~- g0 F2 H5 ^ return OK;' ]% s( w, W! x. |* g
}
% U- Y" @ o4 k h( Zint creat_cus(customer **l)7 {2 T1 `' `6 H/ T6 L- X
{
y+ M: j$ f; O! z customer *p=*l;0 z5 I5 b4 A7 }4 i# Z; I$ _
int i=0;% ~- M8 C; d* Z" g
char *name[3]={"zhsan","lisi","wangwu"};
0 o* K1 }- b. J( o6 s. R char *air_num[3]={"007af","008af","009af"}; o- ?6 R8 T# x2 k3 L: \1 h9 T
int seat_num[3]={2,5,7};& h! c. d7 U0 }$ B& d) o- A. y
for(i=0;i<3;i++)
+ g' r2 ^& a2 i. C2 ]) E insert_cus(&p,name,air_num,seat_num);
, f# L+ g! T2 Y7 z: X) D. {3 a+ ~6 F return OK;5 ~3 l+ m8 p# |+ m
}; |3 l6 f I& ]! T8 V
void main()( p: K( E' g! |* ?; t# Q9 n
{9 z& |% q) n0 T' H3 }- t- L1 g8 Z2 Q
int t=1;$ o4 i3 l4 b) v. v
customer *cus=start_cus();
3 d. ]; C4 a! b' _ airline *air=start_air();" p& C0 p' j; o$ g4 q: V7 s
char name[8],air_num[8],ch;
! J% K. r3 ?- P9 D# N' t creat_air(&air);# P9 A' M2 }9 a/ ~
creat_cus(&cus);
2 s2 L# s5 z2 h5 `" \7 \0 j6 X. [ while(t==1)# Q6 a: A/ s6 T) I
{# o& ]% v+ m0 K c q8 A m' B# s1 X
printf("\n"); V1 C$ o6 Y: L* f) y
printf("*********************************\n");' ^" r C _( p. p p/ C+ h# R
printf("* Welcome to air firm! *\n");& o; V C, Z3 D- j5 I8 N- }
printf("* book--------1 *\n");! |0 ?, N" a. R& k
printf("* cancel------2 *\n");
& t' y! J2 j" L$ r) t" I. q: R printf("* search------3 *\n");8 y' g6 w H* Z0 |
printf("* exit--------4 *\n");- x& W% u' p& y" |- V2 q! F% A9 I& D
printf("*********************************\n");' ^7 f0 L* J5 ]& M$ r A
ch=getch();2 v: \7 Z1 i* G/ c* G& c
if(ch=='1')1 I b Y: z7 w
{
% {& Q X' n6 y; N0 F5 V. A5 b printf("Please input a airline number:");
* }. E2 ?$ u& [. b) h scanf("%s",air_num);
+ n) K5 \* N5 p3 S7 f printf("Please input a name:");) ^& q+ z Q% {- R
scanf("%s",name);" {8 r, M1 I6 C, H! l; B
book(air,air_num,cus,name);
$ z' M$ \( ?; Z; d1 S }
& c$ o) A3 O5 j. \ else. l4 m0 ?0 V- O. ~! ~. K7 z8 A
if(ch=='2')
) V) @& l3 R7 l0 L @ {
* f' W, l6 g9 }6 B8 ]2 ` printf("Please input the cancel name:");* y& |& Y: K3 q/ i
scanf("%s",name);
, v0 _8 n" M+ ? del_cus(cus,air,name);
$ S* V* N4 n( |& G8 p }. K0 z% X2 t2 h6 d
else
L9 J1 x6 N. c/ m" h) v7 [# h if(ch=='3')
! y& a: y2 X$ J- R {
U, ]$ T# f4 b( b6 g# J7 q search_air(air);
. z. r3 P6 w3 q% v7 f5 x' G. O/ _ printf("\n"); 2 c' @& n2 S5 N, d. j8 i; B7 A( H
search_cus(cus);+ A3 U) L5 n2 p0 F: ]
}( U: x, ?$ }2 W; x# N
else- ~; ~$ m7 r. Q2 Q
if(ch=='4')
. B1 ]6 P L/ B {3 T6 R5 M2 r; A" t- l9 U
t=0;5 e& o- g6 C* G! P
}
, h: Y3 C Z) d2 a. v }
' e$ U* U+ [) g e}
' V0 h+ G; u) f* G. z! Y* X/*任务:通过此系统可以实现如下功能:
1 d" n# C8 _: D6 Y录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)2 J- j5 R& I# {+ b; E
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
& B( } `/ V8 M; k2 T可以输入起飞抵达城市,查询飞机航班情况;: M4 S& }0 n6 Y C6 O b
订票:(订票情况可以存在一个数据文件中,结构自己设定)
) t8 c$ t* H/ a3 `/ A可以订票,如果该航班已经无票,可以提供相关可选择航班;
4 ?3 A! E W! X退票:可退票,退票后修改相关数据文件;
# L9 @) `9 ~! N3 E' x0 |客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。& \ ?" o* q: J1 I. e* D
修改航班信息:当航班信息改变可以修改航班数据文件
9 b- Q/ d: r$ w( Q1 f& @要求:/ z: G/ s+ }$ X" p
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|