1 绪论
1.1 系统设计的目的
为了方便机场工作人员对机票的管理,提高飞机票的管理效率,降低飞机票管理中的出错率,减少信息交流及其带来不必要的开销。需要设计一个民航订票系统,该系统能及时反映航班及机票的剩余数量等信息,可快速的帮乘客订到想要的机票,而乘客也可以通过该系统实现自助退票的功能。
1.2 实现的目标
该系统是由两个人共同设计实现功能,由于一个人的能力有限,该系统仅能实现录入航班信息、查询航班信息、订购飞机票、退订飞机票等一部分功能(航班的信息存储在文件夹中)。
1.3 课题的研究方法
机票管理系统是实现机场机票的预定、统计和分析,提高机票运用的科学管理水平,充分发挥机票利用率,节省订退票时间。系统的主要设计思想是实现对机票的查询、退订等功能。航班的信息以文件的形式存储,用头文件包含、全局变量定义和结构体定义源代码,用结构体数组来存放顾客名、航班号、座位号等信息,用链式结构存储信息。系统的人机接口采用简单的字符界面进行交互。系统的设计方法是结构化设计方法,采用C 语言进行开发。软件开发平台采用Visual C++6.0[1]。
第 1 页/共 22页
2 软件模块结构图
民航订票系统可以分为四个部分,订票、退票、查询信息、信息载入。
图2.1 民航订票系统模块结构图
第 2 页/共 22页
3 详细设计
3.1 数据结构设计
用printf()函数输出界面,typedef struct airline{}定义航班的信息,如航班号、飞机号、目的地、座位总数和剩余座位数等。typedef struct customer{}定义顾客信息,如顾客名、所订航班号和座位号等。初始化链表,并在airline 、customer 链表中操作,实现系统的功能[1]。
3.2 模块设计
3.2.1 界面设计
用printf()函数输出界面,提示用户选择需要的功能,用条件语句捕捉用户输入的选项,并执行代码,进入用户所选的操作界面。若用户输入非选项的字符,则提示输入错误,提醒用户重新选择。
3.2.2 订票模块设计
进入订票模块后,进行订票。若票已经售完,提示用户不能预订该航班的机票。若还有余票,则提示用户输入个人信息订票。订票成功后,系统中该航班的余票减少相应的数量,并将顾客信息存入文件[2]。代码实现:
status book(airline *l,char *flight_num,customer *c,char *name) {
airline *p=l;
customer *q=c->next ; p=l->next ;
for(;q->next !=NULL;q=q->next){} for(;p!=NULL;p=p->next ) {
if(strcmp(flight_num,p->flight_num )==0) {
if(p->left >0)
第 3 页/共 22页
}
}
{ }
else printf("Sorry!Seats full!\n"); return 0;
…… p->left --; return 1;
3.2.3 退票模块设计
进入退票模块后,用户需根据提示填写自己的姓名。退票成功后,该系统自动在余票中增加相应的票数。代码实现:
status delete_cus(customer *h,airline *l,char *name) {
customer *p,*pr; char flight_num[8]; pr=h; p=pr->next ; while(p!=NULL) { }
printf("No this customer£¬can't return£¡\n"); return 0;
第 4 页/共 22页
if(strcmp(name,p->name )==0) { }
pr=pr->next ; p=pr->next ;
……
}
3.2.4 查询模块
进入查询模块,用户可以查询现有的航班路线、航班号、余票数等信息。代码实现:
status print_airline(airline *l) {
printf("%8s%8s%8s%9d%9d\n",p->flight_num ,p->plane_num ,p->destinatiairline *p=l->next ; for(;p!=NULL;p=p->next ) {
on ,p->total ,p->left ); }
3.2.5 修改航班信息模块
进入该模块后,用户可以更改航班的信息。有了这个模块,系统内的信息可以灵活的根据航班的变动而变动。代码实现:
status
increase_air(airline
*l,char
*flight_num,char
*plane_num,char
} return 1;
*destination,int total) { }
第 5 页/共 22页
airline *p=l->next ;
for(;p->next !=NULL;p=p->next){}
insert_airline(&p,flight_num,plane_num,destination,total,total); printf("Adding flight %s successed!\n",flight_num); return 1;
3.2.6 初始化体系统
系统最初默认值为零,因此需要初始化链表,录入航班信息和顾客信息。初始化系统后,系统方可进行运行,进行相应的操作,实现系统的功能[3]。
airline *init_airline()
{ …… }
customer * init_customer()
{ }
status insert_airline(airline **p,char *flight_num,char *plane_num,char *destination,int total,int left)
{ }
status insert_customer(customer **p,char *name,char *flight_num,int seat) {
customer *l;
l=(customer*)malloc(sizeof(customer)); if(l==NULL){ }
l->next=NULL; return l;
……
……
customer *q;
q=(customer*)malloc(sizeof(customer)); strcpy(q->name , name); strcpy(q->flight_num , flight_num); ……
第 6 页/共 22页
4 使用说明及运行实例
4.1 登陆主界面
登陆主界面,按用户需求进行相应操作。
图4.1 主菜单
4.2 订票界面
进入订票界面,输入乘机人的相关信息,系统提示订票成功后方可退出。
图4.2 订票界面
第 7 页/共 22页
4.3 退票界面
进入退票界面,用户输入相关信息,系统提示退票成功后可退出系统。
图4.3 退票界面
4.4 信息载入界面
进入信息载入界面,进行相关操作。
图4.4 信息载入界面
第 8 页/共 22页
5 总结
5.1 系统的局限性
该系统仅能实现订票退票和简单的航班录入操作,飞机的起飞、降落时间并未储存在系统中。机票模块的实际剩余票数不能及时反映到系统平台上,导致显示的余票数量可能和实际数量有偏差。查询模块仅能实现按航班号查询和按起飞抵达城市查询的功能。系统并未提供像航班延飞、乘客是否登机等一些实时性的信息这些功能。在安全性方面,系统没有设置密码,因此只能面向航空公司内部人员。
5.2 心得体会
在用C 语言编写程序的时候,最好的方法就是分模块进行编写,每个功能用一个或多个模块来实现。这样写出来的程序容易读懂,而且在出现错误的时候可以快速的找出错误。
课程设计是我们专业课程知识综合应用的实践训练,在这次课程设计中,我收获了很多东西。比如独立思考能力、分析问题的角度、动手能力等。虽然在规定的时间内完成了任务,但是由于知识和经验的欠缺,整个系统的开发功能还不太完善。在设计过程中也遇到了一些困难,由于需求分析的不全面,导致最初的系统运行不起来。后来问了周围的同学和学长,才把问题解决了。经过这次课设,让我对软件开发流程有了更深的了解,激发了我对专业知识学习的兴趣。让我看到了课堂学习与实际工作的距离,找出学习中存在不足的地方,可以根据目前自身实际存在的问题有选择性的进行学习,加强自身的能力。对于我们这个专业的学生,实际动手能力是很重要的,在今后的学习中要着重于这个方面,才能缩短自己的能力与实际需要的差距。
第 9 页/共 22页
参考文献
[1] 严蔚敏,吴伟民. 数据结构(C 语言版)北京:清华大学出版社,1997: 27-30,91.
[2] 李峰, 谢中科. C语言程序设计. 上海:复旦大学出版社,2011: 21,69-72. [3] 谭浩强,C 语言程序设计题解与上机指导(第三版). 北京:清华大学出版社,2005: 55.
第 10 页/共 22页
附录 源程序清单
//#include #include #include #include #include typedef int status; typedef struct airline {
char flight_num[8]; //航班号 char plane_num[8]; //飞机号 char destination[20]; // 目的地 int total; // 座位总数 int left; // 剩余座位 struct airline *next; // 下一个结点 }airline;
typedef struct customer {
char name[9]; // 顾客名 char flight_num[8]; // 航班号 int seat_num; // 座位号 struct customer *next; // 下一个结点 }customer;
airline *init_airline()
{ // 初始化链表 airline *l;
l=(airline*)malloc(sizeof(airline)); if(l==NULL) { exit(0); }
l->next=NULL; return l; }
customer * init_customer()
{ // 初始化链表 customer *l;
l=(customer*)malloc(sizeof(customer)); if(l==NULL){
第 11 页/共 22页
exit(0); }
l->next=NULL; return l; }
status insert_airline(airline **p,char *flight_num,char *plane_num,char *destination,int total,int left)
{ //airline链表插入操作 airline *q;
q=(airline*)malloc(sizeof(airline)); //初始化 strcpy(q->flight_num , flight_num); //拷贝信息 strcpy(q->plane_num , plane_num); strcpy(q->destination , destination); q->total =total; q->left =left; q->next=NULL; (*p)->next=q; (*p)=(*p)->next; return 1; }
status insert_customer(customer **p,char *name,char *flight_num,int seat) { // customer信息插入操作 customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name , name); //顾客信息拷贝 strcpy(q->flight_num , flight_num); q->seat_num =seat; q->next=NULL; (*p)->next=q; (*p)=(*p)->next; return 1; }
airline *modefy_airline(airline *l,char *flight_num) // 修改airline 中的数据 {
airline *p; p=l->next ;
for(;p!=NULL;p=p->next ) { if(strcmp(flight_num,p->flight_num )==0) //查找 { p->left ++; return l; }
第 12 页/共 22页
}
printf("No this flight,can't make correction£¡\n"); //查找失败 return 0; }
status delete_airline(airline *h,char *flight_num) // 删除航班 {
airline *p,*pr; pr=h;
p=pr->next ; while(p!=NULL) { if(strcmp(flight_num,p->flight_num )==0) { pr->next =p->next ; printf("Delete %s flight\n",p->flight_num ); return 1; } pr=pr->next ; p=pr->next ; }
printf("No this flight£¬can't delete£¡\n"); return 0; }
status delete_customer(customer *h,char *flight_num) {
customer *p,*pr; pr=h;
p=pr->next ; while(p!=NULL) { if(strcmp(flight_num,p->flight_num )==0) { pr->next =p->next ; } pr=pr->next ; p=pr->next ; }
return 1; }
status delete_cus(customer *h,airline *l,char *name) {
customer *p,*pr; char flight_num[8]; pr=h;
第 13 页/共 22页
//信息匹配 //无该信息 // 顾客信息删除 //信息匹配 //顾客退票
p=pr->next ; while(p!=NULL) { if(strcmp(name,p->name )==0) //找顾客姓名 { strcpy(flight_num,p->flight_num ); //找航班信息 l=modefy_airline(l,flight_num); //修改该航班信息 pr->next =p->next ; printf("Customer %s return tickets successed!\n",p->name ); return 1; } pr=pr->next ; p=pr->next ; }
printf("No this customer£¬can't return£¡\n"); return 0; }
status save_airline(airline *l) //保存airline.dat {
FILE *fp_airline; char ch='#';
airline *p=l->next ;
char filename[]="c:\\airline.dat"; //寻找C 盘中的航班信息 if((fp_airline=fopen(filename,"wb"))==NULL) { printf("can not open file to write:%s\n",filename); return 0; }
for(;p!=NULL;p=p->next ) {
fprintf(fp_airline,"%s,%s,%s,%d,%d,%c",p->flight_num,p->plane_num,p->destination,p->total,p->left,ch); fflush(stdin); }
fclose(fp_airline); return 1; }
status save_customer(customer *l) // 保存顾客信息 customer.dat. {
FILE *fp_customer; char ch='#';
customer *p=l->next ;
第 14 页/共 22页
char filename[]="c:\\customer.dat"; //寻找C 盘中的顾客信息文件 if((fp_customer=fopen(filename,"wb"))==NULL) { printf("can not open file to write:%s\n",filename); return 0; }
for(;p!=NULL;p=p->next ) {
fprintf(fp_customer,"%s,%s,%d%c",p->name ,p->flight_num ,p->seat_num ,ch); }
fclose(fp_customer); return 1; }
int changStrInt(char *ch) //把字符串转化为整型 {
int a=1,b=0,c=0,i;
for (i=strlen(ch)-1;i>=0;i--) { if (ch[i]='0') { b=a*(ch[i]-'0'); a=a*10; c=c+b; } else { printf("%不合法,无法将此字符转化为整型\n",ch[i]); return 0; } }
return c; }
status insert_air(airline *l,char *flight_num,char *plane_num,char *destination,int total,int left)
{ //airline链表插入操作 airline *q;
q=(airline*)malloc(sizeof(airline)); strcpy(q->flight_num , flight_num); strcpy(q->plane_num , plane_num); strcpy(q->destination , destination); q->total =total; q->left =left;
第 15 页/共 22页
q->next=l->next ; l->next=q; return 1; }
status insert_cus(customer *l,char *name,char *flight_num,int seat)
{ //customer链表插入操作 customer *q;
q=(customer*)malloc(sizeof(customer)); strcpy(q->name , name);
strcpy(q->flight_num , flight_num); q->seat_num =seat; q->next=l->next ; l->next=q; return 1; }
status load_airline(airline *l) //读入文件中航班信息 {
FILE *fp_airline; int flag=0,i=0; char ch;
char flight_num[8]="\0"; // 航班号 char plane_num[8]="\0"; //飞机号 char destination[20]="\0"; // 目的地 char total_str[5]="\0"; char left_str[5]="\0";
int total; // 座位总数 int left; //剩余座位数 char filename[]="c:\\airline.dat";
if((fp_airline=fopen(filename,"r"))==NULL) {
printf("can not open file to load:%s\n",filename); return 0; }
while(!feof(fp_airline)) {
ch=fgetc(fp_airline); if(ch!='#') { if(flag==0&&ch!=',') { flight_num[i]=ch; i++; } else if(flag==1&&ch!=',') {
第 16 页/共 22页
plane_num[i]=ch; i++; } else if(flag==2&&ch!=',') { destination[i]=ch; i++; } else if(flag==3&&ch!=',') { total_str[i]=ch; i++; } else if(flag==4&&ch!=',') { left_str[i]=ch; i++; } else if (ch==',') { if(flag==0) flight_num[i]='\0'; else if(flag==1) plane_num[i]='\0'; else if(flag==2) destination[i]='\0'; else if(flag==3) total_str[i]='\0'; else left_str[i]='\0'; flag++; i=0; } } else { flag=0; i=0; total=changStrInt(total_str); left=changStrInt(left_str);
printf("%8s%8s%8s%9d%9d\n",flight_num ,plane_num ,destination ,total ,left ); fflush(stdin);
////insert_air(l,flight_num,plane_num,destination,total,left); } }
fclose(fp_airline); return 1; }
status load_customer(customer *l) //从文件读入顾客信息 {
FILE *fp_customer; int flag=0,i=0;
第 17 页/共 22页
char ch;
char name[9]="\0";
char flight_num[8]="\0"; // 航班号 char seat_num_str[5]="\0";
int seat_num; //座位 char filename[50]="c:\\customer.dat";
if((fp_customer=fopen(filename,"r"))==NULL) { printf("can not open file to load:%s\n",filename); return 0; }
while(!feof(fp_customer)) { ch=fgetc(fp_customer); if(ch!='#') { if(flag==0&&ch!=',') { name[i]=ch; i++; } else if(flag==1&&ch!=',') { flight_num[i]=ch; i++; } else if(flag==2&&ch!=',') { seat_num_str[i]=ch; i++; } else if (ch==',') { if(flag==0) name[i]='\0'; else if(flag==1) flight_num[i]='\0'; else seat_num_str[i]='\0'; flag++; i=0; } else { printf("ERROR\n"); return 0; } } else { flag=0; i=0; seat_num=changStrInt(seat_num_str); printf("%15s %15s %10d\n",name ,flight_num ,seat_num );
第 18 页/共 22页
fflush(stdin);
////insert_cus(l,name,flight_num,seat_num); } }
fclose(fp_customer); return 1; }
status creat_airline(airline **l) // 创建airline 单链表 {
airline *p=*l; int i=0;
char *flight_num[3]={"bjnc01","bjsh02","shgz03"}; char *plane_num[3]={"plane1","plane2","plane3"}; char *destination[3]={"nc","sh","gz"}; int total[3]={100,100,100}; int left[3]={51,50,78}; for (i=0;i
return 1; }
status creat_customer(customer **l) // 创建customer 单链表 {
customer *p=*l; int i=0;
char *name[3]={"yuyang","lucy","fanhong"};
char *flight_num[3]={"bjnc01","bjsh02","shgz03"}; int seat_num[3]={19,15,10}; for (i=0;i
return 1; }
status increase_air(airline *l,char *flight_num,char *plane_num,char *destination,int total) // 增加航线 {
airline *p=l->next ;
for(;p->next !=NULL;p=p->next){}
insert_airline(&p,flight_num,plane_num,destination,total,total); printf("Adding flight %s successed!\n",flight_num); return 1; }
第 19 页/共 22页
status book(airline *l,char *flight_num,customer *c,char *name) // 订票函数 {
airline *p=l;
customer *q=c->next ; p=l->next ;
for(;q->next !=NULL;q=q->next){} for(;p!=NULL;p=p->next ) { if(strcmp(flight_num,p->flight_num )==0) { if(p->left >0) { printf("Congratulations!Tickets booked!\n"); printf("Your seat_number is: %d\n",(p->total -p->left +1)); insert_customer(&q,name,flight_num,p->total -p->left +1); p->left --; return 1; } else printf("Sorry!Seats full!\n"); return 0; } }
printf("Sorry!No this flight!\n"); return 0; }
status print_airline(airline *l) // 打印航班信息 {
airline *p=l->next ;
for(;p!=NULL;p=p->next ) {
printf("%8s%8s%8s%9d%9d\n",p->flight_num ,p->plane_num ,p->destination ,p->total ,p->left ); }
return 1; }
status print_customer(customer *l) // 打印顾客信息 {
customer *p=l->next ; for(;p!=NULL;p=p->next ) { printf("%10s %10s %d\n",p->name ,p->flight_num ,p->seat_num ); }
第 20 页/共 22页
return 1;
}
void main()
{
char choice,name[9],flight_num[8];
int t=1,k=1;
airline *air=init_airline();
customer *cus=init_customer();
printf("Airline Tickets Book System\n");
printf(" \n");
creat_airline(&air);
creat_customer(&cus);
while(t==1)
{
printf("******************************************\n");
printf("** Welcome To Airline Tickets Book System **\n");
printf("******************************************\n");
printf("*--++++++++-----主菜单-----++++++++++----*\n");
printf("* # 订票------------0 # *\n");
printf("* # 退票------------1 # *\n");
printf("* # 查询 -----------2 # *\n");
printf("* # 信息载入------3 # *\n");
printf("* # 退出-------------4 # *\n");
printf("******************************************\n");
if(k)
{
printf("请选择相应操作: \n"); k=0; }
else printf("请选择相应操作:\n");
choice = getch();
printf("%c\n",choice);
if(choice=='0')
{
printf("Please input your flight number: ");
scanf( "%s",flight_num);
printf("Please input your name: ");
scanf( "%s",name);
book(air,flight_num,cus,name);
save_airline(air);
save_customer(cus);
}
else if(choice=='1')
{
printf("\nPlease input your name: ");
第 21 页/共 22页
scanf( "%s",name);
delete_cus(cus,air,name);
save_airline(air);
save_customer(cus);
}
else if(choice=='2')
{
printf("\n flight_number plane_number destination total tickets_num left tickets_num\n");
print_airline(air);
printf(" name flight_number seat_number\n");
print_customer(cus);
}
else if(choice=='3')
{
printf("flight_num plane_num destination total left\n" );
load_airline(air);
printf("\t name \t\tflight_num\tseat_num \n");
load_customer(cus);
}
else if(choice=='4')
{
printf("Good bye!Please enjoy your travel!"); t=0;
}
else
{
printf("Input error!\n");
}
}
getch();
}
第 22 页/共 22页
1 绪论
1.1 系统设计的目的
为了方便机场工作人员对机票的管理,提高飞机票的管理效率,降低飞机票管理中的出错率,减少信息交流及其带来不必要的开销。需要设计一个民航订票系统,该系统能及时反映航班及机票的剩余数量等信息,可快速的帮乘客订到想要的机票,而乘客也可以通过该系统实现自助退票的功能。
1.2 实现的目标
该系统是由两个人共同设计实现功能,由于一个人的能力有限,该系统仅能实现录入航班信息、查询航班信息、订购飞机票、退订飞机票等一部分功能(航班的信息存储在文件夹中)。
1.3 课题的研究方法
机票管理系统是实现机场机票的预定、统计和分析,提高机票运用的科学管理水平,充分发挥机票利用率,节省订退票时间。系统的主要设计思想是实现对机票的查询、退订等功能。航班的信息以文件的形式存储,用头文件包含、全局变量定义和结构体定义源代码,用结构体数组来存放顾客名、航班号、座位号等信息,用链式结构存储信息。系统的人机接口采用简单的字符界面进行交互。系统的设计方法是结构化设计方法,采用C 语言进行开发。软件开发平台采用Visual C++6.0[1]。
第 1 页/共 22页
2 软件模块结构图
民航订票系统可以分为四个部分,订票、退票、查询信息、信息载入。
图2.1 民航订票系统模块结构图
第 2 页/共 22页
3 详细设计
3.1 数据结构设计
用printf()函数输出界面,typedef struct airline{}定义航班的信息,如航班号、飞机号、目的地、座位总数和剩余座位数等。typedef struct customer{}定义顾客信息,如顾客名、所订航班号和座位号等。初始化链表,并在airline 、customer 链表中操作,实现系统的功能[1]。
3.2 模块设计
3.2.1 界面设计
用printf()函数输出界面,提示用户选择需要的功能,用条件语句捕捉用户输入的选项,并执行代码,进入用户所选的操作界面。若用户输入非选项的字符,则提示输入错误,提醒用户重新选择。
3.2.2 订票模块设计
进入订票模块后,进行订票。若票已经售完,提示用户不能预订该航班的机票。若还有余票,则提示用户输入个人信息订票。订票成功后,系统中该航班的余票减少相应的数量,并将顾客信息存入文件[2]。代码实现:
status book(airline *l,char *flight_num,customer *c,char *name) {
airline *p=l;
customer *q=c->next ; p=l->next ;
for(;q->next !=NULL;q=q->next){} for(;p!=NULL;p=p->next ) {
if(strcmp(flight_num,p->flight_num )==0) {
if(p->left >0)
第 3 页/共 22页
}
}
{ }
else printf("Sorry!Seats full!\n"); return 0;
…… p->left --; return 1;
3.2.3 退票模块设计
进入退票模块后,用户需根据提示填写自己的姓名。退票成功后,该系统自动在余票中增加相应的票数。代码实现:
status delete_cus(customer *h,airline *l,char *name) {
customer *p,*pr; char flight_num[8]; pr=h; p=pr->next ; while(p!=NULL) { }
printf("No this customer£¬can't return£¡\n"); return 0;
第 4 页/共 22页
if(strcmp(name,p->name )==0) { }
pr=pr->next ; p=pr->next ;
……
}
3.2.4 查询模块
进入查询模块,用户可以查询现有的航班路线、航班号、余票数等信息。代码实现:
status print_airline(airline *l) {
printf("%8s%8s%8s%9d%9d\n",p->flight_num ,p->plane_num ,p->destinatiairline *p=l->next ; for(;p!=NULL;p=p->next ) {
on ,p->total ,p->left ); }
3.2.5 修改航班信息模块
进入该模块后,用户可以更改航班的信息。有了这个模块,系统内的信息可以灵活的根据航班的变动而变动。代码实现:
status
increase_air(airline
*l,char
*flight_num,char
*plane_num,char
} return 1;
*destination,int total) { }
第 5 页/共 22页
airline *p=l->next ;
for(;p->next !=NULL;p=p->next){}
insert_airline(&p,flight_num,plane_num,destination,total,total); printf("Adding flight %s successed!\n",flight_num); return 1;
3.2.6 初始化体系统
系统最初默认值为零,因此需要初始化链表,录入航班信息和顾客信息。初始化系统后,系统方可进行运行,进行相应的操作,实现系统的功能[3]。
airline *init_airline()
{ …… }
customer * init_customer()
{ }
status insert_airline(airline **p,char *flight_num,char *plane_num,char *destination,int total,int left)
{ }
status insert_customer(customer **p,char *name,char *flight_num,int seat) {
customer *l;
l=(customer*)malloc(sizeof(customer)); if(l==NULL){ }
l->next=NULL; return l;
……
……
customer *q;
q=(customer*)malloc(sizeof(customer)); strcpy(q->name , name); strcpy(q->flight_num , flight_num); ……
第 6 页/共 22页
4 使用说明及运行实例
4.1 登陆主界面
登陆主界面,按用户需求进行相应操作。
图4.1 主菜单
4.2 订票界面
进入订票界面,输入乘机人的相关信息,系统提示订票成功后方可退出。
图4.2 订票界面
第 7 页/共 22页
4.3 退票界面
进入退票界面,用户输入相关信息,系统提示退票成功后可退出系统。
图4.3 退票界面
4.4 信息载入界面
进入信息载入界面,进行相关操作。
图4.4 信息载入界面
第 8 页/共 22页
5 总结
5.1 系统的局限性
该系统仅能实现订票退票和简单的航班录入操作,飞机的起飞、降落时间并未储存在系统中。机票模块的实际剩余票数不能及时反映到系统平台上,导致显示的余票数量可能和实际数量有偏差。查询模块仅能实现按航班号查询和按起飞抵达城市查询的功能。系统并未提供像航班延飞、乘客是否登机等一些实时性的信息这些功能。在安全性方面,系统没有设置密码,因此只能面向航空公司内部人员。
5.2 心得体会
在用C 语言编写程序的时候,最好的方法就是分模块进行编写,每个功能用一个或多个模块来实现。这样写出来的程序容易读懂,而且在出现错误的时候可以快速的找出错误。
课程设计是我们专业课程知识综合应用的实践训练,在这次课程设计中,我收获了很多东西。比如独立思考能力、分析问题的角度、动手能力等。虽然在规定的时间内完成了任务,但是由于知识和经验的欠缺,整个系统的开发功能还不太完善。在设计过程中也遇到了一些困难,由于需求分析的不全面,导致最初的系统运行不起来。后来问了周围的同学和学长,才把问题解决了。经过这次课设,让我对软件开发流程有了更深的了解,激发了我对专业知识学习的兴趣。让我看到了课堂学习与实际工作的距离,找出学习中存在不足的地方,可以根据目前自身实际存在的问题有选择性的进行学习,加强自身的能力。对于我们这个专业的学生,实际动手能力是很重要的,在今后的学习中要着重于这个方面,才能缩短自己的能力与实际需要的差距。
第 9 页/共 22页
参考文献
[1] 严蔚敏,吴伟民. 数据结构(C 语言版)北京:清华大学出版社,1997: 27-30,91.
[2] 李峰, 谢中科. C语言程序设计. 上海:复旦大学出版社,2011: 21,69-72. [3] 谭浩强,C 语言程序设计题解与上机指导(第三版). 北京:清华大学出版社,2005: 55.
第 10 页/共 22页
附录 源程序清单
//#include #include #include #include #include typedef int status; typedef struct airline {
char flight_num[8]; //航班号 char plane_num[8]; //飞机号 char destination[20]; // 目的地 int total; // 座位总数 int left; // 剩余座位 struct airline *next; // 下一个结点 }airline;
typedef struct customer {
char name[9]; // 顾客名 char flight_num[8]; // 航班号 int seat_num; // 座位号 struct customer *next; // 下一个结点 }customer;
airline *init_airline()
{ // 初始化链表 airline *l;
l=(airline*)malloc(sizeof(airline)); if(l==NULL) { exit(0); }
l->next=NULL; return l; }
customer * init_customer()
{ // 初始化链表 customer *l;
l=(customer*)malloc(sizeof(customer)); if(l==NULL){
第 11 页/共 22页
exit(0); }
l->next=NULL; return l; }
status insert_airline(airline **p,char *flight_num,char *plane_num,char *destination,int total,int left)
{ //airline链表插入操作 airline *q;
q=(airline*)malloc(sizeof(airline)); //初始化 strcpy(q->flight_num , flight_num); //拷贝信息 strcpy(q->plane_num , plane_num); strcpy(q->destination , destination); q->total =total; q->left =left; q->next=NULL; (*p)->next=q; (*p)=(*p)->next; return 1; }
status insert_customer(customer **p,char *name,char *flight_num,int seat) { // customer信息插入操作 customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name , name); //顾客信息拷贝 strcpy(q->flight_num , flight_num); q->seat_num =seat; q->next=NULL; (*p)->next=q; (*p)=(*p)->next; return 1; }
airline *modefy_airline(airline *l,char *flight_num) // 修改airline 中的数据 {
airline *p; p=l->next ;
for(;p!=NULL;p=p->next ) { if(strcmp(flight_num,p->flight_num )==0) //查找 { p->left ++; return l; }
第 12 页/共 22页
}
printf("No this flight,can't make correction£¡\n"); //查找失败 return 0; }
status delete_airline(airline *h,char *flight_num) // 删除航班 {
airline *p,*pr; pr=h;
p=pr->next ; while(p!=NULL) { if(strcmp(flight_num,p->flight_num )==0) { pr->next =p->next ; printf("Delete %s flight\n",p->flight_num ); return 1; } pr=pr->next ; p=pr->next ; }
printf("No this flight£¬can't delete£¡\n"); return 0; }
status delete_customer(customer *h,char *flight_num) {
customer *p,*pr; pr=h;
p=pr->next ; while(p!=NULL) { if(strcmp(flight_num,p->flight_num )==0) { pr->next =p->next ; } pr=pr->next ; p=pr->next ; }
return 1; }
status delete_cus(customer *h,airline *l,char *name) {
customer *p,*pr; char flight_num[8]; pr=h;
第 13 页/共 22页
//信息匹配 //无该信息 // 顾客信息删除 //信息匹配 //顾客退票
p=pr->next ; while(p!=NULL) { if(strcmp(name,p->name )==0) //找顾客姓名 { strcpy(flight_num,p->flight_num ); //找航班信息 l=modefy_airline(l,flight_num); //修改该航班信息 pr->next =p->next ; printf("Customer %s return tickets successed!\n",p->name ); return 1; } pr=pr->next ; p=pr->next ; }
printf("No this customer£¬can't return£¡\n"); return 0; }
status save_airline(airline *l) //保存airline.dat {
FILE *fp_airline; char ch='#';
airline *p=l->next ;
char filename[]="c:\\airline.dat"; //寻找C 盘中的航班信息 if((fp_airline=fopen(filename,"wb"))==NULL) { printf("can not open file to write:%s\n",filename); return 0; }
for(;p!=NULL;p=p->next ) {
fprintf(fp_airline,"%s,%s,%s,%d,%d,%c",p->flight_num,p->plane_num,p->destination,p->total,p->left,ch); fflush(stdin); }
fclose(fp_airline); return 1; }
status save_customer(customer *l) // 保存顾客信息 customer.dat. {
FILE *fp_customer; char ch='#';
customer *p=l->next ;
第 14 页/共 22页
char filename[]="c:\\customer.dat"; //寻找C 盘中的顾客信息文件 if((fp_customer=fopen(filename,"wb"))==NULL) { printf("can not open file to write:%s\n",filename); return 0; }
for(;p!=NULL;p=p->next ) {
fprintf(fp_customer,"%s,%s,%d%c",p->name ,p->flight_num ,p->seat_num ,ch); }
fclose(fp_customer); return 1; }
int changStrInt(char *ch) //把字符串转化为整型 {
int a=1,b=0,c=0,i;
for (i=strlen(ch)-1;i>=0;i--) { if (ch[i]='0') { b=a*(ch[i]-'0'); a=a*10; c=c+b; } else { printf("%不合法,无法将此字符转化为整型\n",ch[i]); return 0; } }
return c; }
status insert_air(airline *l,char *flight_num,char *plane_num,char *destination,int total,int left)
{ //airline链表插入操作 airline *q;
q=(airline*)malloc(sizeof(airline)); strcpy(q->flight_num , flight_num); strcpy(q->plane_num , plane_num); strcpy(q->destination , destination); q->total =total; q->left =left;
第 15 页/共 22页
q->next=l->next ; l->next=q; return 1; }
status insert_cus(customer *l,char *name,char *flight_num,int seat)
{ //customer链表插入操作 customer *q;
q=(customer*)malloc(sizeof(customer)); strcpy(q->name , name);
strcpy(q->flight_num , flight_num); q->seat_num =seat; q->next=l->next ; l->next=q; return 1; }
status load_airline(airline *l) //读入文件中航班信息 {
FILE *fp_airline; int flag=0,i=0; char ch;
char flight_num[8]="\0"; // 航班号 char plane_num[8]="\0"; //飞机号 char destination[20]="\0"; // 目的地 char total_str[5]="\0"; char left_str[5]="\0";
int total; // 座位总数 int left; //剩余座位数 char filename[]="c:\\airline.dat";
if((fp_airline=fopen(filename,"r"))==NULL) {
printf("can not open file to load:%s\n",filename); return 0; }
while(!feof(fp_airline)) {
ch=fgetc(fp_airline); if(ch!='#') { if(flag==0&&ch!=',') { flight_num[i]=ch; i++; } else if(flag==1&&ch!=',') {
第 16 页/共 22页
plane_num[i]=ch; i++; } else if(flag==2&&ch!=',') { destination[i]=ch; i++; } else if(flag==3&&ch!=',') { total_str[i]=ch; i++; } else if(flag==4&&ch!=',') { left_str[i]=ch; i++; } else if (ch==',') { if(flag==0) flight_num[i]='\0'; else if(flag==1) plane_num[i]='\0'; else if(flag==2) destination[i]='\0'; else if(flag==3) total_str[i]='\0'; else left_str[i]='\0'; flag++; i=0; } } else { flag=0; i=0; total=changStrInt(total_str); left=changStrInt(left_str);
printf("%8s%8s%8s%9d%9d\n",flight_num ,plane_num ,destination ,total ,left ); fflush(stdin);
////insert_air(l,flight_num,plane_num,destination,total,left); } }
fclose(fp_airline); return 1; }
status load_customer(customer *l) //从文件读入顾客信息 {
FILE *fp_customer; int flag=0,i=0;
第 17 页/共 22页
char ch;
char name[9]="\0";
char flight_num[8]="\0"; // 航班号 char seat_num_str[5]="\0";
int seat_num; //座位 char filename[50]="c:\\customer.dat";
if((fp_customer=fopen(filename,"r"))==NULL) { printf("can not open file to load:%s\n",filename); return 0; }
while(!feof(fp_customer)) { ch=fgetc(fp_customer); if(ch!='#') { if(flag==0&&ch!=',') { name[i]=ch; i++; } else if(flag==1&&ch!=',') { flight_num[i]=ch; i++; } else if(flag==2&&ch!=',') { seat_num_str[i]=ch; i++; } else if (ch==',') { if(flag==0) name[i]='\0'; else if(flag==1) flight_num[i]='\0'; else seat_num_str[i]='\0'; flag++; i=0; } else { printf("ERROR\n"); return 0; } } else { flag=0; i=0; seat_num=changStrInt(seat_num_str); printf("%15s %15s %10d\n",name ,flight_num ,seat_num );
第 18 页/共 22页
fflush(stdin);
////insert_cus(l,name,flight_num,seat_num); } }
fclose(fp_customer); return 1; }
status creat_airline(airline **l) // 创建airline 单链表 {
airline *p=*l; int i=0;
char *flight_num[3]={"bjnc01","bjsh02","shgz03"}; char *plane_num[3]={"plane1","plane2","plane3"}; char *destination[3]={"nc","sh","gz"}; int total[3]={100,100,100}; int left[3]={51,50,78}; for (i=0;i
return 1; }
status creat_customer(customer **l) // 创建customer 单链表 {
customer *p=*l; int i=0;
char *name[3]={"yuyang","lucy","fanhong"};
char *flight_num[3]={"bjnc01","bjsh02","shgz03"}; int seat_num[3]={19,15,10}; for (i=0;i
return 1; }
status increase_air(airline *l,char *flight_num,char *plane_num,char *destination,int total) // 增加航线 {
airline *p=l->next ;
for(;p->next !=NULL;p=p->next){}
insert_airline(&p,flight_num,plane_num,destination,total,total); printf("Adding flight %s successed!\n",flight_num); return 1; }
第 19 页/共 22页
status book(airline *l,char *flight_num,customer *c,char *name) // 订票函数 {
airline *p=l;
customer *q=c->next ; p=l->next ;
for(;q->next !=NULL;q=q->next){} for(;p!=NULL;p=p->next ) { if(strcmp(flight_num,p->flight_num )==0) { if(p->left >0) { printf("Congratulations!Tickets booked!\n"); printf("Your seat_number is: %d\n",(p->total -p->left +1)); insert_customer(&q,name,flight_num,p->total -p->left +1); p->left --; return 1; } else printf("Sorry!Seats full!\n"); return 0; } }
printf("Sorry!No this flight!\n"); return 0; }
status print_airline(airline *l) // 打印航班信息 {
airline *p=l->next ;
for(;p!=NULL;p=p->next ) {
printf("%8s%8s%8s%9d%9d\n",p->flight_num ,p->plane_num ,p->destination ,p->total ,p->left ); }
return 1; }
status print_customer(customer *l) // 打印顾客信息 {
customer *p=l->next ; for(;p!=NULL;p=p->next ) { printf("%10s %10s %d\n",p->name ,p->flight_num ,p->seat_num ); }
第 20 页/共 22页
return 1;
}
void main()
{
char choice,name[9],flight_num[8];
int t=1,k=1;
airline *air=init_airline();
customer *cus=init_customer();
printf("Airline Tickets Book System\n");
printf(" \n");
creat_airline(&air);
creat_customer(&cus);
while(t==1)
{
printf("******************************************\n");
printf("** Welcome To Airline Tickets Book System **\n");
printf("******************************************\n");
printf("*--++++++++-----主菜单-----++++++++++----*\n");
printf("* # 订票------------0 # *\n");
printf("* # 退票------------1 # *\n");
printf("* # 查询 -----------2 # *\n");
printf("* # 信息载入------3 # *\n");
printf("* # 退出-------------4 # *\n");
printf("******************************************\n");
if(k)
{
printf("请选择相应操作: \n"); k=0; }
else printf("请选择相应操作:\n");
choice = getch();
printf("%c\n",choice);
if(choice=='0')
{
printf("Please input your flight number: ");
scanf( "%s",flight_num);
printf("Please input your name: ");
scanf( "%s",name);
book(air,flight_num,cus,name);
save_airline(air);
save_customer(cus);
}
else if(choice=='1')
{
printf("\nPlease input your name: ");
第 21 页/共 22页
scanf( "%s",name);
delete_cus(cus,air,name);
save_airline(air);
save_customer(cus);
}
else if(choice=='2')
{
printf("\n flight_number plane_number destination total tickets_num left tickets_num\n");
print_airline(air);
printf(" name flight_number seat_number\n");
print_customer(cus);
}
else if(choice=='3')
{
printf("flight_num plane_num destination total left\n" );
load_airline(air);
printf("\t name \t\tflight_num\tseat_num \n");
load_customer(cus);
}
else if(choice=='4')
{
printf("Good bye!Please enjoy your travel!"); t=0;
}
else
{
printf("Input error!\n");
}
}
getch();
}
第 22 页/共 22页