该用户从未签到
|
#include<stdio.h>, X# {, Y' E9 C
#include<stdlib.h>
4 o: E4 p+ m9 t+ ]#include<string.h>
$ K: j* m7 {# Z+ H* |+ j#include<conio.h>0 U5 n! s( b2 T w
#define OK 1; }6 X. d: T* A& z6 n, ^$ O7 G0 v
#define ERROR 0
3 J( ^- i4 D7 ~' W/ J0 qtypedef struct airline{
& U% W! }, o' x& w0 i9 A" z char air_num[8];
' g, b0 N8 Y3 m9 u. f; |0 _ char plane_num[8];
7 j( k0 Z8 ?7 B/ H9 Q* v char end_place[20];: }' f7 z H0 j) r
int total;
; A0 E$ D3 R) ]1 W9 U0 C# p* N int left;
) u- k) J6 i7 Y' o4 N struct airline *next;
, d0 }! L, O) g2 W m4 d}airline;
% q% q+ @! V: J; }typedef struct customer{
; k9 W6 S, G) W& ?; h1 { char name[8];2 T w6 p4 B0 K
char air_num[8];3 H* Q9 F: N V
int seat_num;$ l! c, n0 p6 X r/ j' i& |
struct customer *next;5 \! L, ]* P5 U/ B0 X8 _! W
}customer;
* n, [) `- h6 f, } h' E2 w# c# tairline *start_air()
' B& U6 T/ d% f{
% D5 ~2 o" d( K) b0 D airline *a;3 ~" q1 X5 F7 _6 H
a=(airline*)malloc(sizeof(airline));
$ S( y( o* x% Y if(a==NULL)
; K" P# y# D" j: k; R' a# ~ a->next=NULL;
7 u8 g/ V' n: m' `) V2 ^9 ^ return a;2 Z! }; n9 V# V% l% e
}
7 G3 c" L1 h6 a9 x7 tcustomer *start_cus()
( W" D# G2 s# l- f{" V: n, X; s" Z1 N/ h4 E* s
customer *c;
. u6 g4 E1 X$ I& k* W9 h c=(customer*)malloc(sizeof(customer));% W j8 x# q$ H8 [2 V, x$ R U
if(c==NULL); Q) k/ A! X7 B7 t6 S
c->next=NULL;9 G9 S5 _8 ^) ` {4 F; m7 c/ y* a
return c;2 |! R( I) b6 p3 k" L
}
- {" ^. d8 t. Z% X; b' d" Eairline *modefy_airline(airline *l,char *air_num)
6 A" E" u+ ^. t# e2 F1 f& l' {5 V{0 b2 {5 ^- F5 X
airline *p;3 J5 p" A: F) Q3 X1 D _1 N
p=l->next;
. @5 |% Q$ C3 P0 s6 \3 a. T for(;p!=NULL;p=p->next)9 V) `5 }* g! V/ F
{9 G* |! l% i( x
if(strcmp(air_num,p->air_num)==0)
* m9 Z9 x4 n( f! n* e# } {
8 d. g) c. H# r; M p->left++;) [; g. Y3 D* w
return l;. c, w# F% y% ?
}: c7 v: X v/ a( C; g& h4 Y2 u/ l; e
printf("NO the airline!");+ k0 S6 m/ a n) Z3 [# @ N+ M
return 0;6 t+ w2 d# }0 A
}- s! P. e, T* V: M+ l5 z
}
8 p4 Y! z, B# Zint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
) t" {' z+ N H* G* @4 i5 L' F k2 P j{
5 q, n3 L7 }+ n7 w% q8 _ ^4 p airline *q;
+ y9 W" b6 G& Z q=(airline*)malloc(sizeof(airline));8 t! f# z& N5 R( `; o
strcpy(q->air_num,air_num);
, f& S( q, \" M( D& j strcpy(q->plane_num,plane_num);1 k p# Q) Z: V9 Y: f5 {% O
strcpy(q->end_place,end_place);8 I. W6 C5 |& Y7 a( r' G
q->total=total; J. H8 w5 G2 A1 O: M. H0 f% f
q->left=left;, O% V, L4 n, a7 W
q->next=NULL;/ H+ x' n! i! f$ j- S
(*p)->next=q;
8 W( K, M8 Z* |6 X (*p)=(*p)->next;
% P; g$ p0 v V: j, O- y return OK;
: P- [+ A+ g" d' G, F3 k }1 f5 S3 u$ P/ n0 Q; E; Y8 A
int insert_cus(customer **p,char *name,char *air_num,int seat_num)% ]9 s$ N" |! k3 z# S+ G
{
% A5 K# B# w# C% h8 l) K customer *q;7 r. q7 ~! L9 {! o; R& d
q=(customer*)malloc(sizeof(customer));
) s- h: R' i; {+ F2 t strcpy(q->name,name);; K7 `, {8 M5 W" J! j
strcpy(q->air_num,air_num);
3 S( ]4 h" D8 r( ]; h, y+ Y q->seat_num=seat_num;* p& X5 K" V% e/ F5 S9 D1 ]
q->next=NULL;! V$ F! L. |% K& |8 v3 F
(*p)->next=q;9 a) L* ^7 D/ N4 |! J. ?
(*p)=(*p)->next;: S8 H# i& g/ X$ l, _
return OK;
% T6 `$ d: [5 H* }, r}# P* Y+ Y' l+ L2 L" p0 b( z
int book(airline *a,char *air_num,customer *c,char *name)
% w+ }3 U# y( z; h1 g{
G; B5 m# U( F! q, H airline *p=a;- z4 @$ A u; v/ ?0 g% D
customer *q=c->next;
+ u% X# L/ Z4 A4 } |* g p=a->next;8 P0 g* K9 L' }+ T9 K
for(;q->next!=NULL;q=q->next){}9 ]! l& E4 I @& s8 i" Z' E" F
for(;p->next!=NULL;p=p->next)
1 C. t# K' ]+ }4 } {8 V, E" L$ O, z" f
if(p->left>0)
% X0 }0 z" `: _; h7 V- `; b9 f {
& [# N) a: l5 F2 \5 E printf("Your seat number is %d",(p->total-p->left+1));& }! G; A5 M) ]$ ]
insert_cus(&q,name,air_num,p->total-p->left+1);' Z1 t& l S& p3 d
p->left--;" Q5 S7 P t/ a3 a( i K |
return OK;) t: g& v$ s" |
}
$ L& L% d, N0 D6 \' n else
; }. X+ T( ?* g {7 l5 `' t# ]1 H+ W
printf("seat is full");
p4 D" F5 v: z) o3 l return 0;
& D( X9 _. ]% ], F6 f- _ }0 K! m( M, S0 m: q7 b0 d
}6 J! D$ d! P) g8 G; h0 F) D
return OK;
) k7 |# A7 `- i, L}' i( b4 B! L4 V% B$ M i
int del_cus(customer *c,airline *l,char *name)
9 _. O% G H# c) G* V{
- ]) @: S/ `- e6 n customer *p,*pr;) f" X. h0 O z0 y1 t# S
char air_num[8];
9 `2 p3 d) v2 E+ P+ s4 m u8 A5 R pr=c;" E. y7 o1 {, m; f9 [
p=pr->next;
4 `- w1 b& q: P6 [7 u' ` while(p!=NULL)
9 X }* A$ W. l! a8 i* \& L {
, Y- r- _/ z0 [4 A; \ if(strcmp(p->name,name)==0)
6 j$ Q! v/ L" g* Q2 p2 j {
$ E' N/ P5 Z" ]0 R3 D9 R$ R strcpy(air_num,p->air_num);
1 c8 P( E, y% O$ N- Y* P% N l=modefy_airline(l,air_num);
! ? D5 p3 x: T0 v3 B; [- | pr->next=p->next;
: E. w# c4 ?, Z1 s4 S) e p=pr->next;
; Q# A" O: C& { printf("finish!");
) P+ z+ ^9 c- | return OK;
0 D% ]$ F7 u7 c3 E5 p }: b2 D& n/ i4 g# x
pr=pr->next;
: y8 V+ P- e" _6 H4 E) j4 ]! j p=pr->next;
5 L8 W1 j. U" {) c' J8 x5 x/ T }
0 D1 V# s: D$ V0 I( ]4 G printf("NO the customer!");
# N& R! @# I8 g' ^. b! M return ERROR;
2 m5 E" t& r% N f% V8 i2 ?9 h}2 o# I1 T8 o9 C2 w
int search_air(airline *head)2 G2 B3 G. J2 h
{
% W5 T$ R" Q+ C airline *p=head->next;. F* p! e: L. `' T2 C+ k
printf("air_num plane_num end_place total left\n");; P0 O m6 m' L% N. H
for(;p!=NULL;p=p->next)
9 j5 k! V J K. {, s {
% F" Z N- d. {4 O! N printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
' H3 d r5 E& h5 G$ ?; \ }+ N( t4 _/ W: F8 k0 U9 u* S
return OK;
4 V9 x1 k. B! J3 p( I6 m}
0 \' n+ \& P% v2 _: E ]int search_cus(customer *head)1 g: Y) P, Z- j) u
{! Q: n! Z+ P; l3 u: u5 q: V& c8 h
struct customer *q=head->next;
) p7 v' |' V: g) u a printf("name air_num seat_num\n");
' t$ Q7 ?* G5 t* W9 H for(;q!=NULL;q=q->next)
: I. u; K3 S* M4 m9 y9 u. U {
) s) L. F" ?2 K3 A6 E1 `+ r printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
5 T2 ~, R% K/ O$ S: p8 F }8 M2 s1 W/ P+ C2 {, r; [
return OK;
8 ~1 N t0 U: } L U: n" [# s}* j& r8 q0 }/ u. `' z& ]
int creat_air(airline **l)
( t2 G: j" `9 @9 G1 L& h8 u{
8 ^! `$ |8 r" ]& F5 t: {/ E' c l S airline *p=*l;
9 O/ d" l7 }* Q# J int i=0;
$ Y0 Y/ B; h. j I u7 c" d7 x char *air_num[3]={"007af","008af","009af"};7 Y# y( b+ X$ Z& q$ d
char *plane_num[3]={"plane1","plane2","plane3"};
& A. q* Z1 V; B2 C char *end_place[3]={"Beijing","Shanghai","Tianjin"};+ t1 ?/ ~! ~: `; m( F
int total[3]={100,100,100};: @6 O: S( w9 l( {1 D& D
int left[3]={52,54,76};! b/ v) T( q/ p/ W v6 O- P( m
for(i=0;i<3;i++)9 M i ^4 d8 ]4 \# Y% t0 g6 Q
insert_air(&p,air_num,plane_num,end_place,total,left); _6 h$ ^2 q, I! g( W
return OK;
) Z1 y1 ?, g- Q( B3 L}# X1 K1 e- I" I7 z$ K! P: Q
int creat_cus(customer **l)! Q E# J% {7 g" \
{
% B& f- I6 ?/ L9 [, _3 V customer *p=*l;4 g$ [0 _1 n: o
int i=0;
% i0 d7 `9 A. V' G char *name[3]={"zhsan","lisi","wangwu"};4 H1 E) q9 w" S- r5 z- D o7 f
char *air_num[3]={"007af","008af","009af"};
3 N3 z4 w/ |6 X# n int seat_num[3]={2,5,7};' ?* R, y4 ?* }- A) _& D/ i) P
for(i=0;i<3;i++)
& R7 X1 D: `* B, L5 C insert_cus(&p,name,air_num,seat_num);
( l0 y) l3 N/ I return OK;
. i! c, U+ X( d2 D4 \9 h}8 } Z! p7 I0 u/ n" X: c# [9 ?
void main()
( @0 b( ~8 A. O1 }8 @# }{
. _, K, q! X& G; R1 K! f. v# D int t=1;. o# @4 r2 X. F: I* ^7 p
customer *cus=start_cus();2 @: U( N1 K) A4 K* R
airline *air=start_air();0 {4 F( M& y/ Y1 O8 |. F; c
char name[8],air_num[8],ch;: P! q6 T4 e: @) u. K+ H( o
creat_air(&air);" F+ A: H. A0 I. D
creat_cus(&cus);/ }. k! e; H G N$ }
while(t==1)
' O% ]3 I3 K- Q) D {
$ o% g2 N& H2 ? printf("\n");
; e* {7 _3 {. T4 O! R printf("*********************************\n");
7 h' E: {3 P$ M# X0 c1 H+ ? printf("* Welcome to air firm! *\n");# H5 O ^+ M: A. R! g
printf("* book--------1 *\n");3 r% Z+ Q; L9 r
printf("* cancel------2 *\n");
0 Q3 Z9 E6 {' U' ~4 l) _3 `( B printf("* search------3 *\n");: N1 E+ l. |2 {: N
printf("* exit--------4 *\n");
3 G) z. R% T8 _9 v2 q printf("*********************************\n");
! B) A# O( K4 t5 t ch=getch();4 h7 m& A& E) x) d
if(ch=='1')! ?; m) l7 [- T" Y/ o1 Q
{
; s3 v+ n9 @3 X printf("Please input a airline number:");, K& A7 i/ g; M$ ?
scanf("%s",air_num);# s0 M4 j; V8 K$ s& `/ [) W
printf("Please input a name:");
" Y- w4 `( x9 x) s- i/ \ scanf("%s",name);
0 k; [# c2 f7 |4 J- I book(air,air_num,cus,name);$ T6 ` H% E. | [( d: @ h
}
3 I' E/ W$ u) ~# e3 u$ r else
+ a- T. m: Z. X+ @+ ? B if(ch=='2')
0 B3 V4 n m' x {$ O V) H& b( C v1 ?
printf("Please input the cancel name:");- P2 q$ g" ~* i8 L' ^0 q
scanf("%s",name);
* `) y" N$ Z6 d) s) a' D del_cus(cus,air,name); ^0 D: N! R7 F* O1 ?, S5 t8 c
}
* [( T% [! V8 _; j# }0 M! f3 p else
3 T$ K7 V& u3 e4 `5 ~ if(ch=='3')
$ s# \% ~& j1 q8 w- r. y1 L" S: g {
, |+ A9 ?5 R$ V0 x. e search_air(air);& u% G8 _# B( S# x
printf("\n"); # }7 w& E& K3 J B* _* k9 k. ^
search_cus(cus);8 ?# K. z6 {, h/ _6 S0 a6 G8 W
}
$ V5 Y5 a) S/ A0 y else
2 X8 t8 h; H: @* P' r( \- i! F if(ch=='4')9 T! v' i' X$ ~( c9 a
{
v5 [# E& w: O3 l t=0;4 r3 b( i8 Q9 d* P1 [
}, g; t0 Y5 I- Q0 J
}
# |1 h/ P- Z( D}
$ Y4 E- ^, E% g F1 o; \/*任务:通过此系统可以实现如下功能:
+ Z# l% w# x2 L! r V7 x录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)/ n2 A* J9 u# _0 i1 N5 a8 L
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);5 S, e$ J/ q2 D+ L2 a
可以输入起飞抵达城市,查询飞机航班情况;, z% F" S3 U" @# ~+ @' y
订票:(订票情况可以存在一个数据文件中,结构自己设定)
- q2 t9 y, K/ {6 y. n N可以订票,如果该航班已经无票,可以提供相关可选择航班;
9 l- J4 j* P4 ~+ D! i退票:可退票,退票后修改相关数据文件;; G7 r; q" X9 {4 u1 T) \: K8 Q
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。) G/ ~" K5 `! G% z# L- a# A8 Z
修改航班信息:当航班信息改变可以修改航班数据文件/ t' T6 |" E4 U: ~+ i
要求:
% m( n" j: H: I/ F, R* d9 b根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|