跪求一个用c语言代码编写的飞机售票分配座位的系统

aglovemm 2008-04-16 04:27:37
AIRLINE RESERVATION SYSTEM

A small airline company has just purchased a computer for its new automated ticket reservation system.
The company director has asked you to design the new system to assign seats for each trip of the 25-seater
airline, which covers the route from Kuala Lumpur to Langkawi and back daily. The business class of
the airline can accommodate 5 people and the economy class can accommodate 20 people. Assume the company
has only 2 airlines - each with a different Airline ID, which travels at two-hour intervals from 9 am to 5 pm daily.

SECTION A: BASIC REQUIREMENTS OF THE SYSTEM

1. Main Menu
Your initial program design should display the following menu alternatives:

AIRLINE RESERVATION SYSTEM
P – to Purchase Ticket
V – to View Seating Arrangement
Q – to Quit the system

2. Submenu
The following submenu will be displayed when P is selected:

PURCHASING MODULE
B – to purchase ticket for Business class
E – to purchase ticket for Economy class
M – to return to Main Menu

3. Assigning Seats
If the person types B, then your program should assign a seat in the business class (seats 1-5). If the person
types E, then your program should assign a seat in the economy class (seats 6 - 25).

4. Boarding Ticket
Your program should then print a boarding ticket indicating the person’s name, seat number, whether it is in
the business or economy class of the airline, date and time of departure, departure point and destination of
the flight and Airline ID.


可用到的c语言应用: Data type, functions , control structures, arrays, pointers, storage classes , structures and unions,files.



...全文
937 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
好像没那么简单,呵呵.
xunfengxxx 2008-04-16
  • 打赏
  • 举报
