当前位置:首页 » 编程语言 » c语言航空订票系统

c语言航空订票系统

发布时间: 2025-03-28 10:54:06

Ⅰ 编写c语言:飞机订票系统

#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;
}

Ⅱ c语言如何编写飞机订票系统

java">#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>//overflow

#defineok1

typedefstructYidingkehu
{//单链表
charname[15];//已订票的客户姓名
intdingpiaoshu;//已订票数量
structYidingkehu*next1;//
}Yidingkehu,*Link;

typedefstructWeidingkehu
{//单链队
charname[15];//预订票的客户姓名
intyudingpiao;//要订票数量
structWeidingkehu*next2;//下一个链队结点指针
}Weidingkehu,*Qptr;

typedefstructHangxian
{//创建一个含有六个信息的结构体
charhangbanhao[15];//航班号-
charfeijihao[15];//飞机号
intfeixingriqi;//起飞时间
intchenkerenshu;//座位数
intyupiao;//余票
charzhongdianzhai[15];//降落城市
structHangxian*next;//指向下一个链结点的指针
structYidingkehu*yiding;//定义一个指向已订票客户的头结点指针
structWeidingkehu*yudingqueue;
}Hangxian,*Linklist;

LinklistInitLinklist();//01
intInsertLinklist(Linklist&head1);//02

voidhbhchaxun();//通过航班号查询
voidmddchaxun();//通过目的地查询

voidlurugongneng();//初始化录入功能
voidchaxungongnen();//查询功能
voiddingpiaogongnen();//订票功能
voidtuipiaogongnen();//退票功能

