
正文
c语言飞机订票系统函数 c语言课设飞机订票系统兰州交通大学
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
c语言设计。 跪求真正的高手。
程序好写,我只提供思路,设计界面,将界面与数据库联系,航船信息录入时只需将信息插入数据裤,浏览时信息时只需再次调用数据库查询即可!至于查询方式你可以在数据库查询语句里设定安哪个列名搜索即可!
相关问答
Q1: c语言高手进~~!!
这个其实有很多人问了c语言飞机订票系统函数,
给你一个个人觉得写得比较好c语言飞机订票系统函数的参考一下:)
Q2: c语言程序设计 航班信息管理
#include
#include
#include
#include
(conio.h不是C标准库中的头文件。conio是Console Input/Output(控制台输入输出)的简写,其中定义了通过控制台进行数据输入和数据输出的函数,主要是一些用户通过按键盘产生的对应操作,比如getch()函数等等。)
#define MAXSIZE 4/*定义航线量的最大值*/
typedef struct wat_ros
{ char name[10];/*姓名*/
int req_amt;/*订票量*/
struct wat_ros *next;
}qnode,*qptr;
typedef struct pqueue
{ qptr front;/*等候替补客户名单域的头指针*/
qptr rear;/*等候替补客户名单域的属指针*/
}linkqueue;
typedef struct ord_ros
{ char name[10];/*客户姓名*/
int ord_amt;/*订票量*/
int grade;/*舱位等级*/
struct ord_ros *next;
}linklist;
struct airline
{ char ter_name[10];/*终点站名*/
char air_num[10];/*航班号*/
char plane_num[10];/*飞机号*/
char date[7];/*飞行日期(星期几)*/
int tkt_amt;/*乘员定额*/
int tkt_sur;/*余票量*/
linklist *order;/*乘员名单域,指向乘员名单链表的头指针*/
linkqueue wait;/*等候替补的客户名单域,分别指向排队等候名单队头队尾的指针*/
}lineinfo;
struct airline *start;
struct airline air[MAXSIZE]={{"北京","1","001","SUN",30,15},
{"上海","2","002","MON",40,10},
{"武汉","3","003","FRI",50,14},
{"天津","4","004","TUE",60,20}};
void display(struct airline *info)
/*打印每条航线的基本信息*/
{printf("%8s\t%3s\t%s\t%4s\t\t%3d\t%10d\n",info-ter_name,info-air_num,info-plane_num,info-date,info-tkt_amt,info-tkt_sur);
}
void list()/*打印全部航线信息*/
{ struct airline *info;
int i=0;
info=start;
printf("终点站名\t航班号\t飞机号\t飞行日期\t乘员定额\t余票量\n");
while(iMAXSIZE)
{
display(info);
info++;
i++;
}
printf("\n\n");
}
void search()
/*根据客户提出的终点站名输出航线信息*/
{ struct airline *info,*find();
char name[10];
int i=0;
info=start;
printf("请输入终点站名:");
scanf("%s",name);
while(iMAXSIZE)
{
if(!strcmp(name,info-ter_name)) break;
info++;
i++;
}
if(i=MAXSIZE)
printf("对不起,该航线未找到!\n");
else
{
printf("终点站名\t航班号\t飞机号\t飞行日期\t乘员定额\t余票量\n");
display(info);
}
}
struct airline *find()
/*根据系统提出的航班号查询并以指针形式返回*/
{ struct airline *info;
char number[10];
int i=0;
info=start;
printf("请输入航班号:");
scanf("%s",number);
while(iMAXSIZE)
{
if(!strcmp(number,info-air_num)) return info;
info++;
i++;
}
printf("对不起,该航线末找到!\n");
return NULL;
}
void prtlink()
/*打印订票乘员名单域的客户名单信息*/
{ linklist *p;
struct airline *info;
info=find();
p=info-order;
if(p!=NULL){
printf("客户姓名 订票数额 舱位等级\n");
while(p){
printf("%s\t\t%d\t%d\n",p-name,p-ord_amt,p-grade);
p=p-next;
}
}
else
printf("该航线没有客户信息!!\n");
}
linklist *insertlink(linklist *head,int amount,char name[],int grade)
/*增加订票乘员名单域的客户信息*/
{ linklist *p1,*new1;
p1=head;
new1=(linklist *)malloc(sizeof(linklist));
if(!new1) {printf("\nOut of memory!!\n");return NULL;}
strcpy(new1-name,name);
new1-ord_amt=amount;
new1-grade=grade;
new1-next=NULL;
if(head==NULL)/*若原无订票客户信息*/
{head=new1;new1-next=NULL;}
else
head=new1;
new1-next=p1;
return head;
}
linkqueue appendqueue(linkqueue q,char name[],int amount)
/*增加排队等候的客户名单域*/
{ qptr new1;
new1=(qptr)malloc(sizeof(qnode));
strcpy(new1-name,name);
new1-req_amt=amount;
new1-next=NULL;
if(q.front==NULL)/*若原排队等候客户名单域为空*/
q.front=new1;
else
q.rear-next=new1;
q.rear=new1;
return q;
}
void order()
/*办理订票业务*/
{ struct airline *info;
int amount,grade;
char name[10];
info=start;
if(!(info=find())) return;/*根据客户提供的航班号进行查询,如为空,退出该模块*/
printf("请输入你订票所需要的数量:");
scanf("%d",amount);
if(amountinfo-tkt_amt)/*若客户订票额超过乘员定票总额,退出*/
{ printf("\n对不起,您输入的票的数量已经超过乘员定额!");
return;
}
if(amounttkt_sur)/*若客户订票额末超过余票量,订票成功并等记信息*/
{
int i;
printf("请输入您的姓名(订票客户):");
scanf("%s",name);
printf("请输入%s票的舱位等级:",name);
scanf("%d",grade);
info-order=insertlink(info-order,amount,name,grade);/*在订票乘员名单域中添加客户信息*/
for(i=0;iamount;i++)/*依次输出该订票客户的座位号*/
printf("%s的座位号是:%d\n",name,info-tkt_amt-info-tkt_sur+i+1);
info-tkt_sur-=amount;/*该航线的余票量应减掉该客户的订票量*/
printf("\n祝您乘坐愉快!\n");
}
else /*若满员或余票额少于订票额,询问客户是否需要进行排队等候*/
{ char r;
printf("\n已经没有更多的票,您需要排队等候吗?(Y/N)");
r=getch();
printf("%c",r);
if(r=='Y'||r=='y')
{ printf("\n请输入您的姓名(排队订票客户):");
scanf("%s",name);
info-wait=appendqueue(info-wait,name,amount);/*在排队等候乘员名单域中添加客户信息*/
printf("\n注册成功!\n");
}
else printf("\n欢迎您下次再次订购!\n");
}
}
void return_tkt()
/*退票模块*/
{ struct airline *info;
qnode *t,*back,*f,*r;
int grade;
linklist *p1,*p2,*head;
char cusname[10];
if(!(info=find())) return;/*调用查询函数,根据客户提供的航线进行搜索*/
head=info-order;
p1=head;
printf("请输入你的姓名(退票客户):");
scanf("%s",cusname);
while(p1!=NULL) {/*根据客户提供的姓名到订票客户名单域进行查询*/
if(!strcmp(cusname,p1-name)) break;
p2=p1;p1=p1-next;
}
if(p1==NULL){ printf("对不起,你没有订过票!\n");return;}/*若未找到,退出本模块*/
else
{/*若信息查询成功,删除订票客户名单域中的信息*/
if(p1==head) head=p1-next;
else p2-next=p1-next;
info-tkt_sur+=p1-ord_amt;
grade=p1-grade;
printf("%s成功退票!\n",p1-name);
free(p1);
}
info-order=head;/*重新将航线名单域指向订票单链表的头指针*/
f=(info-wait).front;/*f指向排队等候名单队列的头结点*/
r=(info-wait).rear;/*r指向排队等候名单队列的尾结点*/
t=f;/*t为当前满点条件的排队候补名单域*/
while(t)
{
if(info-tkt_sur=info-wait.front-req_amt)
{/*若满足条件者为头结点*/
int i;
info-wait.front=t-next;
printf("%s订票成功!\n",t-name);
for(i=0;ireq_amt;i++)/*输出座位号*/
printf("%s的座位号是:%d\n",t-name,(info-tkt_sur)-i);
info-tkt_sur-=t-req_amt;
info-order=insertlink(info-order,t-req_amt,t-name,grade);/*插入到订票客户名单链表中*/
free(t);
break;
}
back=t;t=t-next;
if((info-tkt_sur)=(t-req_amt)t!=NULL)/*若满足条件者不为头结点*/
{ int i;
back-next=t-next;
printf("%s订票成功!\n",t-name);
for(i=0;ireq_amt;i++)/*输出座位号*/
printf("
Q3: C语言编写一个简单的航空管理系统
需要分析:
A.车寻航线:
1.根据旅客提出的起点站,终点站名输出下列信息:航班号,票价,折扣,最多载客量,是否满载,起飞时间,降落时间和飞行时间;
2.根据订票乘客的姓名可以查询所订航班的航班号,座位号,飞行日期等信息;
3.根据航班号查询航班的起点站,中转站,终点站名,票价,折扣,最多载客量,是否满载,起飞时间,降落时间和飞行时间;
B.承办客户提出的要求(航班号、订票数额)查询该航班票额情况,若有余票,则为客户办理订票手续,输出座位号,需付款项信息;若已满员或余票额少于盯票额,则需重新询问客户要求。若需要,可登记排队候补;
C.根据客户提供的情况(日期、航班),为客户办理退票手续。(然后查询该航班是否有人排队候补,首先询问排第一的客户,若所退票额所能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补客户);
E.内部人员对航班情况的控制:
可以录入航班信息,删除航班信息,修改航班信息,查看基本航班信息。
概要设计:
因为每个客户名单或查询名单都包括多个数据域,这样就需要有一个能存储多个数据域的数据类型来存储,因此采用单链表类型。由于航线的信息是固定的,可选用结构体数组,又因为订票与预约人数无法预计,可选用链表存储信息。
线性表的单链表存储结构:typedef struct LNode{
ElemType;
Struct Lnode*next;}LNode,*LinkList;
a.抽象数据类型顺序表的定义如下:
ADT SqList{
数据对象:D={ai|ai∈数据类型,i=1,2,3...,n}
数据关系:R1={ai-1,ai|ai-1,ai∈D,i=1,2,3...,n}
基本操作:
InitList_Sq(L)
操作结果:创建空的顺序表。
CreatList_Sq(L)
操作结果:建立顺序表。
}ADT SqList
b.抽象数据类型单链表的定义如下:
ADT LinkList{
数据对象:D={ai|ai∈结构类型,i=1,2,3...,n,n0}
数据关系:R1={ai-1,ai|ai-1,ai∈D,i=1,2,3...,n}
基本操作:
InitList_L(L)
操作结果:创建空的顺序表。
}ADT LinkList
在main()里调用各个函数
2.主程序
void main(){
初始化;
do{
接受命令;
处理命令;
}while(“命令”!=“退出”);
}
3.程序的模块调用:
三.详细设计:
1.所有数据类型:
struct plan /*航班数据*/
{
char num[5];/*航班号码*/
char city[10];/*到达城市*/
char up[8];/*航班起飞时间*/
char down[8];/*航班到达时间*/
int pric ;/*航班价格*/
int rshu ;/*人数*/
int zheg[4];/*价格折扣*/
}
;
struct man/*定票人数据*/
{
char num[10];/*身份证号码*/
char nam[10];/*姓名*/
int demand ;/*定票数量*/
}
;
typedef struct node/*航班数据结点*/
{
struct plan data ;
struct node*next ;
}
Node,*Link ;
typedef struct people/*乘客数据结点*/
{
struct man data ;
struct people*next ;
}
peo,*LIN ;
2.程序所用函数:
void print()/*界面输出*/
{
printf("============================System of book ticket===============================\n");
printf("\n");
printf("\t***********************************************************\n");
printf("\t*\t1---Bookticket \t2---Dishonorbill *\n");
printf("\t*\t3---Adding flight\t4---Adding flight *\n");
printf("\t*\t5---Modify \t6---Advice *\n");
printf("\t*\t7---Save \t8---exit *\n");
printf("\t##########################################################\n");
}
添加航班模块
void add(Link l)/*添加航班数据*/
{
Node*p,*r,*s ;
char num[10];
r=l ;
s=l-next ;
while(r-next!=NULL)
r=r-next ;
while(1)
{
printf("please input the number of the plan(0-return)");/*输入0就返回*/
scanf("%s",num);
if(strcmp(num,"0")==0)
break ;
while(s)
{
if(strcmp(s-data.num,num)==0)
{
printf("=====tip:the number'%s'has been born!\n",num);
return ;
}
s=s-next ;
}
p=(Node*)malloc(sizeof(Node));/*航班数据输入*/
strcpy(p-data.num,num);
printf("Input the city where the plan will reach:");/*飞机到达地城市*/
scanf("%s",p-data.city);
getchar();
printf("Input the time which the plan take off:");/*起飞时间*/
scanf("%s",p-data.up);
getchar();
printf("Input the time which the plan reach:");/*降落时间*/
scanf("%s",p-data.down);
getchar();
printf("Input the price of ticket:$");/*机票价格*/
scanf("%d",p-data.pric);
getchar();
printf("Input the number of people who have booked ticket:");/*定票数量*/
scanf("%d",p-data.rshu);
getchar();
printf("Input the agio of the ticket:");
scanf("%s",p-data.zheg);
getchar();
p-next=NULL ;
r-next=p ;
r=p ;
shoudsave=1 ;
}
}
输出模块
void pri(Node*p)/*输出函数*/
{
printf("\n\t\t\tThe following is the record you want:\n");
printf("\nnumber of plan: %s",p-data.num);
printf("\ncity the plan will reach: %s",p-data.city);
printf("\nthe time the plan take off: %s\nthe time the plan reach: %s",p-data.up,p-data.down);
printf("\nthe price of the ticket: %d",p-data.pric);
printf("\nthe number of people who have booked ticket: %d",p-data.rshu);
printf("\nthe agio of the ticket:%s",p-data.zheg);
}
退出函数模块
Node*Locate1(Link l,char findmess[],char numorcity[])
{
Node*r ;
if(strcmp(numorcity,"num")==0)
{
r=l-next ;
while(r)
{
if(strcmp(r-data.num,findmess)==0)
return r ;
r=r-next ;
}
}
else if(strcmp(numorcity,"city")==0)
{
r=l-next ;
while(r)
{
if(strcmp(r-data.city,findmess)==0)
return r ;
r=r-next ;
}
}
return 0 ;
}
航班信息模块
void qur(Link l)/*航班信息查询*/
{
Node*p ;
int sel ;
char str1[5],str2[10];
if(!l-next)
{
printf("TIP:there are not any record to be inquired for you!");
return ;
}
printf("Choose the way:(1-according to the number of plan;2-according to the city):");/*选择航班号查询和终点城市查询*/
scanf("%d",sel);
if(sel==1)
{
printf("Input the the number of plan:");
scanf("%s",str1);
p=Locate1(l,str1,"num");
if(p)
{
printf("the following is what you want:\n");
pri(p);
}
else
{
mark1=1 ;
printf("\nthe file can't be found!");
}
}
else if(sel==2)
{
printf("Input the city:");
scanf("%s",str2);
p=Locate1(l,str2,"city");
if(p)
{
printf("the following is what you want:\n");
pri(p);
}
else
{
mark1=1 ;
printf("\nthe file can't be found!");
}
}
}
定票模块
void buy(Link l,LIN k)/*定票函数*/
{
Node*r[10],*p ;
int ch,dem ;
peo*v,*h ;
int i=0,t=0 ;
char str[10],str1[10],str2[10];
v=k ;
while(v-next!=NULL)
v=v-next ;
printf("Input the city you want to go: ");/*航班终点站城市*/
scanf("%s",str);
p=l-next ;
while(p!=NULL)
{
if(strcmp(p-data.city,str)==0)
{
r[i]=p ;
i++;
}
p=p-next ;
}
printf("\n\nthe number of record have %d\n",i);
for(t=0;ti;t++)
pri(r[t]);
if(i==0)
printf("\n\tSorry!Can't find the plan for you!\n");
else
{
printf("\ndo you want to book it?1/0\n");
printf("please choose: ");
scanf("%d",ch);
if(ch==1)
{
h=(peo*)malloc(sizeof(peo));/*重新分配空间*/
printf("Input your name: ");
scanf("%s",str1);
strcpy(h-data.nam,str1);
printf("Input your id: ");
scanf("%s",str2);
strcpy(h-data.num,str2);
printf("Input your demand: ");
scanf("%d",dem);
h-data.demand=dem ;
h-next=NULL ;
v-next=h ;
v=h ;
printf("\n\tLucky!Success in booking ticket!");
getch();
shoudsave=1 ;
}
}
}
peo*Locate2(LIN k,char findmess[])
{
peo*r ;
r=k-next ;
while(r)
{
if(strcmp(r-data.num,findmess)==0)
{
mark=1 ;
return r ;
}
r=r-next ;
}
return 0 ;
}
退票模块
void tui(LIN k)/*退票函数*/
{
char str[10];
peo*p,*r ;
int ch2=0 ;
printf("Input your id: ");/*输入身份证号*/
scanf("%s",str);
p=Locate2(k,str);
if(mark!=1)
printf("can't find the people!");
else if(mark==1)
{
mark=0 ;
printf("\t\t\tthe following is the record you want:\n");
printf("your id:%s\n",p-data.num);
printf("name:%s\n",p-data.nam);
printf("your denmand:%d",p-data.demand);
printf("\ndo you want to refund the ticket?1/0");
scanf("%d",ch2);
if(ch2==1)
{
if(p)
{
r=k ;
while(r-next!=p)
r=r-next ;
r-next=p-next ;
free(p);
}
count2--;
printf("\nyou have sucessed in refunding ticket!");
shoudsave=1 ;
}
}
}
void Modify(Link l)/*修改航班信息*/
{
Node*p ;
char findmess[20],ch ;
if(!l-next)
{
printf("\n=====tip:there isn't record for you to modify!\n");
return ;
}
else
{
qur(l);
if(mark1==0)
{
printf("\nDo you want to modify it?\n");
getchar();
scanf("%c",ch);
if(ch=='y');
{
printf("\nInput the number of the plan:");
scanf("%s",findmess);
p=Locate1(l,findmess,"num");
if(p)
{
printf("Input another number of plan:");
scanf("%s",p-data.num);
getchar();
printf("Input another city the plan will reach:");
scanf("%s",p-data.city);
getchar();
printf("Input another time the plan take off");
scanf("%s",p-data.up);
printf("Input another time the plan reach:");
scanf("%s",p-data.down);
printf("Input another price of the ticket::");
scanf("%d",p-data.pric);
printf("Input another number of people who have booked ticket:");
scanf("%d",p-data.rshu);
printf("Input another agio of the ticket:");
scanf("%s",p-data.zheg);
printf("\n=====tip:modifying record is sucessful!\n");
shoudsave=1 ;
}
else
printf("\tcan't find the flight!");
}
}
else
mark1=0 ;
}
}
void advice(Link l)/*终点站航班查询*/
{
Node*r ;
char str[10];
int mar=0 ;
r=l-next ;
printf("Iuput the city you want to go: ");/*输入终点站城市*/
scanf("%s",str);
while(r)
{
if(strcmp(r-data.city,str)==0r-data.rshu200)
{
mar=1 ;
printf("\nyou can select the following plan!\n");
printf("\n\nplease select the fourth operation to book the ticket!\n");
pri(r);
}
r=r-next ;
}
if(mar==0)
printf("\n\t\t\tyou can't book any ticket now!\n");
}
void save1(Link l)/*保存数据*/
{
FILE*fp ;
Node*p ;
int count=0,flag=1 ;
fp=fopen("g:\\data1","wb");
if(fp==NULL)
{
printf("the file can't be opened!");
return ;
}
p=l-next ;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p-next ;
count++;
}
else
{
flag=0 ;
break ;
}
}
if(flag)
{
printf("the number of the record which have been saved is %d\n",count);
shoudsave=0 ;
}
fclose(fp);
}
void save2(LIN k) /*保存数据*/
{
FILE*fp ;
peo*p ;
int count=0,flag=1 ;
fp=fopen("g:\\data2","wb");/*文件连接*/
if(fp==NULL)
{
printf("the file can't be opened!");
return ;
}
p=k-next ;
while(p)
{
if(fwrite(p,sizeof(peo),1,fp)==1)
{
p=p-next ;
count++;
}
else
{
flag=0 ;
break ;
}
}
if(flag)
{
printf("the number of the record which have been saved is %d\n",count);
shoudsave=0 ;
}
fclose(fp);
}
四.主函数模块:
main()
{
FILE*fp1,*fp2 ;
Node*p,*r ;
char ch1,ch2 ;
Link l ;
LIN k ;
peo*t,*h ;
int sel ;
l=(Node*)malloc(sizeof(Node));
l-next=NULL ;
r=l ;
k=(peo*)malloc(sizeof(peo));
k-next=NULL ;
h=k ;
fp1=fopen("g:\\data1","ab+");
if((fp1==NULL))
{
printf("can't open the file!");
return 0 ;
}
while(!feof(fp1))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp1)==1)
{
p-next=NULL ;
r-next=p ;
r=p ;
count1++;
}
}
fclose(fp1);
fp2=fopen("g:\\data2","ab+");
if((fp2==NULL))
{
printf("can't open the file!");
return 0 ;
}
while(!feof(fp2))
{
t=(peo*)malloc(sizeof(peo));
if(fread(t,sizeof(peo),1,fp2)==1)
{
t-next=NULL ;
h-next=t ;
h=t ;
count2++;
}
}
fclose(fp2);
while(1)
{
getch();
clrscr();
print();
printf("please choose the operation(1-8): ");
scanf("%d",sel);
if(sel==8)
{
if(shoudsave==1)
{
getchar();
printf("\n=====tip:the file have been changed!do you want to save it(y/n)?\n");
scanf("%c",ch1);
if(ch1=='y'||ch1=='Y')
{
save2(k);
save1(l);
}
}
printf("\n\tyou have exited! Happy serve for you");
break ;
}
switch(sel)
{
case 1 :
buy(l,k);
break ;
case 2 :
tui(k);
break ;
case 3 :
qur(l);
break ;
case 4 :
add(l);
break ;
case 5 :
Modify(l);
break ;
case 6 :
advice(l);
break ;
case 7 :
{
save1(l);
save2(k);
break ;
}
case 8 :
exit(0);
}
}
getch();
}
c语言飞机订票系统函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语言课设飞机订票系统兰州交通大学、c语言飞机订票系统函数的信息别忘了在本站进行查找喔。






