该用户从未签到
|
#include<stdio.h>
( J4 |2 o- A$ f#include<stdlib.h>/ ]5 F* q7 V, B6 c& g/ {4 j
#include<string.h>
; }$ H+ ]7 y& W p# g$ e#include<conio.h>
0 P4 N+ p% D: D6 O1 g6 ]) G#define OK 1
2 C0 u7 h' ?2 @, |#define ERROR 0
6 |7 \, {# M6 @typedef struct airline{% o% D8 M" a& B) O2 r
char air_num[8];' u) A& z/ `8 x M, r ]! q7 f
char plane_num[8];& C6 Z7 x+ n, [0 s3 D) }
char end_place[20];
, B |' S+ h( r3 y P; [ int total;0 l( u" t( ?' Z% u# v
int left;
$ y' ?8 k& h1 D( |2 y- `/ n struct airline *next;
& W* s5 t6 o. k+ G+ ?: n}airline;
/ d& Z! U+ b6 ftypedef struct customer{
+ v0 @% s) @( f6 d4 q$ d7 A char name[8];
/ z# d5 V) j* l, z& i% `( h char air_num[8];
7 S8 @, l- n4 K2 T) n% o int seat_num;
, l! _' [* q9 }% J+ T struct customer *next;, _- h g% L0 q4 m, c! Z9 F
}customer;
, |4 w! L& { V# m" {airline *start_air(), p# B2 _+ V" [4 W' L6 x
{
x9 _0 X! f/ z# @. e airline *a;9 h9 y% D5 R& R* P
a=(airline*)malloc(sizeof(airline));" m8 m Z' a) H" I
if(a==NULL)
+ c H4 a% j; ?! |; L a->next=NULL;0 B, T# B) B t, Q& h( S, z
return a;
9 z3 ]' j; n# B* Z) O3 t}
% r6 X9 S2 d0 D* T: c* K0 O" ~* p/ X# Acustomer *start_cus(). l/ I5 a6 n4 t5 A
{
9 Q% [" p" z4 D$ g customer *c;) t& L( p9 o1 o5 F
c=(customer*)malloc(sizeof(customer));$ s/ P! s C7 d# K+ ^
if(c==NULL)) h j3 l2 S; {* ~' M) X- T. U
c->next=NULL;9 ?& A2 w" i f" a0 @
return c;9 \: ?. z, V5 F) E7 ^7 }
}
8 E* S" r7 r$ nairline *modefy_airline(airline *l,char *air_num)8 }7 h) s$ C7 T6 e
{
' b1 r/ ?" a5 k7 r4 I3 Z airline *p;2 c) w7 v/ I; P: ], X
p=l->next;
; Y% e" K7 i5 m1 J1 ~* h for(;p!=NULL;p=p->next)
- a! f" I1 b' W' Y8 w' C! X {0 \/ z; W' t2 }, i% R# J
if(strcmp(air_num,p->air_num)==0)$ `0 r- c0 N3 D9 w
{
/ L3 F" d( c2 u. ] p->left++;& m9 ]. b3 m) S. ^) y. e( w1 g
return l;
3 M) g I9 B8 x% J: i }
/ g# P/ i( |. `# \7 c- U. P printf("NO the airline!");
) U7 V: H5 g# ^4 e return 0;+ m# J# A; e$ X* Z0 T$ i
}
! J+ v' f6 `2 ]1 Y( U}
7 y- G, J/ v1 O Y6 H8 n% k3 O; d R6 ~$ fint insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
9 k) J; r5 c/ w3 u# M{
8 M8 S( M' x% w2 B5 X; ]' {/ A airline *q;/ J1 V- L3 {& ]1 \; ?
q=(airline*)malloc(sizeof(airline));
9 M. g* @6 O9 }* X8 z, N; [ strcpy(q->air_num,air_num);. s5 Y; ~; ~6 |5 Z q* X
strcpy(q->plane_num,plane_num);
3 t. ?- D$ e% ~! J+ J. U strcpy(q->end_place,end_place);4 [$ L+ r, Y( n" u4 z, y
q->total=total;
+ i# M2 P/ c! w5 B+ Z2 ]$ t" R q->left=left; ]* x* p% i; B4 H' j
q->next=NULL;$ F* H* @+ X5 X# T6 R
(*p)->next=q;
0 b- X Z+ J5 o$ C9 c$ _+ u5 V (*p)=(*p)->next;2 ]. Q0 a: M$ x$ i
return OK;
3 w: a0 w/ g7 e5 r( A }
. ^/ T5 ]" f/ p/ E; _/ q; @int insert_cus(customer **p,char *name,char *air_num,int seat_num)1 c* h$ F+ |3 Y+ P) J: d+ _
{
9 x- F, `# n) t: q- E% J customer *q;
8 Q x% ~6 _ M( a/ |& K- f i q=(customer*)malloc(sizeof(customer));
* `! d) e- E7 t/ X strcpy(q->name,name);9 ~* h/ W/ Q3 Y$ m0 U
strcpy(q->air_num,air_num);
/ e; } s) w V N+ s9 w) N q->seat_num=seat_num;0 D, b6 j6 G8 B4 G9 E
q->next=NULL;
3 ~% W7 L8 \% F, @" m. H (*p)->next=q;
9 b" K0 ?$ t* P; U9 S F1 g (*p)=(*p)->next;
% |( I' b- r) y3 W7 X$ D. d return OK;
# _* ?+ K, |( E. }2 ?- ~' ?+ J}
/ w! y6 X! j( M4 n; Eint book(airline *a,char *air_num,customer *c,char *name)
8 r) A% Z5 j/ z& e* y2 y{* ?) v7 H5 _+ y7 Z' C& [, y7 F
airline *p=a;
7 G; u' W8 @ R+ D& E customer *q=c->next;
d C, [. Z3 y2 i1 e @! C+ d p=a->next;
1 U% \3 ~# T& p for(;q->next!=NULL;q=q->next){}
, y( ^ N8 c7 q; q2 |7 V for(;p->next!=NULL;p=p->next)/ ^# S- d# b/ f
{8 Q3 `7 G& D9 d# Q$ |
if(p->left>0)1 E9 P: h% ]: J1 B3 S
{
, _1 s+ j, G: Y' a! Z# Y1 b+ i4 |' ` printf("Your seat number is %d",(p->total-p->left+1));
* f1 H. a; ? m insert_cus(&q,name,air_num,p->total-p->left+1);& R; D B9 O/ F+ U7 |
p->left--;: y: t V8 R6 K& }9 g1 Z
return OK;
, F5 i* @ @2 z }
! N ?: a; Q! h) d9 f" K2 h else; b0 W. U0 |$ X1 O$ G, n' M0 z; g# j
{
4 @9 k) w- W1 S& [1 G+ R- R* c printf("seat is full");
3 p8 F# M/ c; v! J( i return 0;
- N1 N( p$ p) f9 k/ n3 y" _( _ }
1 v9 x: K$ {% b# F! Q4 [" l4 ? }
: p1 c4 ^% V4 P0 Ireturn OK;% c/ p" E; O: [2 e& i# o
}0 I0 l2 m6 u& d5 f$ ]# A; g, s( d
int del_cus(customer *c,airline *l,char *name)
?3 z* z% G6 Q1 r- e( ^- z{
# ?! Y" ?3 ^. B9 ?1 Y' e customer *p,*pr;
$ g. T, l8 V0 @8 F% ~* T5 N char air_num[8];
" _! p0 J k0 z- m% V pr=c;( S0 [% X. ]! H5 J4 n6 e( }
p=pr->next;
/ f2 c0 c1 I. z, L while(p!=NULL): Q( Y" i& m/ a
{, t1 ^" Q/ C* K) h& Q( R
if(strcmp(p->name,name)==0)
; G" @: N9 M& w$ g' ^: I" o {
. d. h. `& H" X strcpy(air_num,p->air_num);
9 @1 I9 C6 L: B l=modefy_airline(l,air_num);
. m0 j/ r# r7 I0 ?9 `8 t pr->next=p->next;6 s- n' s, R- W+ q5 L
p=pr->next;- u, s) a7 W: k* k6 P. l& R }
printf("finish!");
- J g g8 o0 F+ @+ M return OK; " m& D# x( r; ^
}( X' G5 @' E6 O, A+ ]
pr=pr->next;% S0 m- F7 ~1 p1 S
p=pr->next;
& r6 m* @7 X# C+ q ]( w9 T1 Y }
) a8 D/ h5 ?- [; |$ Y8 _7 o printf("NO the customer!");
- p0 Y/ F9 I% z1 M' t# Y: i. p1 e return ERROR;: n7 ~% @+ Y" p/ G7 x2 t+ S+ J
}9 k% b6 [3 n- W4 F% h1 m Z
int search_air(airline *head)
5 k5 Q/ g) |9 E# X/ u, u{5 V* V1 U/ D3 J& X: Z- v6 v* h4 T S$ \
airline *p=head->next;6 P j: I$ O4 W" Q) W# n E
printf("air_num plane_num end_place total left\n");4 P5 r* U$ F x9 b) i) B
for(;p!=NULL;p=p->next)" z" v, Z: ]+ d2 Z5 E
{
3 u, a. R& R+ {% G5 W printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
, v0 f2 y/ v! u7 P" K7 F! f8 p }
$ z) R. A; [2 B: [2 s& n return OK;- ^7 X! _: v, e
}
5 @' P. w9 m/ z6 j2 J4 p$ D oint search_cus(customer *head)4 _& C& W. T' u- }- ~. F
{) ?+ v& t$ {/ ^; L' Z: ]( |% {
struct customer *q=head->next;7 `: ~' K- m1 x
printf("name air_num seat_num\n");
' i' E% E. p1 y3 X0 x' A+ t for(;q!=NULL;q=q->next)3 ?9 d! l& e8 E2 C6 {& R- y0 }# D
{
8 f4 r# x4 |: p+ F$ u: m0 _ printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
" |; I: \; w3 |! k }( x X0 L; k r, `2 ]
return OK;* O |# A' k O/ k
}
1 U+ [( }7 {2 @3 q: Zint creat_air(airline **l), r& y) O% U) D' o. }1 C0 y% l
{" S( j* {# T: v$ K
airline *p=*l;
* s& I, D' c- D% Q/ G, e1 s8 J ^) p int i=0;! E$ c2 i' P8 i+ U6 G
char *air_num[3]={"007af","008af","009af"};
! S+ \3 U% x' U: \3 C$ e char *plane_num[3]={"plane1","plane2","plane3"};0 S- U( G- @ y
char *end_place[3]={"Beijing","Shanghai","Tianjin"};% I, j3 c( X) U$ ~9 x4 H0 ~* M
int total[3]={100,100,100};& h8 m5 W4 u1 H4 C% t0 a
int left[3]={52,54,76};) a) y9 e; M- ]# T8 u0 u4 `
for(i=0;i<3;i++)2 e1 A- ^! x: h: L [% M# q
insert_air(&p,air_num,plane_num,end_place,total,left);
7 F( _1 R* O0 Y6 A return OK;
5 A8 c6 g8 A% x! W% q2 M/ h7 Y}& O* r! |* @; q2 s3 |! J( W' R3 }
int creat_cus(customer **l)
i6 [, c6 W" y0 ?{
0 K/ |8 _( `' u customer *p=*l; ?/ G1 R L' `& l B$ ~5 J# F- y. ]2 c
int i=0;
8 D, S/ ^' A% ^1 U0 q p7 \ char *name[3]={"zhsan","lisi","wangwu"};
3 S3 C% [) ?8 E char *air_num[3]={"007af","008af","009af"};0 g1 h' X; e0 G. D" Z3 q9 l
int seat_num[3]={2,5,7};
1 Q$ q A* g% r for(i=0;i<3;i++)
9 J9 }6 f2 e! R3 w5 _ insert_cus(&p,name,air_num,seat_num);
' l2 S* e1 z3 f( ` B8 T$ h return OK;
- c( G+ }) Y+ R}* A" L9 k1 s2 x5 z
void main()
4 t, u8 t" W) }9 O{
Y0 L3 r6 _# n7 f3 L9 s* t int t=1;
! L% r; ?! } }6 a7 h customer *cus=start_cus();
& O( p2 |; x5 g airline *air=start_air();
' d$ |5 I* ?) I v6 b- {( ^' ` char name[8],air_num[8],ch;6 a% f4 `" j- a3 n
creat_air(&air);$ h' s: _, U9 s. b P' n
creat_cus(&cus);
2 p" Y' ]' ?. a! b4 k$ w! l while(t==1)2 ^$ O9 J/ w/ `; ~8 f, w1 V! L
{
( l* g9 k: D7 Q( X- u" b printf("\n");
4 _$ ~3 E5 v R8 J f printf("*********************************\n");
, V) y) `* _3 {/ v. D+ c( Z printf("* Welcome to air firm! *\n");
% E8 x' j/ z( J v' @ printf("* book--------1 *\n");" W0 t5 H1 t3 b: o) R a. ] `
printf("* cancel------2 *\n");7 a5 I# O8 B, v* T/ M5 t
printf("* search------3 *\n");
, i/ f( {4 {9 y/ Y7 H printf("* exit--------4 *\n");/ w3 k. X/ E+ C* U
printf("*********************************\n");6 z* E' j* g; q
ch=getch();/ X4 n# h1 d+ w) b" h5 D, g
if(ch=='1') ?/ `; X. t+ s& G# z
{8 `- z7 e1 H$ h& K0 m; }- _% z
printf("Please input a airline number:");
# }4 i2 B# E1 r/ Y; {" @ scanf("%s",air_num);" l4 @& D) |8 b9 ]- a1 o% v( w
printf("Please input a name:");" M+ ~, n5 D9 y# w% [9 Y
scanf("%s",name);7 p/ Z8 I6 H/ w9 r
book(air,air_num,cus,name);( F* J* L1 a7 o \% d2 K
}
o4 V% S# \) N( j else
8 v1 C9 p! E* s& k. ~; i0 J9 l if(ch=='2'): X3 N1 v8 K8 {! N
{$ F8 D* `$ D4 h" S5 _% l/ h
printf("Please input the cancel name:");6 @- _7 w; [0 I1 S1 Q- _' }$ y
scanf("%s",name);
0 B1 U. [& c0 W1 B# x) k del_cus(cus,air,name);
2 i7 v7 m! J. l8 f8 g- L }! u% K7 X1 A% p Q( Z$ @8 P
else
7 ~. f/ ^: j# S1 Y) ?/ R' I. d if(ch=='3')
9 H4 [; v! f, W$ M2 {7 s \4 o( M {" I5 x& H; t) H: [* T$ b
search_air(air);; ?1 D* l' q8 e0 R6 g n3 Z
printf("\n"); d3 l- _6 I* f# F" h
search_cus(cus);
2 X* \7 Z5 V. U X }1 x }% `* ?) T- u( @& x5 ^8 [5 w
else
! `- X2 g2 c6 q' ^( G, X if(ch=='4')* W* ` r6 w1 ~8 P
{
, b& H9 F( P7 s! i; K) I' x# W t=0;6 ~6 n' B# L3 m+ b
}8 B) c% ~# ]; j/ \! V6 J7 m
}
5 ~3 x! c4 S$ J C- B, V}
+ o+ `; M, E+ O9 I! i$ H/*任务:通过此系统可以实现如下功能:+ l2 p" I) H: ~, i$ U- Z' M* @1 o
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)) h* } W( ^7 I
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
, y7 n& c! R% F) ^5 ]- h可以输入起飞抵达城市,查询飞机航班情况;/ l: c' e% ^: i0 A. [7 v
订票:(订票情况可以存在一个数据文件中,结构自己设定)
3 T9 } t, l j/ a& A9 L0 n) E可以订票,如果该航班已经无票,可以提供相关可选择航班;
& m4 P- Z/ m6 ]退票:可退票,退票后修改相关数据文件;
G4 |* `. v: B& A$ g客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。) z* Z f* X) `1 S
修改航班信息:当航班信息改变可以修改航班数据文件. \& r5 a' |9 a* M- l' O
要求:& F+ g- S5 e" A9 I+ T' j
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|