回复
/*
飞机订票系统(限2 人完成)
  任务: 通过此系统可以实现如下功能:
  录入:  可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
  查询:  可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,
票价折扣,确定航班是否满仓);
可以输入起飞抵达城市,查询飞机航班情况;
订票: (订票情况可以存在一个数据文件中,结构自己设定)
   可以订票,如果该航班已经无票,可以提供相关可选择航班;
  退票: 可退票,退票后修改相关数据文件;
   客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
修改航班信息:  当航班信息改变可以修改航班数据文件
  要求:  根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
//航班信息
typedef struct airline{
char air_num[8];//航班号
char plane_num[8];//飞机号
char end_place[20];//抵达城市
int total;//总的座位数
int left;//剩下的座位
struct airline *next;//下一航班
}airline;
//客户信息
typedef struct customer{
char name[8];//客户姓名
char air_num[8];//所定航班号
int seat_num;//座位号
struct customer *next;//下个客户
}customer;
//存储航班信息
airline *start_air()
{
airline *a;
a=(airline*)malloc(sizeof(airline));
if(a==NULL)
a->next=NULL;
return a;
}
//存储客户信息
customer *start_cus()
{
customer *c;
c=(customer*)malloc(sizeof(customer));
if(c==NULL)
c->next=NULL;
return c;
}
//查询航班是否满仓
airline *modefy_airline(airline *l,char *air_num)
{
airline *p;
p=l->next;
for(;p!=NULL;p=p->next)
{
if(strcmp(air_num,p->air_num)==0)
{
p->left++;
return l;
}
printf("已经没有这个航班了!");
}
return 0;
}
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
{
airline *q;
q=(airline*)malloc(sizeof(airline));
strcpy(q->air_num,air_num);
strcpy(q->plane_num,plane_num);
strcpy(q->end_place,end_place);
q->total=total;
q->left=left;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return OK;
}
int insert_cus(customer **p,char *name,char *air_num,int seat_num)
{
customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name,name);
strcpy(q->air_num,air_num);
q->seat_num=seat_num;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return OK;
}
//定票
xunfengxxx 2008-04-16
  • 打赏
  • 举报
回复
int search(airline *head1,customer *head2)
{
airline *p=head1->next;
customer *cus=start_cus();
airline *air=start_air();
creat_air(&air);
creat_cus(&cus);
char ch1;
printf("请选择按以下哪种信息查询:\n");
printf(" A. 航班号 (air_num) \n");
printf(" B. 飞机号 (plane_num) \n");
printf(" C. 抵达城市 (end_place) \n");
printf(" D. 退出 \n");
int m=1;
while(m==1)
{
getchar();
printf("请选择:");
ch1=getchar();
if(ch1=='A')
{ char a[8];
printf("请输入要查询的航班号:");
scanf("%s",a); //a为地址
for(p=head1->next;p!=NULL;p=p->next)
{ if(!strcmp(p->air_num,a))
{
printf("航班号:%s 飞机号:%s 抵达城市:%s 总座位数:%d 剩余座位:%-8d\n",
p->air_num,p->plane_num,p->end_place,p->total,p->left);
}

}
}
else if(ch1=='B')
{
char b[8];
printf("请输入要查询的飞机号:");
scanf("%s",b);
for(p=head1->next;p!=NULL;p=p->next)//p要变,所以必须初始p=head1->next;
{
if(!strcmp(p->plane_num,b))
printf("航班号:%s 飞机号:%s 抵达城市:%s 总座位数:%d 剩余座位:%-8d\n",
p->air_num,p->plane_num,p->end_place,p->total,p->left);
else
printf("****");
}


}
else if(ch1=='C')
{
char c[8];
printf("请输入要查询的抵达城市:");
scanf("%s",c);
for(p=head1->next;p!=NULL;p=p->next)
{
if(!strcmp(p->end_place,c))
printf("航班号:%s 飞机号:%s 抵达城市:%s 总座位数:%d 剩余座位:%-8d\n",
p->air_num,p->plane_num,p->end_place,p->total,p->left);
else
printf("****");
}

}
else if(ch1=='D')
{
m=0;
}
}
return OK;
}
void main()
{
int t=1,ch;
customer *cus=start_cus();
airline *air=start_air();
char name[8],air_num[8];
creat_air(&air);
creat_cus(&cus);
while(t==1)
{
printf("\n");
printf("*********************************\n");
printf("* 欢迎使用飞机订票系统! *\n");
printf("* 定票--------1 *\n");
printf("* 退票--------2 *\n");
printf("* 查询--------3 *\n");
printf("* 退出--------4 *\n");
printf("*********************************\n");
scanf("%d",&ch);
if(ch==1)
{
printf("请输入航班号:");
scanf("%s",air_num);
printf("请输入你的名字:");
scanf("%s",name);
book(air,air_num,cus,name);
}
else if(ch==2)
{
printf("请输入你想取消航班的乘客的姓名:");
scanf("%s",name);
del_cus(cus,air,name);
}
else if(ch==3)
{
search(air ,cus );
}
else if(ch==4)
{
t=0;
}
}
}
xunfengxxx 2008-04-16
  • 打赏
  • 举报
回复
/*
飞机订票系统(限2 人完成)
  任务: 通过此系统可以实现如下功能:
  录入:  可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
  查询:  可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,
票价折扣,确定航班是否满仓);
可以输入起飞抵达城市,查询飞机航班情况;
订票: (订票情况可以存在一个数据文件中,结构自己设定)
   可以订票,如果该航班已经无票,可以提供相关可选择航班;
  退票: 可退票,退票后修改相关数据文件;
   客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
修改航班信息:  当航班信息改变可以修改航班数据文件
  要求:  根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;
作者QQ:596284989
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
//航班信息
typedef struct airline{
char air_num[8];//航班号
char plane_num[8];//飞机号
char end_place[20];//抵达城市
int total;//总的座位数
int left;//剩下的座位
struct airline *next;//下一航班
}airline;
//客户信息
typedef struct customer{
char name[8];//客户姓名
char air_num[8];//所定航班号
int seat_num;//座位号
struct customer *next;//下个客户
}customer;
//存储航班信息
airline *start_air()
{
airline *a;
a=(airline*)malloc(sizeof(airline));
if(a==NULL)
a->next=NULL;
return a;
}
//存储客户信息
customer *start_cus()
{
customer *c;
c=(customer*)malloc(sizeof(customer));
if(c==NULL)
c->next=NULL;
return c;
}
//查询航班是否满仓
airline *modefy_airline(airline *l,char *air_num)
{
airline *p;
p=l->next;
for(;p!=NULL;p=p->next)
{
if(strcmp(air_num,p->air_num)==0)
{
p->left++;
return l;
}
printf("已经没有这个航班了!");
}
return 0;
}
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
{
airline *q;
q=(airline*)malloc(sizeof(airline));
strcpy(q->air_num,air_num);
strcpy(q->plane_num,plane_num);
strcpy(q->end_place,end_place);
q->total=total;
q->left=left;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return OK;
}
int insert_cus(customer **p,char *name,char *air_num,int seat_num)
{
customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name,name);
strcpy(q->air_num,air_num);
q->seat_num=seat_num;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return OK;
}
//定票
int book(airline *a,char *air_num,customer *c,char *name)
{
airline *p=a;
customer *q=c->next;
p=a->next;

for(;p->next!=NULL;p=p->next)
{
if(p->left>0)
{
printf("定票成功!你的座位是:%d",(p->total-p->left+1));
insert_cus(&q,name,air_num,p->total-p->left+1);
p->left--;
return OK;
}
else
{
printf("seat is full");
}
}
return 0;
}
//退票
int del_cus(customer *c,airline *l,char *name)
{
customer *p,*pr;
char air_num[8];
pr=c;
p=pr->next;
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{
strcpy(air_num,p->air_num);
l=modefy_airline(l,air_num);
pr->next=p->next;
p=pr->next;
printf("成功了!");
return OK;
}
pr=pr->next;
p=pr->next;
}
printf("没有这个乘客!");
return ERROR;
}

int creat_air(airline **l)
{
airline *p=*l;
int i=0;
char *air_num[3]={"007af","008af","009af"};
char *plane_num[3]={"plane1","plane2","plane3"};
char *end_place[3]={"四川","北京","上海"};
int total[3]={100,100,100};
int left[3]={52,54,76};
for(i=0;i<3;i++)
insert_air(&p,air_num[i],plane_num[i],end_place[i],total[i],left[i]);
return OK;
}
int creat_cus(customer **l)
{
customer *p=*l;
int i=0;
char *name[3]={"赵高","虹姝","李刚"};
char *air_num[3]={"007af","008af","009af"};
int seat_num[3]={2,5,7};
for(i=0;i<3;i++)
insert_cus(&p,name[i],air_num[i],seat_num[i]);
return OK;
}
zhanglei_0411 2008-04-16
  • 打赏
  • 举报
回复
多线程可以解决
myullian 2008-04-16
  • 打赏
  • 举报
回复
孙鑫视频里是有一个火车票多线程例子
wwoo_1105 2008-04-16
  • 打赏
  • 举报
回复
多线程嘛,互斥量嘛,孙鑫讲了嘛,可以参考
liyuzhu_1984 2008-04-16
  • 打赏
  • 举报
回复
设置一个锁 用以解决一张票被卖出多次
aglovemm 2008-04-16
  • 打赏
  • 举报
回复
其实大概的要求就是
有个主菜单:
P – 买票
V – 看座位安排表
Q – 退出系统
然后有个P下面有个子菜单:
B – 头等舱
E – 经济舱
M – 返回主菜单
..
小弟我才接触c语言.. 什么都不太懂
现在这个问题不知道的就是 子菜单怎么返回主菜单
还有每次买勒一次票过后 如何返回主菜单继续为下一位客人订票
然后还有 座位安排表 怎么弄...
其他的都会...
还请达人解答........T_T..

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