voidmain()
{

intn;
do{//打印主界面
printf(" 欢迎使用航空客运订票系统 ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" ==>1.录入功能== ");
printf(" ==>2.查询功能== ");
printf(" ==>3.订票功能== ");
printf(" ==>4.退票功能== ");
printf(" ==>5.退出== ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" 请选择:");
scanf("%d",&n);printf(" ");
switch(n)
{
case1:lurugongneng();//录入功能
break;
case2:chaxungongnen();//查询功能
break;
case3:dingpiaogongnen();//订票功能
break;
case4:tuipiaogongnen();//退票功能
break;
default:exit(0);//退出
}
}while(n==1||n==2||n==3||n==4);
}

voidlurugongneng()//初始化的单链表*********************************************************录入功能
{

Linklistp;
//intm,n;
if(!p)exit(OVERFLOW);
printf(" 请依次输入下面几项内容: ");//这里的输入采用一个个单独输入,避免了乱赋值的现象
printf("航班号 ");
gets(p->hangbanhao);//这里的二个gets主要是因为在回车键的输入,其中的第一个是来接收上次的回车
gets(p->hangbanhao);
printf("飞机号 ");
gets(p->feijihao);
printf("终点站 ");
gets(p->zhongdianzhai);
printf("飞行日期 ");
scanf("%d",&p->feixingriqi);
printf("乘客总数 ");
scanf("%d",&p->chenkerenshu);
printf("余票数 ");
scanf("%d",&p->yupiao);

}

voidchaxungongnen()//******************************************************************查询功能
{
intn;
printf(" 查找航线信息 ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" ==>1.通过目的地查询== ");
printf(" ==>2.通过航班号查询== ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" 请选择:");
scanf("%d",&n);
printf(" ");//格式化
switch(n)
{
case1:mddchaxun();
break;
case2:hbhchaxun();
break;
default:break;
}
}

voidmddchaxun()//通过目的地查询
{
charc[15];
intm;
Linklistp=L;
printf(" 请输入要查询的目的地:");
gets(c);
gets(c);//原因同上
do{
p=p->next;
if(p)
{
m=strcmpi((*p).zhongdianzhai,c);//如果==的话则m=0;
if(m==0)
{
printf(" 航班信息: ");
printf(" 航班号:%s ",p->hangbanhao);
printf(" 飞机号:%s ",p->feijihao);
printf(" 飞行时间:周%d ",p->feixingriqi);
printf(" 余票量:%d ",p->yupiao);
}
}
else
{//如果不匹配的话就做
printf(" 对不起没有你要找的目的地: ");m=0;
}
}while(m!=0);
}

voidhbhchaxun()//通过目的地查询
{
charc[15];
intm;
Linklistp=L;
printf(" 请输入要查询的航班号:");
gets(c);gets(c);printf(" ");
do{
p=p->next;
if(p)
{
m=strcmpi((*p).hangbanhao,c);//如果==的话则m=0;这里的(*p).与p->的作用是一样的
if(m==0)
{
printf(" 航班信息: ");
printf(" 航班号:%s ",p->hangbanhao);
printf(" 飞机号:%s ",p->feijihao);
printf(" 飞行时间:周%d ",p->feixingriqi);
printf(" 余票量:%d ",p->yupiao);
}
}
else
{//如果不匹配的话就做
printf(" 对不起没有你要找的航班号: ");m=0;
}
}while(m!=0);
}

voiddingpiaogongnen()//***************************************************************订票功能
{

charc[15];
intm=1,piao,ydpiao=0,yd=0,n;//
gets(c);
printf("请输入终点站名:");gets(c);printf(" ");
p=L->next;
if(p){
do{//查找一下,是否有这个航班
if(!p)
{
printf("对不起,没有你要找的航班: ");
gotoloop1;
}
m=strcmpi(p->zhongdianzhai,c);
if(m==0)
{
printf("航班信息: ");
printf("航班号:%s ",p->hangbanhao);
printf("飞机号:%s ",p->feijihao);
printf("飞行时间:周%d ",p->feixingriqi);
printf("余票量:%d ",p->yupiao);}
elsep=p->next;
}while(m!=0);
if(m==0)
{
do{
printf(" 请输入你要订的票数:");scanf("%d",&piao);
if(piao<=p->yupiao)
{
h=p->yiding;
if(h)
{
h1=h;
h=h->next1;
h=(structYidingkehu*)malloc(sizeof(Yidingkehu));
printf("请输入你的名字:");
gets(h->name);gets(h->name);
h->dingpiaoshu=piao;
h->next1=h1->next1;
h1->next1=h;
p->yupiao=p->yupiao-piao;
printf("订票成功: ");m=2;
}
}
else
{
printf("余票量:%d ",p->yupiao);
printf("对不起,余票%d张不足,不能完成订票 ",p->yupiao);
printf("是否要重新订票? ");
printf("需要请输入1否则请按2预订请输入3:");
scanf("%d",&m);
printf(" ");
if(m==3)gotoloop3;
}
}while(m==1);
}
}
elseif(!p)
{
loop3:structWeidingkehu*q3;
printf("对不起,该航班的票已售完 ");
q.front=p->yudingqueue;
if(q.front==q.rear)printf("没有人预订票,是否要预订? ");
elseif(q.front!=q.rear)printf("已有人预订票,是否要预订? ");
printf("预订请输入1否则输入2:");
scanf("%d",&n);
printf(" ");
if(n==1)
{

printf("请输入你的姓名");gets(q3->name);gets(q3->name);//q3不能指向name???
printf("请输入订票数");scanf("%d",&q3->yudingpiao);
q3->next2=NULL;
q.rear->next2=q3;
q.rear=q3;
printf("你已经预订了! ");
}
}
loop1:;
}

voidtuipiaogongnen()//***************************************************************退票功能
{

}
///////////以下是人家的要求//////////
1、本系统采用一个包含N个数据的结构体数组,每个数据的结构应当包括:起飞地、目的地航班号、座次号码、座次订出与否标记、订座者的姓名和订座者的身份证号码。
2、本系统显示这样的菜单:
(1)输入航班信息
(2)输出航班信息
(3)查找航班信息
a.显示空座的数量
b.显示空座的信息
c.显示已订座的信息
d.起飞时间
(4)订票预约
(5)删除定票预约
(6)退出系统
1、本系统成功执行菜单的每个信息,选项4)和5)将要求额外的输入,并且它们都允许用户收回其输入。
2、查找航班信息既可按线路查,也可按目的地查。
4、在两次运行之间,数据被保存于一个文件里,当本程序重新开
始的时候,它首先从该文件读入数据

Ⅲ 用C语言写火车订票系统

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int shoudsave=0 ;
int count1=0,count2=0,mark=0,mark1=0 ;
/*定义存储火车信息的结构体*/
struct train
{
char num[10];/*列车号*/
char city[10];/*目的城市*/
char takeoffTime[10];/*发车时间*/
char receiveTime[10];/*到达时间*/
int price;/*票价*/
int bookNum ;/*票数*/
};
/*订票人的信息*/
struct man
{
char num[10];/*ID*/
char name[10];/*姓名*/
int bookNum ;/*需求的票数*/
};
/*定义火车信息链表的结点结构*/
typedef struct node
{
struct train data ;
struct node * next ;
}Node,*Link ;
/*定义订票人链表的结点结构*/
typedef struct people
{
struct man data ;
struct people*next ;
}bookMan,*bookManLink ;
/* 初始界面*/
void printInterface()
{
puts("********************************************************");
puts("* Welcome to use the system of booking tickets *");
puts("********************************************************");
puts("* You can choose the operation: *");
puts("* 1:Insert a train information *");
puts("* 2:Inquire a train information *");
puts("* 3:Book a train ticket *");
puts("* 4:Update the train information *");
puts("* 5:Advice to you about the train *");
puts("* 6:save information to file *");
puts("* 7:quit the system *");
puts("********************************************************");
}
/*添加一个火车信息*/
void InsertTraininfo(Link linkhead)
{
struct node *p,*r,*s ;
char num[10];
r = linkhead ;
s = linkhead->next ;
while(r->next!=NULL)
r=r->next ;
while(1)
{
printf("please input the number of the train(0-return)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break ;
/*判断是否已经存在*/
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("the train '%s'has been born!\n",num);
return ;
}
s = s->next ;
}
p = (struct node*)malloc(sizeof(struct node));
strcpy(p->data.num,num);
printf("Input the city where the train will reach:");
scanf("%s",p->data.city);
printf("Input the time which the train take off:");
scanf("%s",p->data.takeoffTime);
printf("Input the time which the train receive:");
scanf("%s",&p->data.receiveTime);
printf("Input the price of ticket:");
scanf("%d",&p->data.price);
printf("Input the number of booked tickets:");
scanf("%d",&p->data.bookNum);
p->next=NULL ;
r->next=p ;
r=p ;
shoudsave = 1 ;
}
}
/*打印火车票信息*/
void printTrainInfo(struct node*p)
{
puts("\nThe following is the record you want:");
printf(">>number of train: %s\n",p->data.num);
printf(">>city the train will reach: %s\n",p->data.city);
printf(">>the time the train take off: %s\nthe time the train reach: %s\n",p->data.takeoffTime,p->data.receiveTime);
printf(">>the price of the ticket: %d\n",p->data.price);
printf(">>the number of booked tickets: %d\n",p->data.bookNum);
}

struct 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 QueryTrain(Link l)

{
Node *p ;
int sel ;
char str1[5],str2[10];
if(!l->next)
{
printf("There is not any record !");
return ;
}
printf("Choose the way:\n>>1:according to the number of train;\n>>2:according to the city:\n");
scanf("%d",&sel);
if(sel==1)
{
printf("Input the the number of train:");
scanf("%s",str1);
p=Locate1(l,str1,"num");
if(p)
{
printTrainInfo(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)
{
printTrainInfo(p);
}
else
{
mark1=1 ;
printf("\nthe file can't be found!");
}
}
}

/*订票子模块*/
void BookTicket(Link l,bookManLink k)
{
Node*r[10],*p ;
char ch,dem ;
bookMan*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;t<i;t++)
printTrainInfo(r[t]);
if(i==0)
printf("\n\t\t\tSorry!Can't find the train for you!\n");
else
{
printf("\ndo you want to book it?<1/0>\n");
scanf("%d",&ch);
if(ch == 1)
{
h=(bookMan*)malloc(sizeof(bookMan));
printf("Input your name: ");
scanf("%s",&str1);
strcpy(h->data.name,str1);
printf("Input your id: ");
scanf("%s",&str2);
strcpy(h->data.num,str2);
printf("Input your bookNum: ");
scanf("%d",&dem);
h->data.bookNum=dem ;
h->next=NULL ;
v->next=h ;
v=h ;
printf("\nLucky!you have booked a ticket!");
getch();
shoudsave=1 ;
}
}
}
bookMan*Locate2(bookManLink k,char findmess[])
{
bookMan*r ;
r=k->next ;
while(r)
{
if(strcmp(r->data.num,findmess)==0)
{
mark=1 ;
return r ;
}
r=r->next ;
}
return 0 ;
}
/*修改火车信息*/
void UpdateInfo(Link l)
{
Node*p ;
char findmess[20],ch ;
if(!l->next)
{
printf("\nthere isn't record for you to modify!\n");
return ;
}
else
{
QueryTrain(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 train:");
scanf("%s",findmess);
p=Locate1(l,findmess,"num");
if(p)
{
printf("Input new number of train:");
scanf("%s",&p->data.num);
printf("Input new city the train will reach:");
scanf("%s",&p->data.city);
printf("Input new time the train take off");
scanf("%s",&p->data.takeoffTime);
printf("Input new time the train reach:");
scanf("%s",&p->data.receiveTime);
printf("Input new price of the ticket::");
scanf("%d",&p->data.price);
printf("Input new number of people who have booked ticket:");
scanf("%d",&p->data.bookNum);
printf("\nmodifying record is sucessful!\n");
shoudsave=1 ;
}
else
printf("\t\t\tcan't find the record!");
}
}
else
mark1=0 ;
}
}
/*系统给用户的提示信息*/
void AdvicedTrains(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)==0&&r->data.bookNum<200)
{
mar=1 ;
printf("\nyou can select the following train!\n");
printf("\n\nplease select the fourth operation to book the ticket!\n");
printTrainInfo(r);
}
r=r->next ;
}
if(mar==0)
printf("\n\t\t\tyou can't book any ticket now!\n");

}
/*保存火车信息*/
void SaveTrainInfo(Link l)
{
FILE*fp ;
Node*p ;
int count=0,flag=1 ;
fp=fopen("c:\\train.txt","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 SaveBookmanInfo(bookManLink k)
{
FILE*fp ;
bookMan*p ;
int count=0,flag=1 ;
fp=fopen("c:\\man.txt","wb");
if(fp==NULL)
{
printf("the file can't be opened!");
return ;
}
p=k->next ;
while(p)
{
if(fwrite(p,sizeof(bookMan),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);
}

int main()
{
FILE*fp1,*fp2 ;
Node*p,*r ;
char ch1,ch2 ;
Link l ;
bookManLink k ;
bookMan*t,*h ;
int sel ;
l=(Node*)malloc(sizeof(Node));
l->next=NULL ;
r=l ;
k=(bookMan*)malloc(sizeof(bookMan));
k->next=NULL ;
h=k ;
fp1=fopen("c:\\train.txt","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("c:\\man.txt","ab+");
if((fp2==NULL))
{
printf("can't open the file!");
return 0 ;
}

while(!feof(fp2))
{
t=(bookMan*)malloc(sizeof(bookMan));
if(fread(t,sizeof(bookMan),1,fp2)==1)
{
t->next=NULL ;
h->next=t ;
h=t ;
count2++;
}
}
fclose(fp2);
while(1)
{
system("cls");
printInterface();
printf("please choose the operation: ");
scanf("%d",&sel);
system("cls");
if(sel==8)
{
if(shoudsave==1)
{
getchar();
printf("\nthe file have been changed!do you want to save it(y/n)?\n");
scanf("%c",&ch1);
if(ch1=='y'||ch1=='Y')
{
SaveBookmanInfo(k);
SaveTrainInfo(l);
}
}
printf("\nThank you!!You are welcome too\n");
break ;

}
switch(sel)
{
case 1 :
InsertTraininfo(l);break ;
case 2 :
QueryTrain(l);break ;
case 3 :
BookTicket(l,k);break ;
case 4 :
UpdateInfo(l);break ;
case 5 :
AdvicedTrains(l);break ;
case 6 :
SaveTrainInfo(l);SaveBookmanInfo(k);break ;
case 7 :
return 0;
}
printf("\nplease press any key to continue.......");
getch();
}
return 0;
}

Ⅳ C语言程序设计 飞机订票管理系统

编制一个航班订票系统。应具备如下功能:该航班仅有一架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();}}

Ⅳ c语言车票订购系统

#include

#include

#include

#include

int shoudsave=0 ;

int count1=0,count2=0,mark=0,mark1=0 ;

/*定义存储火车信息的结构体*/

struct train

{

char num[10];/*列车号*/

char city[10];/*目的城市*/

char takeoffTime[10];/*发车时间*/

char receiveTime[10];/*到达时间*/

int price;/*票价*/

int bookNum ;/*票数*/

};

/*订票人的信息*/

struct man

{

char num[10];/*ID*/

char name[10];/*姓名*/

int bookNum ;/*需求的票数*/

};

/*定义火车信息链表的结点结构*/

typedef struct node

{

struct train data ;

struct node * next ;

}Node,*Link ;

/*定义订票人链表的结点结构*/

typedef struct people

{

struct man data ;

struct people*next ;

}bookMan,*bookManLink ;

/* 初始界面*/

void printInterface()

{

puts("********************************************************");

puts("* Welcome to use the system of booking tickets *");

puts("********************************************************");

puts("* You can choose the operation: *");

puts("* 1:Insert a train information *");

puts("* 2:Inquire a train information *");

puts("* 3:Book a train ticket *");

puts("* 4:Update the train information *");

puts("* 5:Advice to you about the train *");

puts("* 6:save information to file *");

puts("* 7:quit the system *");

puts("********************************************************");

}

/*添加一个火车信息*/

void InsertTraininfo(Link linkhead)

{

struct node *p,*r,*s ;

char num[10];

r = linkhead ;

s = linkhead->next ;

while(r->next!=NULL)

r=r->next ;

while(1)

{

printf("please input the number of the train(0-return)");

scanf("%s",num);

if(strcmp(num,"0")==0)

break ;

/*判断是否已经存在*/

while(s)

{

if(strcmp(s->data.num,num)==0)

{

printf("the train '%s'has been born!\n",num);

return ;

}

s = s->next ;

}

p = (struct node*)malloc(sizeof(struct node));

strcpy(p->data.num,num);

printf("Input the city where the train will reach:");

scanf("%s",p->data.city);

printf("Input the time which the train take off:");

scanf("%s",p->data.takeoffTime);

printf("Input the time which the train receive:");

scanf("%s",&p->data.receiveTime);

printf("Input the price of ticket:");

scanf("%d",&p->data.price);

printf("Input the number of booked tickets:");

scanf("%d",&p->data.bookNum);

p->next=NULL ;

r->next=p ;

r=p ;

shoudsave = 1 ;

}

}

/*打印火车票信息*/

void printTrainInfo(struct node*p)

{

puts("\nThe following is the record you want:");

printf(">>number of train: %s\n",p->data.num);

printf(">>city the train will reach: %s\n",p->data.city);

printf(">>the time the train take off: %s\nthe time the train reach:
%s\n",p->data.takeoffTime,p->data.receiveTime);

printf(">>the price of the ticket: %d\n",p->data.price);

printf(">>the number of booked tickets:
%d\n",p->data.bookNum);

}

struct 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 QueryTrain(Link l)

{

Node *p ;

int sel ;

char str1[5],str2[10];

if(!l->next)

{

printf("There is not any record !");

return ;

}

printf("Choose the way:\n>>1:according to the number of
train;\n>>2:according to the city:\n");

scanf("%d",&sel);

if(sel==1)

{

printf("Input the the number of train:");

scanf("%s",str1);

p=Locate1(l,str1,"num");

if(p)

{

printTrainInfo(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)

{

printTrainInfo(p);

}

else

{

mark1=1 ;

printf("\nthe file can't be found!");

}

}

}

/*订票子模块*/

void BookTicket(Link l,bookManLink k)

{

Node*r[10],*p ;

char ch,dem ;

bookMan*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;t
printTrainInfo(r[t]);

if(i==0)

printf("\n\t\t\tSorry!Can't find the train for you!\n");

else

{

printf("\ndo you want to book it?<1/0>\n");

scanf("%d",&ch);

if(ch == 1)

{

h=(bookMan*)malloc(sizeof(bookMan));

printf("Input your name: ");

scanf("%s",&str1);

strcpy(h->data.name,str1);

printf("Input your id: ");

scanf("%s",&str2);

strcpy(h->data.num,str2);

printf("Input your bookNum: ");

scanf("%d",&dem);

h->data.bookNum=dem ;

h->next=NULL ;

v->next=h ;

v=h ;

printf("\nLucky!you have booked a ticket!");

getch();

shoudsave=1 ;

}

}

}

bookMan*Locate2(bookManLink k,char findmess[])

{

bookMan*r ;

r=k->next ;

while(r)

{

if(strcmp(r->data.num,findmess)==0)

{

mark=1 ;

return r ;

}

r=r->next ;

}

return 0 ;

}

/*修改火车信息*/

void UpdateInfo(Link l)

{

Node*p ;

char findmess[20],ch ;

if(!l->next)

{

printf("\nthere isn't record for you to modify!\n");

return ;

}

else

{

QueryTrain(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 train:");

scanf("%s",findmess);

p=Locate1(l,findmess,"num");

if(p)

{

printf("Input new number of train:");

scanf("%s",&p->data.num);

printf("Input new city the train will reach:");

scanf("%s",&p->data.city);

printf("Input new time the train take off");

scanf("%s",&p->data.takeoffTime);

printf("Input new time the train reach:");

scanf("%s",&p->data.receiveTime);

printf("Input new price of the ticket::");

scanf("%d",&p->data.price);

printf("Input new number of people who have booked ticket:");

scanf("%d",&p->data.bookNum);

printf("\nmodifying record is sucessful!\n");

shoudsave=1 ;

}

else

printf("\t\t\tcan't find the record!");

}

}

else

mark1=0 ;

}

}

/*系统给用户的提示信息*/

void AdvicedTrains(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)==0&&r->data.bookNum<200)

{

mar=1 ;

printf("\nyou can select the following train!\n");

printf("\n\nplease select the fourth operation to book the ticket!\n");

printTrainInfo(r);

}

r=r->next ;

}

if(mar==0)

printf("\n\t\t\tyou can't book any ticket now!\n");

}

/*保存火车信息*/

void SaveTrainInfo(Link l)

{

FILE*fp ;

Node*p ;

int count=0,flag=1 ;

fp=fopen("c:\\train.txt","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 SaveBookmanInfo(bookManLink k)

{

FILE*fp ;

bookMan*p ;

int count=0,flag=1 ;

fp=fopen("c:\\man.txt","wb");

if(fp==NULL)

{

printf("the file can't be opened!");

return ;

}

p=k->next ;

while(p)

{

if(fwrite(p,sizeof(bookMan),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);

}

int main()

{

FILE*fp1,*fp2 ;

Node*p,*r ;

char ch1,ch2 ;

Link l ;

bookManLink k ;

bookMan*t,*h ;

int sel ;

l=(Node*)malloc(sizeof(Node));

l->next=NULL ;

r=l ;

k=(bookMan*)malloc(sizeof(bookMan));

k->next=NULL ;

h=k ;

fp1=fopen("c:\\train.txt","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("c:\\man.txt","ab+");

if((fp2==NULL))

{

printf("can't open the file!");

return 0 ;

}

while(!feof(fp2))

{

t=(bookMan*)malloc(sizeof(bookMan));

if(fread(t,sizeof(bookMan),1,fp2)==1)

{

t->next=NULL ;

h->next=t ;

h=t ;

count2++;

}

}

fclose(fp2);

while(1)

{

system("cls");

printInterface();

printf("please choose the operation: ");

scanf("%d",&sel);

system("cls");

if(sel==8)

{

if(shoudsave==1)

{

getchar();

printf("\nthe file have been changed!do you want to save it(y/n)?\n");

scanf("%c",&ch1);

if(ch1=='y'||ch1=='Y')

{

SaveBookmanInfo(k);

SaveTrainInfo(l);

}

}

printf("\nThank you!!You are welcome too\n");

break ;

}

switch(sel)

{

case 1 :

InsertTraininfo(l);break ;

case 2 :

QueryTrain(l);break ;

case 3 :

BookTicket(l,k);break ;

case 4 :

UpdateInfo(l);break ;

case 5 :

AdvicedTrains(l);break ;

case 6 :

SaveTrainInfo(l);SaveBookmanInfo(k);break ;

case 7 :

return 0;

}

printf("\nplease press any key to continue.......");

getch();

}

return 0;

}

热点内容
如何清除密码锁上的小程序 发布:2025-03-31 11:29:52 浏览:784
苹果uc清理缓存 发布:2025-03-31 11:15:23 浏览:506
如何在命令栏搜ftp 发布:2025-03-31 11:09:37 浏览:101
109五开最便宜怎么配置 发布:2025-03-31 10:55:49 浏览:70
优酷视频上传加密码 发布:2025-03-31 10:44:18 浏览:675
OCM服务器地址基站地址 发布:2025-03-31 10:44:17 浏览:645
页游传奇脚本 发布:2025-03-31 10:43:44 浏览:35
java文件上传视频 发布:2025-03-31 10:34:03 浏览:985
win7怎么搜索文件夹 发布:2025-03-31 10:34:03 浏览:871
qq怎么用手机改密码 发布:2025-03-31 10:34:01 浏览:928