飞机订票系统c语言?
发布网友
发布时间:2022-04-23 23:27
我来回答
共2个回答
热心网友
时间:2023-10-03 20:35
编制一个航班订票系统。应具备如下功能:该航班仅有一架100座飞机;该飞机座位分为吸烟区(30个座位)和无烟区(70个);订票系统界面是选择菜单:1.选吸烟区座位号;2.选无烟区座位号;用户输入自己的选择后,该区若有空位,则顺序地分配一个座号;否则致歉;若吸烟区已满而无烟区有空位,则征求顾客意见,是否愿意得到无烟区的空位,若愿意,则在无烟区分配一个座号,否则致歉退出;顾客不得自主挑选座位号;
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<memory.h>
#define LIN 31
#define LIE 71
static int smok[LIN];//吸烟区票
static int nosmoke[LIE];//无烟区票
void Initnosmoke();//初始化
void ASK();void Initsmok();
void nosmok();
void smoke();
int search(int *array,int size);
void show();
int main()
{
Initnosmoke();
Initsmok();show();return 0;}void Initnosmoke()//初始化无烟区票{int sun=0;for(int j=0;j<LIE;j++){sun+=1;nosmoke[j]=sun;}}void Initsmok()//初始化吸烟区票{int k=0;for(int i=0;i<LIN;i++){k+=1;smok[i]=k;}}int search(int *array,int size)/*该函数的作用是用来查看系统中某类票是否卖完,入股卖完了返回1,反之返回的是0*/{int i;for(i=0;i<size;i++){if(array[i]!=0){return 0;}else{;}}return 1;}void nosmok()//购买无烟区票{for(int i=0;i<LIE;i++){if(i<LIE-1){if(nosmoke[i]!=0){printf("你票是:NOSMOKE_%d\n",nosmoke[i]);nosmoke[i]=0;break;}else{;}}else{printf("对不起!NOSMOKE票已售完!");}}}void ASK()/*该函数用来询问客户是否需要买NOSMOKE票当SMOKE票卖完的情况下*/{char ask;printf("NOSMOKE票你要吗?(y/n)\n");ask=getchar();if(ask =='y' || ask=='Y' ){nosmok();}else if(ask=='n' || ask=='N'){printf("谢谢!再见\n");}else{printf("输入错误!\n");}}void smoke()//购买吸烟区票{for(int j=0;j<LIN;j++){if(j<LIN-1){if(smok[j]!=0){printf("你票是: SMOKE_%d\n",smok[j]);smok[j]=0;break;}else{;}}else{printf("对不起!SMOKE票已售完!");{fflush(stdin);int rec=search(nosmoke,LIE);if(rec==0){ASK();}else{printf("谢谢!\n");}}}}}void window(){printf("\t\t欢迎使用航班订票系统\n");printf("\t\t1.吸烟区座位\n");printf("\t\t2.无烟区座位\n");printf("\t\t3.退出系统\n");printf("\t\t请选择(1~3)进行操作:\n");}void show(){system("color 4a");char ch=' ';window();while(ch!='3'){fflush(stdin);ch=getchar();switch(ch){case '1':{smoke();break;}case '2':{nosmok();break;}case '3':{break;}default:break;}window();ch=getchar();}}
热心网友
时间:2023-10-03 20:35
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <conio.h>
#define MAXSIZE 3
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]={
{"beijing", "1", "B8571", "SUN", 3, 1},
{"shanghai","2","S1002","MON",2,5},
{"london","3","L1003","FRI",1,3}
};;
void display(struct airline *info)
{
printf("%8s\t%3s\t%s\t%4s\t\%d\t\%d\t\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飞行日期" "乘员定额" "余票量\n");
while(i < MAXSIZE){
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(i<MAXSIZE)
{
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(i<MAXSIZE)
{
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(amount>info->tkt_amt)
{ printf("\n对不起,您输入的票的数量已经超过乘员定额!");
return;
}
if(amount<=info->tkt_sur)
{
int i;
printf("请输入您的姓名(订票客户):");
scanf("%s",name);
printf("请输入%s票的舱位等级:",name);
scanf("%d",&grade);
info->order=insertlink(info->order,amount,name,grade);
for(i=0;i<amount;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);
scanf ( "回车继续等待%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;
r=(info->wait).rear;
t=f;
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;i<t->req_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;i<t->req_amt;i++)
printf("<%s>'s seat number is:%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;
}
if(f==r) break;
}
}
void sort_tkt()
{
int j;
struct airline t,*info,*p,*q;
p=info=air;
for(p=info;(p+1)->tkt_sur;p++)
for(q=p+1;q->tkt_sur;q++)
{
if(p->tkt_sur<q->tkt_sur)
{
t=*p;
*p=*q;
*q=t;
}
}
printf("终点站名\t航班号\t飞机号\t飞行日期\t乘员定额\t余票量\n");
for(j=0;j<MAXSIZE;j++)
{
display(info);
info++;
}
}
int menu_select()
{
int c;
char s[20];
printf("\n\t\t 航空客运订票系统(by zjhxmjl)\n");
printf(" ******************************************\n");
printf(" ** 1.浏览航线信息 **\n");
printf(" ** 2.浏览已订票客户信息 **\n");
printf(" ** 3.查询航线 **\n");
printf(" ** 4.办理订票业务 **\n");
printf(" ** 5.办理退票业务 **\n");
printf(" ** 6.查看剩余票数并排序 **\n");
printf(" ** 0.退出系统 **\n");
printf(" *******************************************\n");
do
{
printf("请选择:");
scanf("%s",s);
c = atoi(s); /* atoi将字符串转换为整型 */
}while(c < 0||c > 7);
return c;
}
int main()
{
start = air;
for(;;)
{
switch(menu_select())
{
case 1:list();break;
case 2:prtlink();break;
case 3:search();break;
case 4:order();break;
case 5:return_tkt();break;
case 6:sort_tkt();break;
case 0:printf("\n欢迎使用本系统,再见!\n");exit(0);
}
printf("\nPress any key to continue!\n");
getchar();
}
return 0;
}