实战项目航空查询系统.docx
- 文档编号:12709210
- 上传时间:2023-04-21
- 格式:DOCX
- 页数:32
- 大小:20.59KB
实战项目航空查询系统.docx
《实战项目航空查询系统.docx》由会员分享,可在线阅读,更多相关《实战项目航空查询系统.docx(32页珍藏版)》请在冰豆网上搜索。
实战项目航空查询系统
头文件
/*==========================================================================
=---------->FileName:
head.h
=---------->Author:
solo
=---------->CreatedTime:
Tue20Aug201307:
28:
20PMCST
==========================================================================*/
#ifndef__HEAD_H
#define__HEAD_H
#include
#include
#include
#include
#include
#include"print.h"
typedefstructflight
{
charnumber[10];//航班号
charstaddress[10];//起点站
chararraddress[10];//终点站
chardate[11];//班期
chartype[10];//机型
charstime[6];//起飞时间
charatime[6];//到达时间
intvalue;//票价
}datatype;
typedefstructnode
{
datatypeinfo;
structnode*next;
}node_list,*p_link;
p_linkL;
voidinit_list(p_link*);
voidcreate_list(p_link);
voiddestroy_list(p_link*L);
voidinit_info(void);
voidshow_sort(void);
voidload_info(p_link);
voidsearch_info(void);
voidprintf_list(p_link);
voidsort_number(void);
voidsort_type(void);
voidsort_stime(void);
voidsort_value(void);
voidsort_info(void);
voidinput_info(void);
boolis_empty(p_link);
voidsave_file(p_link);
voidsave_info(p_link);
voidshow_info(void);
voidhelp_file(void);
voiddata_file(intnum);
booldata_changed;
#endif
Main.c主函数
/*==========================================================================
=---------->FileName:
main.c
=---------->Author:
solo
=---------->CreatedTime:
Thu22Aug201309:
56:
38AMCST
==========================================================================*/
#include"inc/head.h"
intmain(void)
{
intn;
init_list(&L);
create_list(L);
Menu:
system("clear");
while
(1)
{
printf(BLUE"\033[44;37;1mFlightSystem\n"NONE);
printf("\033[32m*****************************\n"NONE);
printf("\033[31m*--->1:
Loggingdata<---*\n");
printf("*--->\033[32m2:
Dispaly<---*\n");
printf("*--->\033[31m3:
Search<---*\n");
printf("*--->\033[32m4:
Sort<---*\n");
printf("*--->\033[31m5:
Load<---*\n");
printf("*--->\033[32m6:
Logout<---*\n");
printf("*--->\033[31m7:
Help<---*\n");
printf("*--->\033[32m8:
Exit<---*\n"NONE);
printf("\033[32m*****************************\n"NONE);
printf(BLUE"Enteryouchoose:
"NONE);
while(scanf("%d",&n)!
=1||(n>8||n<1))
{
printf(RED"Error!
!
!
Tryagain!
\n"NONE);
while(getchar()!
='\n');//清空缓存
printf(BLUE"Enteryouchoose:
"NONE);
}
system("clear");
switch(n)
{
case1:
system("clear");
load_info(L);
gotoMenu;
//break;
case2:
system("clear");
show_info();
gotoMenu;
break;
case3:
system("clear");
search_info();
gotoMenu;
//break;
case4:
system("clear");
sort_info();
gotoMenu;
//break;
case5:
system("clear");
save_info(L);
//system("clear");
break;
case7:
system("clear");
help_file();
//system("clear");
break;
case6:
destroy_list(&L);
system("clear");
gotoMenu;
case8:
destroy_list(&L);
exit(0);
default:
destroy_list(&L);
exit
(1);
}
}
return0;
}
子函数
创建
/*==========================================================================
=---------->FileName:
create.c
=---------->Author:
solo
=---------->CreatedTime:
Thu22Aug201310:
15:
00AMCST
==========================================================================*/
#include"../inc/head.h"
/*
*初始化链表
*/
voidinit_list(p_link*L)
{
*L=(p_link)malloc(sizeof(node_list));
if(*L==NULL)
{
perror("malloc");
}
(*L)->next=NULL;
}
/*
*销毁链表
*/
voiddestroy_list(p_link*L)
{
p_linkp=*L,q=NULL;
printf("\033[1;31m系统注销ing......\033[m\n");
sleep
(1);
printf(RED"卡了?
你那破电脑!
\n"NONE);
sleep
(2);
printf("\033[0;32;31m系统回收内存ing......\033[m\n");
sleep
(2);
while(p)
{
q=p->next;//先保存p的next
free(q);
p=q;
}
printf("\033[0;32;32m系统注销成功!
\033[m\n");
}
/*
*向链表中插入数据
*/
voidcreate_list(p_linkL)
{
p_linkp;
inti=0;
datatypemy_info[25]={
{"MU508","东京","北京","2013-08-18","M","18:
11","20:
30",1160},
{"BG008","达卡","曼谷","2013-08-29","B","10:
21","13:
31",1870},
{"CZ3151","深圳","上海","2013-07-28","Z","17:
52","19:
59",960},
{"CA1206","北京","西安","2013-07-29","A","11:
46","13:
17",890},
{"KZ4052","昆明","上海","2013-07-30","K","12:
15","16:
01",860},
{"EU2753","南京","长沙","2013-08-10","E","10:
31","11:
55",738},
{"CZ6344","杭州","南阳","2013-06-29","C","13:
05","14:
50",1080},
{"KY8286","广州","昆明","2013-08-03","K","06:
50","09:
10",1260},
{"SC4698","西宁","青岛","2013-03-19","S","12:
00","16:
20",1398},
{"MF8139","天津","澳门","2013-06-30","M","08:
30","11:
55",1379},
{"3U8764","南京","重庆","2013-10-02","3","21:
01","00:
20",1108},
{"SC4645","杭州","桂林","2013-08-28","S","10:
10","12:
10",1000},
{"CZ4846","深圳","烟台","2013-08-21","C","17:
52","19:
59",1260},
{"3U8689","济南","兰州","2013-05-03","3","10:
05","12:
15",890},
{"TV9835","重庆","林芝","2013-05-21","T","06:
30","08:
45",998},
{"MU2279","南京","伊宁","2012-01-18","M","17:
21","23:
44",1560},
{"HU7343","广州","沈阳","2013-06-29","Q","12:
30","14:
10",1180},
{"ZH9981","深圳","丽江","2013-06-16","Z","20:
52","23:
15",1150},
{"TV9818","西宁","成都","2013-07-29","A","23:
30","01:
00",890},
{"CA3986","太原","拉萨","2013-04-01","C","16:
35","21:
00",1060},
{"MF8313","杭州","珠海","2013-08-18","M","11:
30","14:
50",1020},
{"CA4336","广州","万州","2013-05-13","C","13:
05","15:
20",1098},
{"HU7020","深圳","海口","2013-08-26","H","23:
00","00:
10",960},
{"SC4982","济南","厦门","2013-06-11","S","15:
15","17:
15",1490},
{"ZH1481","天津","运城","2013-07-30","Z","08:
20","09:
40",980},
};
for(i=0;i<25;i++)
{
p=(p_link)malloc(sizeof(node_list));
p->info=my_info[i];
/*尾插入*/
p->next=L->next;
L->next=p;
L=L->next;
}
}
帮助
/*==========================================================================
=---------->FileName:
help.c
=---------->Author:
solo
=---------->CreatedTime:
Thu22Aug201311:
36:
42AMCST
==========================================================================*/
/*
*航空查询系统说明文档
*/
#include"../inc/head.h"
voidhelp_file()
{
FILE*fp=NULL;
char*buffer;
inti=0;
size_tsize;
buffer=(char*)malloc(1024*sizeof(char));
if(buffer==NULL)
{
perror("malloc");
return;
}
if(!
(fp=fopen("help/help.txt","r")))
{
printf("读取文件错误!
\n");
return;
}
while(getline(&buffer,&size,fp)!
=-1)
{
printf("\033[0;32;32m%s\033[m",buffer);
++i;
if(i%20==0)
{
printf(RED"PressEntercontinue\n"NONE);
getchar();
}
}
fclose(fp);
free(buffer);
printf(RED"\nPressEntergotoMenu"NONE);
getchar();
}
航班信息输入
/*==========================================================================
=---------->FileName:
load_info.c
=---------->Author:
solo
=---------->CreatedTime:
Thu22Aug201311:
50:
24AMCST
==========================================================================*/
#include"../inc/head.h"
/*
手动输入航班信息
*/
voidinput_info(void)
{
FILE*fp;
datatypemy_datatype;
if((fp=fopen("help/my_data","a+"))==NULL)
{
printf("Openfilefailed!
\n");
exit
(1);
}
memset(&my_datatype,'\0',sizeof(my_datatype));
printf(BLUE"请输入要插入的航班信息:
\n");
printf("航班号起点站终点站班期机型起飞时间到达时间票价\n"NONE);
p_linkp;
p_linkq=L;
p=(p_link)malloc(sizeof(node_list));
if(p==NULL)
{
perror("malloc");
exit
(1);
}
scanf("%s%s%s%s%s%s%s%d",p->info.number,\
p->info.staddress,\
p->info.arraddress,\
p->info.date,\
p->info.type,\
p->info.stime,\
p->info.atime,\
&p->info.value);
while(q->next!
=NULL)
{
q=q->next;
}
p->next=q->next;
q->next=p;
fwrite(&my_datatype,sizeof(my_datatype),1,fp);
printf("信息输入成功!
\n");
fclose(fp);
}
/*
*打开示例文件
*/
voiddata_file(intnum)
{
FILE*fp=NULL;
char*buffer;
inti=0;
size_tsize;
buffer=(char*)malloc(1024*sizeof(char));
if(buffer==NULL)
{
perror("malloc");
return;
}
if(num==2)
{
if(!
(fp=fopen("help/my_data","r")))
{
printf("读取文件错误!
\n");
return;
}
}
elseif(num==3)
{
if(!
(fp=fopen("help/data","r")))
{
printf("读取文件错误!
\n");
return;
}
}
while(getline(&buffer,&size,fp)!
=-1)
{
printf("\033[0;32;32m%s\033[m",buffer);
++i;
if(i%20==0)
{
//printf(RED"PressEntercontinue\n"NONE);
getchar();
}
}
fclose(fp);
free(buffer);
printf(RED"\nPressEntergotoMenu"NONE);
getchar();
}
/**
*通过文件录入航班信息
*@type;1:
手动录入数据2:
加载自己手动输入的数据3.加载示例数据
*/
voidload_info(p_linkL)
{
inttype;
printf(BLUE"Inputtype\n");
printf("**************************************************************\n");
printf("*1.LoadByHand2.LoadMy_data3.Loadbyfile4.GotoMenu*\n");
printf("**************************************************************\n"NONE);
printf(RED"Enteryouchoose:
"NONE);
scanf("%d",&type);
switch(type)
{
case1:
input_info();
break;
case2:
data_file
(2);
break;
case3:
data_file(3);
break;
default:
break;
}
}
航班信息的保存
/*==========================================================================
=---------->FileName:
save.c
=---------->Author:
solo
=---------->CreatedTime:
Thu22Aug201310:
38:
57AMCST
==========================================================================*/
#include"../inc/head.h"
/*
*判断是否为空
*/
boolis_empty(p_linkL)
{
returnL->next==NULL;
}
/*
*保存数据
*/
voidsave_file(p_linkL)
{
charpath[100];
FILE*fp;
p_linkp=L->next;
printf("请输入保存路径:
");
scanf("%s",path);
if(!
(fp=fopen(path,"a+")))
{
printf("OpenFileFailed!
\n");
exit
(1);
}
while(p)
{
if(fprintf(fp,"%s\t%s\t%s\t%s\t%s\t%s\t
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实战 项目 航空 查询 系统