#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>//overflow
#define ok 1
typedef struct Yidingkehu
{//单链表
char name[15]//已订票的客户姓名
int dingpiaoshu//已订票数量
struct Yidingkehu *next1//
}Yidingkehu,*Link
typedef struct Weidingkehu
{//单链队
char name[15]//预订票的客户姓名
int yudingpiao// 要订票数量
struct Weidingkehu *next2//下一个链队结点指针
}Weidingkehu,*Qptr
typedef struct Hangxian
{//创建一个含有六个信息的结构体
char hangbanhao[15]//航班号-
char feijihao[15]//飞机号
int feixingriqi//起飞时间
int chenkerenshu//座位数
int yupiao//余票
char zhongdianzhai[15]//降落城市
struct Hangxian *next//指向下一个链结点的指针
struct Yidingkehu *yiding//定义一个指向已订票客户的头结点指针
struct Weidingkehu *yudingqueue
}Hangxian,*Linklist
Linklist InitLinklist()//01
int InsertLinklist(Linklist &head1)//02
void hbhchaxun()//通过航班号查询
void mddchaxun()//通过目的地查询
void lurugongneng()//初始化录入功能
void chaxungongnen()//查询功能
void dingpiaogongnen()//订票功能
void tuipiaogongnen()//退票功能
void main()
{
int n
do{ //打印主界面
printf("\t 欢迎使用航空客运订票系统\n")
printf("\t+++++++++++++++++++++++++++++\n")
printf("\t==>1. 录入功能 ==\n")
printf("\t==>2. 查询功能 ==\n")
printf("\t==>3. 订票功能 ==\n")
printf("\t==>4. 退票功能 ==\n")
printf("\t==>5. 退出 ==\n")
printf("\t+++++++++++++++++++++++++++++\n")
printf("\t请选择:")
scanf("%d",&n)printf("\n")
switch(n)
{
case 1: lurugongneng()//录入功能
break
case 2: chaxungongnen()//查询功能
break
case 3: dingpiaogongnen()//订票功能
break
case 4:tuipiaogongnen()//退票功能
break
default :exit(0)//退出
}
}while(n==1||n==2||n==3||n==4)
}
void lurugongneng()//初始化的单链表*********************************************************录入功能
{
Linklist p
//int m,n
if(!p) exit(OVERFLOW)
printf("\t请依次输入下面几项内容:\n\n")//这里的输入采用一个个单独输入,避免了乱赋值的现象
printf("航班号\n")
gets(p->hangbanhao)//这里的二个gets主要是因为在回车键的输入,其中的第一个是来接收上次的回车
gets(p->hangbanhao)
printf("飞机号\n")
gets(p->feijihao)
printf("终点站\n")
gets(p->zhongdianzhai)
printf("飞行日期\n")
scanf("%d",&p->feixingriqi)
printf("乘客总数\n")
scanf("%d",&p->chenkerenshu)
printf("余票数\n")
scanf("%d",&p->yupiao)
}
void chaxungongnen()//******************************************************************查询功能
{
int n
printf("\t 查 找 航 线 信 息 \n")
printf("\t+++++++++++++++++++++++++++++\n")
printf("\t==>1. 通过目的地查询 ==\n")
printf("\t==>2. 通过航班号查询 ==\n")
printf("\t+++++++++++++++++++++++++++++\n")
printf("\t请选择:")
scanf("%d",&n)
printf("\n")//格式化
switch(n)
{
case 1:mddchaxun()
break
case 2:hbhchaxun()
break
default :break
}
}
void mddchaxun()//通过目的地查询
{
char c[15]
int m
Linklist p=L
printf("\t请输入要查询的目的地:")
gets(c)
gets(c)//原因同上
do{
p=p->next
if(p)
{
m=strcmpi((*p).zhongdianzhai,c)//如果==的话则m=0
if(m==0)
{
printf("\t航班信息:\n")
printf("\t航班号:%s\n",p->hangbanhao)
printf("\t飞机号:%s\n",p->feijihao)
printf("\t飞行时间:周%d\n",p->feixingriqi)
printf("\t余票量:%d\n",p->yupiao)
}
}
else
{//如果不匹配的话就做
printf("\t对不起没有你要找的目的地:\n\n")m=0
}
}while(m!=0)
}
void hbhchaxun()//通过目的地查询
{
char c[15]
int m
Linklist p=L
printf("\t请输入要查询的航班号:")
gets(c)gets(c)printf("\n")
do{
p=p->next
if(p)
{
m=strcmpi((*p).hangbanhao,c)//如果==的话则m=0这里的(*p).与p->的作用是一样的
if(m==0)
{
printf("\t航班信息:\n")
printf("\t航班号:%s\n",p->hangbanhao)
printf("\t飞机号:%s\n",p->feijihao)
printf("\t飞行时间:周%d\n",p->feixingriqi)
printf("\t余票量:%d\n\n",p->yupiao)
}
}
else
{//如果不匹配的话就做
printf("\t对不起没有你要找的航班号:\n")m=0
}
}while(m!=0)
}
void dingpiaogongnen()//***************************************************************订票功能
{
char c[15]
int m=1,piao,ydpiao=0,yd=0,n//
gets(c)
printf("请输入终点站名:")gets(c)printf("\n")
p=L->next
if(p) {
do{//查找一下,是否有这个航班
if(!p)
{
printf("对不起,没有你要找的航班:\n\n")
goto loop1
}
m=strcmpi(p->zhongdianzhai,c)
if(m==0)
{
printf("航班信息:\n")
printf("航班号:%s\n",p->hangbanhao)
printf("飞机号:%s\n",p->feijihao)
printf("飞行时间:周%d\n",p->feixingriqi)
printf("余票量:%d\n",p->yupiao)}
else p=p->next
}while(m!=0)
if(m==0)
{
do{
printf("\n请输入你要订的票数:")scanf("%d",&piao)
if(piao<=p->yupiao)
{
h=p->yiding
if(h)
{
h1=h
h=h->next1
h=(struct Yidingkehu*)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("订票成功:\n")m=2
}
}
else
{
printf("余票量:%d\n",p->yupiao)
printf("对不起,余票 %d 张不足,不能完成订票\n\n",p->yupiao)
printf(" 是否要重新订票?\n")
printf("需要请输入1 否则请按2 预订请输入3 : ")
scanf("%d",&m)
printf("\n")
if(m==3) goto loop3
}
}while(m==1)
}
}
else if(!p)
{
loop3: struct Weidingkehu *q3
printf("对不起,该航班的票已售完\n")
q.front=p->yudingqueue
if(q.front==q.rear) printf("没有人预订票,是否要预订?\n")
else if(q.front!=q.rear) printf("已有人预订票,是否要预订?\n")
printf("预订请输入1 否则输入2 : ")
scanf("%d",&n)
printf("\n")
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(" 你已经预订了 !\n")
}
}
loop1:
}
void tuipiaogongnen()//***************************************************************退票功能
{
}
请采纳答案,支持我一下。
#include <stdio.h>#include <stdlib.h>
struct cell
{
char* name
int time
int seat
int saled
} a,b,c,d
int sel=0
void title()
void saleproc()
int saleThread(struct cell* ce,int dd)
void tiupiaoproc()
int tiupiaoThread(struct cell* ce)
void count()
int init(struct cell* ce,char* name,int time,int seat)
{
ce->name=name
ce->time=time
ce->seat=seat
ce->saled=0
return 1
}
int saleThread(struct cell* ce,int dd)
{
if((ce->seat-ce->saled)>=dd)
{
ce->saled+=dd
printf("售票成功!按ESC键返回主菜单\n")
fflush(stdin)
int cc=_getche()
return 1
}
else
{
printf("售票失败---余票不足!按ESC键返回主菜单\n")
fflush(stdin)
int cc=_getche()
return 0
}
}
void saleproc()
{
int f=1
while(f)
{
system("cls")
printf("***********************************\n")
printf("* *\n")
printf("* 厅 影片 时间 余票 *\n")
printf("* *\n")
printf("* A %s %d:%d %3d *\n",a.name,a.time/60,a.time%60,a.seat-a.saled)
printf("* *\n")
printf("* B %s %d:%d %3d *\n",b.name,b.time/60,b.time%60,b.seat-b.saled)
printf("* *\n")
printf("* C %s %d:%d %3d *\n",c.name,c.time/60,c.time%60,c.seat-c.saled)
printf("* *\n")
printf("* D %s %d:%d %3d *\n",d.name,d.time/60,d.time%60,d.seat-d.saled)
printf("* *\n")
printf("***********************************\n")
printf("请选择放映厅(a,b,c,d)和要购的票数(按ESC键返回主菜单)(格式: a 5):\n")
fflush(stdin)
char cc
int dd
dd=_getche()
if(dd==27)
{
f=0
break
}
else
{
cc=(char)dd
}
scanf("%d",&dd)
switch(cc)
{
case 'a':
saleThread(&a,dd)
f=0
break
case 'b':
saleThread(&b,dd)
f=0
break
case 'c':
saleThread(&c,dd)
f=0
break
case 'd':
saleThread(&d,dd)
f=0
break
default:
break
}
}
title()
}
int tiupiaoThread(struct cell* ce)
{
if(ce->saled==0)
{
printf("撞尼玛鬼了 老子一张票都没卖, 哪来的退票???\n")
fflush(stdin)
int cc=_getche()
return 0
}
ce->saled--
printf("退票成功! 按任意键返回主菜单\n")
fflush(stdin)
int cc=_getche()
return 1
}
void tiupiaoproc()
{
int f=1
while(f)
{
system("cls")
printf("***********************************\n")
printf("* *\n")
printf("* 退 票 *\n")
printf("* *\n")
printf("* A %-20s *\n",a.name)
printf("* *\n")
printf("* B %-20s *\n",b.name)
printf("* *\n")
printf("* C %-20s *\n",c.name)
printf("* *\n")
printf("* D %-20s *\n",d.name)
printf("* *\n")
printf("***********************************\n")
printf("请输入要退的厅(a,b,c,d):\n")
char cc
fflush(stdin)
scanf("%c",&cc)
if(cc==' ')
{
f=0
break
}
switch(cc)
{
case 'a':
tiupiaoThread(&a)
f=0
break
case 'b':
tiupiaoThread(&b)
f=0
break
case 'c':
tiupiaoThread(&c)
f=0
break
case 'd':
tiupiaoThread(&d)
f=0
break
default:
break
}
}
title()
}
void countproc()
{
int f=1
while(f)
{
system("cls")
printf("***********************************\n")
printf("* *\n")
printf("* 统 计 *\n")
printf("* *\n")
printf("* A厅: 余票 %3d 上座率 %5.2f%% *\n",a.seat-a.saled,(((float)a.saled/(float)a.seat)*100))
printf("* *\n")
printf("* B厅: 余票 %3d 上座率 %5.2f%% *\n",b.seat-b.saled,(((float)b.saled/(float)b.seat)*100))
printf("* *\n")
printf("* C厅: 余票 %3d 上座率 %5.2f%% *\n",c.seat-c.saled,(((float)c.saled/(float)c.seat)*100))
printf("* *\n")
printf("* D厅: 余票 %3d 上座率 %5.2f%% *\n",d.seat-d.saled,(((float)d.saled/(float)d.seat)*100))
printf("* *\n")
printf("***********************************\n")
printf("按ESC键返回主菜单!\n")
fflush(stdin)
int cc=_getche()
if(cc==27)
{
f=0
break
}
}
title()
}
void title()
{
int f=1
while(f)
{
system("cls")
printf("***********************************\n")
printf("* *\n")
printf("* 欢迎光临牛B电影院 *\n")
printf("* *\n")
printf("* 1. 售 票 *\n")
printf("* *\n")
printf("* 2. 退 票 *\n")
printf("* *\n")
printf("* 3. 统 计 *\n")
printf("* *\n")
printf("* 4. 退 出 *\n")
printf("* *\n")
printf("***********************************\n")
printf("请选择:(1,2,3,4) \n")
fflush(stdin)
scanf("%d",&sel)
getchar()
switch(sel)
{
case 1:
saleproc()
f=0
break
case 2:
tiupiaoproc()
f=0
break
case 3:
countproc()
f=0
break
case 4:
system("exit")
f=0
break
default:
break
}
}
}
int main(int argc, char *argv[])
{
init(&a,"钢铁侠3",18*60+30,150)
init(&b,"致青春",19*60+30,150)
init(&c,"姜戈",20*60+30,150)
init(&d,"生化危机4",20*60+20,100)
title()
return 0
}
#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=0t<it++)
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
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)