该用户从未签到
|
#include<stdio.h>) y* {" d. B3 {- E
#include<stdlib.h>; h2 k5 z- ^0 c$ L+ R
#include<string.h> ~, C. W" y& B& w0 D1 g* n
#include<conio.h>% }, W% W3 i! {5 w
#define OK 1; }7 M3 U3 h5 Y5 r! q
#define ERROR 0
, l3 m% Y: m9 l- \2 _; Stypedef struct airline{
% D7 t; P; s8 t, A& C3 w! K char air_num[8];! D. Z! M1 y3 y
char plane_num[8];
! b7 F4 L+ L8 H' N- Z5 R char end_place[20];8 v$ r" A9 m0 ?' H
int total;
- d; H* b u; m$ ` l1 ~: ?8 T int left;
* _$ j8 r2 c) S$ I1 R8 ` struct airline *next;
) v/ v" H. ~5 g o3 O- f& Z}airline;
' _8 | G) Z* S2 c5 a2 J4 a0 k/ Ztypedef struct customer{* J3 B* u3 M0 P* L. B6 a
char name[8];5 W f, Z" }2 F) E; j: b& I
char air_num[8];
8 E! F. V" W- L. p2 i. @/ s int seat_num;3 [/ G' q' y( u
struct customer *next;$ u5 Z* A' X# R" U
}customer;* E# y/ `2 s M
airline *start_air()
2 \, ^: q% s% O n{
; g0 h5 ~3 f; Q$ b, c airline *a;
) b7 Q$ Q1 z( w; U: r0 l, d a=(airline*)malloc(sizeof(airline));
7 o; Q8 q; E0 g& z& \, f( R if(a==NULL)
6 v; t* p) F* ~# Z7 c a->next=NULL;2 t5 W( c( o; ~, p5 @
return a;9 ?/ \7 h- P9 C ~- K5 Q
}# Z/ ^2 o6 C0 N# H" W
customer *start_cus()+ I. I# u* L- \9 M. @
{
+ }" Z7 T- J1 j/ A" @% f customer *c;
* t( Q s+ }/ }+ v8 }7 r f6 A c=(customer*)malloc(sizeof(customer));
r2 G( f/ P7 c! y& E2 }) U7 V if(c==NULL): j M+ q+ W# O# q, O, c
c->next=NULL;' z4 @5 }, s' D6 k6 N& n
return c;
7 h( {/ |1 B: C$ P# W}+ e$ k6 P' n. ]* x) Q
airline *modefy_airline(airline *l,char *air_num)
) \/ V3 j2 F+ [{
9 Q' ?4 L" n8 d airline *p;1 U* |6 L' V r, j6 n
p=l->next;
/ m: l+ H4 F9 X1 K1 M for(;p!=NULL;p=p->next)
& s+ V& Z4 V' N _ {" g& O% H5 x+ `2 \
if(strcmp(air_num,p->air_num)==0)1 _, n' f- C9 i0 n: A
{ c4 b1 d' a8 A8 @/ c/ {% X% W( m
p->left++;
0 n3 g! j& O N return l;& Q: ^" n( Q# O$ m
}/ m) P' l0 m @
printf("NO the airline!");
8 X' }% E1 j9 `" e. S return 0;# N5 ` t+ G3 `3 r& U8 b
}; t: i; O4 o5 ]/ f7 K
} i9 V. @4 B, N) j' B+ N
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
) ]) G9 N" R- f' H# x! ]7 W{
& `6 K6 W5 v( s& u( b airline *q;+ S7 F4 h8 i0 h, F. }3 |
q=(airline*)malloc(sizeof(airline));2 I) C: t5 ~1 H# \
strcpy(q->air_num,air_num);: L* r4 H# T2 R
strcpy(q->plane_num,plane_num);
( D9 s4 i9 l& Y. } strcpy(q->end_place,end_place);1 k0 g5 i3 q% ] K; k
q->total=total;
. \7 r9 t) n g$ m q->left=left;. Q: Y9 W! S8 E# }7 |7 N( h1 G% V
q->next=NULL;& y* V& |1 c8 I6 z; p3 y/ A
(*p)->next=q;
6 u7 I3 I+ _" h0 M h# F (*p)=(*p)->next;
9 S' q: [. ^( ~1 V# H4 O return OK; m' Z3 z, b }* _7 p" R6 \
}
" }" `& K+ G- P" q4 k! I0 y* ?int insert_cus(customer **p,char *name,char *air_num,int seat_num)
% X! L. P! |) K3 u{$ {$ W$ @' T2 e/ G$ i
customer *q;9 X9 r! j5 C# h! Z& w
q=(customer*)malloc(sizeof(customer));& Z% k8 B5 v0 X0 l2 r7 l! x
strcpy(q->name,name);4 X7 c2 b$ m- ]0 a
strcpy(q->air_num,air_num);7 d6 ~- ?% x5 a {! W* Q
q->seat_num=seat_num;
: L( h: W5 t7 t! Y4 o' G9 h q->next=NULL;0 I3 j- k8 z8 [, x5 b7 ~9 }6 ] {
(*p)->next=q;% T" E" }# D2 v; C9 e* W! ^
(*p)=(*p)->next;' V! W7 d, r2 j9 ?3 \$ n
return OK;
' I" n/ o2 q1 T- g2 _2 e4 ]+ f/ U}9 n. h' f4 p$ `8 b' s9 v A0 ~, J
int book(airline *a,char *air_num,customer *c,char *name)
6 Q( d# M( r& j{
% k7 A b8 e# i) r4 [ airline *p=a;
5 h7 r7 Q+ ?! B/ c customer *q=c->next;
4 Q2 |- o- f1 ~ p=a->next;* H I# Q3 q. B1 x$ J7 T0 B
for(;q->next!=NULL;q=q->next){}
+ |5 r- }( |+ Q+ q- _9 x1 A4 s/ V for(;p->next!=NULL;p=p->next)" @( F' Q. @& D: P' \( F" m
{
4 `5 z0 L; i! Y: \: i if(p->left>0)
4 }7 E- [/ T. ^. S {2 G) {) e. H7 B+ r! u8 e; q3 ?
printf("Your seat number is %d",(p->total-p->left+1));; U- }' b! A( s: r4 N1 F
insert_cus(&q,name,air_num,p->total-p->left+1);0 d# P- A" k( ^- w2 {
p->left--;
1 b; P- Y5 i$ x+ n0 n s$ p return OK;, p: t& G& D3 J/ W- I1 I# i6 ~) N
}
& W& E0 \+ I. l# o3 _% G else3 s f0 X* S& q6 c/ r8 B* S+ q" g
{
( J7 {0 E5 y" v7 z% J$ a" \/ {) p printf("seat is full");9 j* H3 k' ]1 }
return 0;
& L6 s/ V% N& l }
* G8 ~) w, F( B: W w# ~2 X, U } z! S5 u9 {' _- d3 \# \
return OK;
. K( |7 z) ^; P" l% o- d+ g}
" P! V5 k- b q% I. H mint del_cus(customer *c,airline *l,char *name)
7 _+ ?. a, d" M3 n{0 `4 p- Z+ t. \8 X) D
customer *p,*pr;
( d: F, `! t2 n. t" E char air_num[8];
. J% z* ?% {9 w8 ` pr=c;
. o, @8 w* U0 t* z2 H! G+ d p=pr->next;
) w# d: k' h* Q while(p!=NULL)5 ]0 ~1 s" d# @7 G( X$ U
{$ e, W u v+ \8 p2 N
if(strcmp(p->name,name)==0)
. @1 X3 v8 G6 b2 Q {
3 ]7 D: H) f* U+ U& ? strcpy(air_num,p->air_num);9 y+ I% T- r# P! `+ _# l+ s3 m$ m& c
l=modefy_airline(l,air_num);
- ]' @" ~$ f4 N) A pr->next=p->next;
4 g/ I/ d& f2 l- } p=pr->next;% P6 L$ J+ F U9 p6 U
printf("finish!");$ [8 D7 t: }4 g4 U( B1 [. {
return OK;
& b r0 f, q$ j- E) _2 w9 X3 f }3 O6 ^% W1 d+ _
pr=pr->next;
2 J! n# P, s% D5 T* M8 U p=pr->next;
: ^" q) Q% j. l3 n5 O0 M }1 ~" E6 U( c& q4 ?
printf("NO the customer!");$ J: R1 h: s. p( e( S5 [
return ERROR;
8 E! @, g5 A# S}
" Q C8 v/ |3 D" q! L& ]int search_air(airline *head), ~4 Q3 h5 u" O8 ~0 y
{% @& P9 K! e+ Y0 H, q8 m
airline *p=head->next;" m# W- ]1 h5 Z$ B" p" {
printf("air_num plane_num end_place total left\n");
: T X% [- l% ? for(;p!=NULL;p=p->next)7 L/ e4 |9 ~, z8 M
{
4 S/ U/ B! w) q/ [* N printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);( h# I. {4 ]3 I' n0 M5 I
}% _ e8 i) h5 C2 B" v0 \7 `4 h- c0 e
return OK;' l: @' Y" L+ n2 C! A+ X1 h
}
' s3 t9 U* Q; a! T+ Sint search_cus(customer *head)$ a$ M/ Z7 q# F' N6 y2 S6 O+ M* |
{
& J0 Y4 V" w. z6 T5 u struct customer *q=head->next;
0 \, G. m% s) K) h" } printf("name air_num seat_num\n");
, \& I- ~" l8 \; c for(;q!=NULL;q=q->next)
; j2 o% k; `% O r: \8 q/ t {
$ L- L \* j) S9 T% L printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);) U; N* _% e k
}
2 I- W" G( I" b/ E: R: R/ @ return OK;; r* F" X' X# q. i4 {
}
+ B; H" P7 c/ |# [7 |8 u% _4 W; Vint creat_air(airline **l)4 ~5 x7 ~' v$ b4 Z: {, N8 Y& K2 k
{2 E" [; r' t: n
airline *p=*l;* R& Q- z2 q5 w
int i=0;
! X4 s* A- F- e; \* t6 [ H char *air_num[3]={"007af","008af","009af"};
: F$ z* E4 [' A0 C char *plane_num[3]={"plane1","plane2","plane3"};
4 T7 }! s! W. {& o) p" ?9 I! s char *end_place[3]={"Beijing","Shanghai","Tianjin"};8 _( L( S5 o+ w- V( D
int total[3]={100,100,100};% \7 W; w- q5 d6 ^' s+ `7 w
int left[3]={52,54,76};
2 ?3 a, Q! p* O; L+ U6 n for(i=0;i<3;i++)
% {/ E u, H/ @' g) ] insert_air(&p,air_num,plane_num,end_place,total,left);% b: G. }) {) K! d; x- R; V; o$ v
return OK;0 |; Y' y }- ?, _# q' C
}* u4 @3 O; E: G9 v( |
int creat_cus(customer **l)
# X0 p0 ~7 t; p& R1 S, T: s{) P7 _; Z' w& o+ ]4 u( F3 b. e H* |
customer *p=*l;" c* ~# U% Q+ v# A2 B2 R
int i=0; x; `) K2 ]! N. `' I
char *name[3]={"zhsan","lisi","wangwu"};
. O7 b3 H, h, Z char *air_num[3]={"007af","008af","009af"};
, L# x7 u$ f6 K2 M6 D7 _6 u" L1 k int seat_num[3]={2,5,7};
) h" Z; r1 ^. G for(i=0;i<3;i++)4 a* Q/ Z1 F6 T# X/ b
insert_cus(&p,name,air_num,seat_num);
8 s8 k. \" k1 g/ Z return OK;
0 W9 T; F; J" j: h}
4 d, w6 Q! _6 `5 ~% {/ gvoid main()- T W1 d/ `3 h' z4 ^
{8 r$ j1 I& q0 _/ v6 u9 M; \
int t=1;
3 z2 K( r! P& Z3 q1 { customer *cus=start_cus();4 V' v0 A& m" j3 [3 V) F0 L9 y
airline *air=start_air();
# ~9 _* ?: i* q5 @3 \9 g char name[8],air_num[8],ch;
$ I1 i' F/ X9 V' T" M4 q2 | creat_air(&air);
1 F) R5 j$ O$ j9 ]: f creat_cus(&cus);/ G% Q3 H+ I+ D. k: b$ p3 E( F2 p
while(t==1) \- ]8 b. v3 o' a
{/ Z- e% D) _2 k3 h4 h! Y. J
printf("\n");0 a; Z3 V, Y# z- Y
printf("*********************************\n");
. E; G. x2 I- u9 c printf("* Welcome to air firm! *\n");
8 D& w4 U8 D# q w printf("* book--------1 *\n");
. K& u# x. U/ I! ~; ? printf("* cancel------2 *\n");
$ L- {+ s' X: ^* ~7 @1 B, U printf("* search------3 *\n");
3 S. g4 [) y0 X* S printf("* exit--------4 *\n");8 T _" L6 r0 }
printf("*********************************\n");
; }8 n$ L/ y& y: |6 i ch=getch();# e, }- j" \5 i( o$ k# |
if(ch=='1')
/ J! b7 i. N1 L' `6 N$ h- Y {4 | F R* `1 h5 K+ o7 {+ W
printf("Please input a airline number:");& P% n2 p- w7 Y
scanf("%s",air_num);- o v- k1 k/ n: p* t0 \( h* k
printf("Please input a name:");! u d4 ]+ g9 K) z
scanf("%s",name);: n5 X h/ \2 z S1 E) u
book(air,air_num,cus,name);* l% Q! k5 }2 n* L: j
}; U) U* D) k6 D3 M }6 J( p+ p
else
- `* o- m8 d2 A5 u if(ch=='2')$ F9 X7 h1 b1 U2 ~
{* [$ C3 g4 s: Y( P9 W6 N
printf("Please input the cancel name:");$ R) s5 i9 {/ L x& N! X/ i
scanf("%s",name);
7 o j5 b& s7 I. ` y7 L del_cus(cus,air,name);+ ~! I: Y) ^) b5 A$ s
}
8 V+ K# q: l1 Q9 \. G) Z2 ]8 s/ l4 x else) }% Z }; j; K! l e
if(ch=='3')$ j* ]# L. x$ X( E) ?$ a
{
2 k- b/ s- s }0 R6 ?# f search_air(air);, ]+ I% S+ j& D( O& }0 U
printf("\n");
9 d7 Y* T/ H. S: g search_cus(cus);
, E' {4 L+ g5 E% N }
1 x, P# [/ @7 n! I$ g! S! `" S else' o- V& Y5 P @. W
if(ch=='4'): a- K5 q! ?& Z3 B N
{' K1 k; G" X0 n. V2 R3 u
t=0; f: C- O* s) g0 d8 {7 ~- O
}
6 U8 D$ m5 x3 B }8 W; B# u% E- w3 b5 n
}
9 v2 e- o/ H! F3 _3 c/*任务:通过此系统可以实现如下功能:$ _/ W! a* \% ?4 I$ I7 i6 H
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)' B" v' R" {" [( c. g; r
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
- R/ H7 D' B C% _3 R$ Y: x/ K+ Q可以输入起飞抵达城市,查询飞机航班情况;
. n! K4 p k P: O4 L* C6 @7 k! s订票:(订票情况可以存在一个数据文件中,结构自己设定)& f: I* Z) w2 \! A, v! X7 e# @
可以订票,如果该航班已经无票,可以提供相关可选择航班;
: q2 B/ N8 l$ s+ F# F0 x# D- K) e退票:可退票,退票后修改相关数据文件;( N9 C& k% d6 L0 W) \% l
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。! ~& t( x6 t3 P2 X1 d& ]3 A
修改航班信息:当航班信息改变可以修改航班数据文件
) }7 l `8 P" q6 [要求:+ t% G5 ~) A) t$ A0 X
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/ |
|