今天给各位分享c语言订票系统代码的知识,其中也会对c语言编写火车订票系统进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
1、谁有关于航空公司订票管理系统的c语言代码啊2、飞机订票系统设计 c语言3、c语言车票订购系统4、用C语言写火车订票系统5、求c语言,电影院售票管理系统的设计与实现的代码6、用C语言编写一个车票管理系统
谁有关于航空公司订票管理系统的c语言代码啊
没分啊,那我就拷一个还看得过去的给你吧:
#includestdio.h
#includestring.h
struct inf
{
char name[20];
long ID;
};
struct inf T[3232];
void main()
{
int c,d2,g,h,h2,i,j,k,n2,n3,x,y,z;
int n4,n9,n55,add1,add5,add6,add7,add9;
long ID2,d1;
int n[3][7];
int k2[4][8];
char s[15];
char s2[15],s3[15];
char a,d,f,add2,add3,add4,add8,add10;
int l[3232]={0},a3[100],a4[100],p3[100],a7[100],s22[100];
int n5[100],n6[100],t2[100],p2[100],a2[100],s33[100],t3[100];
int n7[10][10][10];
for(i=0;i=2;i++)
for(j=0;j=6;j++)
n[i][j]=100;
/************************************开头****************************************************/
loop2:
printf(“\n***************************************\n”);
printf(” 欢迎使用航空售票系统 \n”);
printf(“***************************************\n”);
printf(“\n1.订票\n2.退票\n3.查票\n4.查询\n5.退出\n”);
printf(“请输入您的选择(1-5):\n”);
do{ scanf(“%c”,a);}
while(a!=’1’a!=’2’a!=’3’a!=’4’a!=’5′);
/********************************************订票*******************************************/
if(a==’1′)
{loop1:
{
printf(“共有三个航班,请您输入您的选择(1-3):\n”);
do{scanf(“%d”,i);}
while(i3||i1);
printf(“请输入你旅行的周日代码(1-7):\n”);
do{scanf(“%ld”,j);}
while(j7||j1);
printf(“本航班当天余票为%d张!\n”,n[i-1][j-1]);
printf(“\n请输入您想订的座位号(1-100):\n”);
do{scanf(“%d”,k);}
while(k100||k1);
h=i+4*j+32*k;
while(l[h]==1)
{
do{printf(“该票已经被订,请重新输入:\n”);
scanf(“%d”,k);h=i+4*j+32*k;}
while(k100||k1);}
printf(“请输入您的姓名:\n”);
scanf(“%s”,T[h].name);
printf(“\n请输入您的身份证号码:\n”);
scanf(“%ld”,T[h].ID);
do
{
printf(“\n请输入您的目的地(1-5):\n”);
printf(“1.天堂\n2.地狱\n3.蓬莱仙岛\n4.台湾\n5.美国\n”);
scanf(“%d”,c);
}
while(c5||c1);
switch(c)
{
case 1:strcpy (s,”天堂”);break;
case 2:strcpy (s,”地狱”);break;
case 3:strcpy (s,”蓬莱仙岛”);break;
case 4:strcpy (s,”台湾”);break;
case 5:strcpy (s,”美国”);break;
}
printf(“\n您的订票信息如下:\n”);
printf(“姓名 身份证号 航班号 飞行时间 目的地\n”);
printf(“\n%s%10ld 偏见%d号 周%d%13s\n”,T[h].name,T[h].ID,i,j,s);
printf(“\n”);
printf(“\n 请再次检查您的信息。\n\n如果正确无误,请输入y.\n\n重新填写,请输入r.\n\n放弃订票,回主选单输入q。\n”);
do
{
scanf(“%c”,d);
}
while(d!=’r’d!=’q’d!=’y’);
}
if(d==’y’)
{
n[i-1][j-1]–;
l[h]=1;
printf(“\n订票成功!!\n”);
goto loop2;
}
else if(d==’r’)
goto loop1;
else goto loop2;
}
/********************************************退票*******************************************/
if(a==’2′)
{
printf(“\n请填写退票详细信息.\n”);
printf(“\n请输入航班号(1-3):\n”);
do{scanf(“%d”,x);}
while(x3||x1);
printf(“\n请输入旅行周日(1-7):\n”);
do{scanf(“%d”,y);}
while(y7||y1);
printf(“\n请输入座位号:\n”);
do{scanf(“%d”,z);}
while(z100||z1);
printf(“\n请输入您的姓名:\n”);
scanf(“%s”,s2);
printf(“\n请输入您的身份证号:\n”);
scanf(“%ld”,ID2);
h2=x+4*y+32*z;
if(T[h2].ID==0)
{
printf(“\n该票没有被定出!\n”);
goto loop2;
}
else
{
if(T[h2].ID!=ID2||strcmp(s2,T[h2].name))
{
printf(“信息出现矛盾!无法退票!\n”);goto loop2;}
else
{
printf(“\n请输入y确认退票!回主选单请输入q!\n”);
scanf(“%c”,f);
while(f!=’y’f!=’q’)
{scanf(“%c”,f);}
if(f==’y’)
{
printf(“退票成功!\n”);
l[h2]=0;
n[x-1][y-1]++;}
else goto loop2;
}
}
goto loop2;
}
/*************************************查票系统************************************************/
if(a==’3′)
{loop4:
printf(“\n请输入查询方式:\n”);
printf(“\n1.输入身份证号查询。\n2.输入座位号码查询。\n3.输入姓名查询。\n4.返回。\n”);
do
{scanf(“%d”,g);}
while(g4||g1);
/******************身份证号查询**********************/
if(g==1)
{loop6:
printf(“\n请您输入您要查询的身份证号:\n”);
do{scanf(“%ld”,d1);}
while(d1==0);
n3=0;
i=36;
while(i=3231)
{
if(T[i].ID==d1l[i]==1)
{
n3++;a3[n3]=i;
}
i++;
}
if(n3==0){printf(“\n没有找到您输入的身份证号!\n”);
goto loop4;
}
else
{
for(i=1;i=n3;i++)
{
s33[i]=a3[i]/32;
t3[i]=(a3[i]-s33[i]*32)/4;
p3[i]=a3[i]-s33[i]*32-t3[i]*4;
}
printf(“\n您所查找的的信息为:\n”);
printf(“\n姓名 身份证号 航班号 座位号 飞行日\n”);
for(i=1;i=n3;i++)
printf(“%s%10ld 偏见%d号%7d 周%d\n”,T[a3[i]].name,T[a3[i]].ID,p3[i],s33[i],t3[i]);
}
printf(“\n继续查找请输入y,返回输入q.\n”);
do{scanf(“%c”,add3);}
while(add3!=’y’add3!=’q’);
if(add3==’y’)
goto loop6;
else goto loop4;
}
/***********************名字查询***************************/
if(g==3)
{loop5:
printf(“\n请您输入您要查询的名字:\n”);
scanf(“%s”,s3);
n2=0;
i=37;
while(i=3231)
{
while(T[i].name==NULL) i++;
if(strcmp(T[i].name,s3)==0l[i]!=0)
{
a2[n2+1]=i;
n2++;
}
i++;
}
if(n2==0)
{
printf(“\n没有找到您输入的姓名!\n”);
goto loop4;
}
else
{
for(i=1;i=n2;i++)
{
s22[i]=a2[i]/32;
t2[i]=(a2[i]-s22[i]*32)/4;
p2[i]=a2[i]-s22[i]*32-t2[i]*4;
}
printf(“\n您所查找的的信息为:\n”);
printf(“姓名 身份证号 航班号 座位号 飞行日\n”);
for(i=1;i=n2;i++)
printf(“%s%10ld 偏见%d号%7d 周%d\n”,s3,T[a2[i]].ID,p2[i],s22[i],t2[i]);
}
printf(“\n继续查找请输入y,返回输入q.\n”);
do{scanf(“%c”,add2);}
while(add2!=’y’add2!=’q’);
if(add2==’y’)
goto loop5;
else
goto loop4;
}
/************************座位号码查询*****************************/
if(g==2)
{loop7:
printf(“\n请您输入您要查询的座位号:\n”);
do{ scanf(“%d”,d2);}
while(d21||d2100);
for(i=1;i=3;i++)
for(j=1;j=7;j++)
k2[i][j]=d2*32+4*j+i;
i=1;
n4=0;
while(i=3)
{
j=1;
while(j=7)
{
if(T[k2[i][j]].ID!=0l[k2[i][j]]!=0)
{
n4++;
n5[n4]=i;
n6[n4]=j;
n7[n4][n5[n4]][n6[n4]]=k2[i][j];
}
j++;
}
i++;
}
if(n4==0){printf(“\n该座位号码没有被定出!\n”);
goto loop4;
}
else
{
printf(“\n您所输入的座位号信息是:\n”);
printf(“姓名 身份证号 航班号 座位号 飞行日\n”);
for(i=1;i=n4;i++)
printf(“%s%10ld 偏见%d号%7d 周%d\n”,T[n7[i][n5[i]][n6[i]]].name,T[n7[i][n5[i]][n6[i]]].ID,n5[i],d2,n6[i]);
}
printf(“\n继续查找请输入y,返回输入q.\n”);
do{scanf(“%c”,add4);}
while(add4!=’y’add4!=’q’);
if(add4==’q’)
goto loop4;
if(add4==’y’)
goto loop7;
}
else
goto loop2;
}
/*****************************************查询系统****************************************************/
if(a==’4′)
{loop8:
printf(“\n1.查询特定航班的余票情况。\n2.查询特定航班的乘客情况。\n3.返回主选单。\n”);
printf(“\n请输入您的选择(1-3):\n”);
do
{scanf(“%d”,add1);}
while(add13||add11);
if(add1==3)goto loop2;
/*******************************查余票*****************************/
if(add1==1)
{loop9:
printf(“\n请输入您要查询的航班号(1-3):\n”);
do{scanf(“%d”,add5);}
while(add53||add51);
printf(“\n请输入您要查询的飞行期(1-7):\n”);
do{scanf(“%d”,add6);}
while(add67||add61);
i=37;
n55=0;
while(i=3231)
{
if((T[i].ID==0||l[i]==0)(i-add5-add6*4)%32==0)
{
n55++;
a4[n55]=i;
}
i++;
}
printf(“\n第%d航班飞机周%d的余票情况是:\n”,add5,add6);
i=0;
for(j=i+1;j=n55;j++)
{
{
for(i=j;i=j+9;i++)
printf(“%5d”,a4[i]/32);
}
printf(“\n”);j=i-1;
}
printf(“\n继续查找请输入y,返回输入q.\n”);
do{scanf(“%c”,add8);}
while(add8!=’y’add8!=’q’);
if(add8==’y’)
goto loop9;
else
goto loop8;
}
/*******************查询已订票信息**********************/
if(add1==2)
{loop10:
printf(“\n请输入您要查询的航班号(1-3):\n”);
do{scanf(“%d”,add7);}
while(add73||add71);
printf(“\n请输入您要查询的飞行期(1-7):\n”);
do{scanf(“%d”,add9);}
while(add97||add91);
n9=0;
i=37;
while(i=3231)
{
if(T[i].ID!=0(i-add7-add9*4)%32==0l[i]!=0)
{
n9++;
a7[n9]=i;
}
i++;
}
if(n9==0)
printf(“\n该航班满票,没有被定出!\n”);
if(n9!=0)
{
printf(“\n第%d航班飞机周%d的订票情况是:\n”,add7,add9);
printf(“\n姓名 身份证号 航班号 座位号 飞行日\n”);
for(i=1;i=n9;i++)
printf(“%S%10ld 偏见%d号%7d 周%d\n”,T[a7[i]].name,T[a7[i]].ID,add7,(a7[i]-add7-4*add9)/32,add9);
}
printf(“\n继续查找请输入y,返回输入q.\n”);
do{scanf(“%c”,add10);}
while(add10!=’y’add10!=’q’);
if(add10==’y’)
goto loop10;
else
goto loop8;
}
}
}
飞机订票系统设计 c语言
(已修改,请用最新的代码)代码说明:
1级菜单:选择购买的航班号,并显示对应座位状态。
(我只做测试,所以初始化initFlight函数中我只初始了2个航班,需要自己按照我的代码添)
(注意:实际开发软件,链表数据是从数据库中读取的,需要实时同步,如果要多次调用initFlight函数,记得自己写一个释放内存的函数,把所有链表“SINFO和FLINFO”节点都释放掉,释放函数我没写,需要你自己写!!!)
2级菜单:选择购买对应座位号,完成购买,并实时显示购买结果。
位置编号、座位最大排数、舱室类型、折扣等参数均由常量参数空值,需要修改自行改常量。
注意:舱室类型(我默认3个类型头等舱、公务舱、经济舱)对应折扣参数:tDiscount二维数组。如要如要添加新的舱室类型,必须将参数常量TYPESIZE、typeName、types、tDiscount这4个同时修改,具体看代码备注!!
座位票价=基础票价*类型折扣*时段折扣。
因为飞机不让吸烟,所以我没做吸烟区(笑),如果你需要,可以作为类型自行添加!
#includestdio.h
#includestdlib.h
#includeconio.h
#includestring.h
#includemalloc.h
#includetime.h
//———————–相关参数,想改变,在这里修改!!!!!!!—————————–
const float timeDiscount=1;//时段折扣,影响所有航班最终价格,默认1
const char cID[5]=”ABCD”;//位置编号
const int maxRow=20;//位置最大排号
//注意:如果修改类型数量,types和tDiscount必须同时修改!!!
#define TYPESIZE 3//类型数量
const char typeName[TYPESIZE][10]={“头等舱”,”公务舱”,”经济舱”};
const int types[TYPESIZE][2]={{1,2},{3,4},{5,20}};//排号对应类型。1~2排头等舱,3~4排公务舱,5~20排经济舱
const float tDiscount[TYPESIZE]={1.5,1.3,1};//类型折扣。头等舱1.5倍,公务舱1.3倍,经济舱1倍
//——————————————————————————-
typedef struct seatInfo//座位信息,一条链表对应一个航班信息,链表顺序从第一排左边第一个开始往后A1~D1,A2~D2。。。
{
char cloID;//位置编号A、B、C、D
int row;//位置排号
int type;//座位所属类型:0:头等舱、1:公务舱、2:经济舱,不同类型对应不同的类型折扣tDiscount
int sell;//出售状态,0:未出售;1:已出售
struct seatInfo *next;
}SINFO;
typedef struct flightInfo//航班信息
{
char fid[10];//航班号
time_t tfTime;//起飞时间
time_t ldTime;//降落时间
char toCity[20];//抵达城市
float tPrice;//基础票价,不同位置具有不同折扣,座位票价=基础票价*类型折扣*时段折扣
struct flightInfo *next;
struct seatInfo *sHead;//对应座位链表的头节点
}FLINFO;
void meError(void *p);
SINFO *getSINFO();//获取座位链表
//addFLINFO:添加航班信息链表的节点flinfoHead:头节点(第一次传NULL会自动生成),flinfoTail:尾节点,fNew:要添加的结构信息(成员指针无需赋值)
FLINFO *addFLINFO(FLINFO **ffHead,FLINFO *flinfoTail,FLINFO fNew);//返回尾节点
time_t getTime_tfromStr(char *sTime);//将YYYY-MM-DD hh:mm:ss格式的时间字符串转换成time_t型数值
FLINFO *initFlight();//初始化航班信息,返回航班链表头节点,如果想手动输入,请在这里添加!!!正常软件开发,这一步应该是从数据库读取!
char *getTString(struct tm *tm0);//通过tm获取时间字符串
void showSinfo(FLINFO *flinfo);//显示航班对应座位信息
void printfFlinfo(FLINFO * flinfoHead);
FLINFO *selectFlinfo(FLINFO *flinfoHead,char *fid);//选择航班号,返回节点
void showSinfo(FLINFO *flinfo);//显示航班对应座位信息
SINFO *selectSinfo(FLINFO *flinfo,char *sid);//选择座位,返回节点
int main()
{
FLINFO *flinfoHead=initFlight(),*ffSelect=NULL;
SINFO *sfSelect=NULL;
char fid[10]={0},sid[10]={10};
while(1)
{
ffSelect=NULL;
sfSelect=NULL;
memset(fid,0,10);
memset(sid,0,10);
printfFlinfo(flinfoHead);
printf(“请输入要购买的航班号:”);
scanf(“%s”,fid);
ffSelect=selectFlinfo(flinfoHead,fid);
if(!ffSelect)
{
printf(“未找到对应航班,按任意键继续—–\n”);
getch();
system(“cls”);
continue;
}
system(“cls”);
printf(“航班号:%s 座位信息如下:\n”,ffSelect-fid);
showSinfo(ffSelect);
printf(“请输入要购买的座位编号(输入0返回主菜单):”);
scanf(“%s”,sid);
if(!strcmp(sid,”0″))
{
system(“cls”);
continue;
}
else
{
sfSelect=selectSinfo(ffSelect,sid);
if(!sfSelect||sfSelect-sell)
{
printf(“未找到对应座位或该座位已出售,请重新输入!按任意键继续—–\n”);
getch();
system(“cls”);
continue;
}
printf(“购买成功!按任意键继续—–“);
sfSelect-sell=1;
getch();
system(“cls”);
}
}
return 0;
}
SINFO *selectSinfo(FLINFO *flinfo,char *sid)//选择座位,返回节点
{
SINFO *sinfoHead=flinfo-sHead;
while(sinfoHead-next)
{
if(sinfoHead-next-cloID==sid[0] sinfoHead-next-row==atoi(sid+1))
return sinfoHead-next;
sinfoHead=sinfoHead-next;
}
return NULL;
}
void showSinfo(FLINFO *flinfo)//显示航班对应座位信息
{
SINFO *sinfoHead=flinfo-sHead,*sfp=NULL;
int i,j,k,row=maxRow,clo=strlen(cID);
char typeStr[10]={0};
for(i=0;irow;i++)
{
//———读取座位所属舱室————
memset(typeStr,0,10);
for(k=0;kTYPESIZE;k++)
if(i+1=types[k][0] i+1=types[k][1])
strcpy(typeStr,typeName[k]);
//————————————–
printf(“\n”);
for(j=0;jclo;j++)
printf(“————- “);
printf(“\n”);
sfp=sinfoHead;
for(j=0;jclo;j++)
{
printf(“| %c%02d | “,sfp-next-cloID,sfp-next-row);
sfp=sfp-next;
}
printf(“\n”);
sfp=sinfoHead;
for(j=0;jclo;j++)
{
printf(“| %c | “,sfp-next-sell?2:1);
sfp=sfp-next;
}
printf(“\n”);
sfp=sinfoHead;
for(j=0;jclo;j++)
{
printf(“|%6s:%4.0f| “,typeStr,flinfo-tPrice*tDiscount[sfp-next-type]*timeDiscount);
sfp=sfp-next;
}
printf(“\n”);
sinfoHead=sfp;
}
for(j=0;iclo;j++)
printf(“——- “);
printf(“\n”);
}
FLINFO *selectFlinfo(FLINFO *flinfoHead,char *fid)//选择航班号,返回节点
{
while(flinfoHead-next)
{
if(!strcmp(flinfoHead-next-fid,fid))
return flinfoHead-next;
flinfoHead=flinfoHead-next;
}
return NULL;
}
void printfFlinfo(FLINFO * flinfoHead)
{
while(flinfoHead-next)
{
printf(“目的地:%s,航班号:%s\n—-起飞时间:%s,抵达时间:%s\n\n”,flinfoHead-next-toCity,flinfoHead-next-fid,getTString(localtime(flinfoHead-next-tfTime)),getTString(localtime(flinfoHead-next-ldTime)));
flinfoHead=flinfoHead-next;
}
}
char *getTString(struct tm *tm0)//通过tm获取时间字符串
{
char *str=(char *)malloc(sizeof(char)*20),num[5]={0};
meError(str);
memset(str,0,20);
sprintf(num,”%4d”,tm0-tm_year+1900);
strcat(str,num);
strcat(str,”-“);
memset(num,0,5);
sprintf(num,”%02d”,tm0-tm_mon);
strcat(str,num);
strcat(str,”-“);
memset(num,0,5);
sprintf(num,”%02d”,tm0-tm_mday);
strcat(str,num);
strcat(str,” “);
memset(num,0,5);
sprintf(num,”%02d”,tm0-tm_hour);
strcat(str,num);
strcat(str,”:”);
memset(num,0,5);
sprintf(num,”%02d”,tm0-tm_min);
strcat(str,num);
strcat(str,”:”);
memset(num,0,5);
sprintf(num,”%02d”,tm0-tm_sec);
strcat(str,num);
return str;
}
time_t getTime_tfromStr(char *sTime)//将YYYY-MM-DD hh:mm:ss格式的时间字符串转换成time_t型数值
{
time_t rt;
struct tm *tm1=NULL;
rt=time(NULL);
tm1=localtime(rt);
sscanf(sTime,(“%4d-%2d-%2d %2d:%2d:%2d”),tm1-tm_year,tm1-tm_mon,tm1-tm_mday,tm1-tm_hour,tm1-tm_min,tm1-tm_sec);
tm1-tm_year-=1900;
tm1-tm_mon–;
rt=mktime(tm1);
return rt;
}
FLINFO *initFlight()//初始化航班信息,返回航班链表头节点,如果想手动输入,请在这里添加!!!正常软件开发,这一步应该是从数据库读取!
{
FLINFO *ffHead=NULL,*flinfoTail=NULL,fNew;
//——–添加一个航班信息—-需要增加按照我下面调用方式写——————————–
strcpy(fNew.fid,”CI502″);
fNew.tfTime=getTime_tfromStr(“2019-02-20 03:30:30”);
fNew.ldTime=getTime_tfromStr(“2019-02-20 05:20:30”);
strcpy(fNew.toCity,”台北”);
fNew.tPrice=1000;
fNew.next=NULL;
flinfoTail=addFLINFO(ffHead,flinfoTail,fNew);
//——————————————————————————————–
strcpy(fNew.fid,”9C8921″);
fNew.tfTime=getTime_tfromStr(“2019-02-20 14:30:30”);
fNew.ldTime=getTime_tfromStr(“2019-02-20 16:40:30”);
strcpy(fNew.toCity,”香港”);
fNew.tPrice=500;
fNew.next=NULL;
flinfoTail=addFLINFO(ffHead,flinfoTail,fNew);
return ffHead;
}
FLINFO *addFLINFO(FLINFO **ffHead,FLINFO *flinfoTail,FLINFO fNew)//返回尾节点
//添加航班信息链表的节点flinfoHead:头节点(第一次传NULL会自动生成),flinfoTail:尾节点,fNew:要添加的结构信息(成员指针无需赋值)
{
FLINFO *flinfoHead=*ffHead;
if(flinfoHead==NULL)
{
*ffHead=(FLINFO *)malloc(sizeof(FLINFO));
flinfoHead=*ffHead;
meError(flinfoHead);
flinfoHead-next=NULL;
}
FLINFO *flinfoNew=(FLINFO *)malloc(sizeof(FLINFO));
meError(flinfoNew);
flinfoNew-next=NULL;
flinfoNew-fid[0]=0;
strcpy(flinfoNew-fid,fNew.fid);
flinfoNew-ldTime=fNew.ldTime;
flinfoNew-tfTime=fNew.tfTime;
flinfoNew-toCity[0]=0;
strcpy(flinfoNew-toCity,fNew.toCity);
flinfoNew-tPrice=fNew.tPrice;
flinfoNew-sHead=getSINFO();
if(flinfoHead-next==NULL)
flinfoHead-next=flinfoNew;
else
flinfoTail-next=flinfoNew;
flinfoTail=flinfoNew;
return flinfoTail;
}
SINFO *getSINFO()//获取座位链表
{
int maxClo=strlen(cID),cnt=maxClo*maxRow,clo=0,row=1,i;
SINFO *sinfoHead=(SINFO *)malloc(sizeof(SINFO)),*sinfoTail=NULL;
meError(sinfoHead);
sinfoHead-next=NULL;
SINFO *sinfoNew=NULL;
while(cnt–)//按顺序生成对应数量的座位链表
{
if(clo==maxClo)
clo=0,row++;
if(row==maxRow+1)
row=1;
sinfoNew=(SINFO *)malloc(sizeof(SINFO));
meError(sinfoNew);
sinfoNew-cloID=cID[clo];
sinfoNew-row=row;
for(i=0;iTYPESIZE;i++)
if(row=types[i][0] row=types[i][1])
{
sinfoNew-type=i;
break;
}
sinfoNew-sell=0;
sinfoNew-next=NULL;
if(sinfoHead-next==NULL)
sinfoHead-next=sinfoNew;
else
sinfoTail-next=sinfoNew;
sinfoTail=sinfoNew;
clo++;
}
return sinfoHead;
}
void meError(void *p)//内存申请失败
{
if(p==NULL)
{
printf(“\n异常:内存申请失败!回车结束程序!\n”);
while(getch()!=’\r’);
exit(0);
}
}
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:\n1:according to the number of
train;\n2: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)==0r-data.bookNum200)
{
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语言写火车订票系统
#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:\n1:according to the number of train;\n2: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;ti;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)==0r-data.bookNum200)
{
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语言,电影院售票管理系统的设计与实现的代码
#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;
}
用C语言编写一个车票管理系统
1、首先打开CodeBlocks,新建一个空白文件。先定义头文件和主函数。
2、定义所需要的变量,因为有除法,肯定会有小数出现,所以将变量定义为浮点型。
3、定义输入函数,将刚才的x和y定义为计算的变量,将c定义为选择计算方式的变量。scanf(“%f%c%f”,x,c,y)。
4、添加switch函数,将c作为选择变量。
5、然后在主函数中输入一个输出函数来输出计算式及结果。
6、这时进行运行如图,计算正常。
关于c语言订票系统代码和c语言编写火车订票系统的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。