C语言编程火车订票系统源代码Word格式.docx
《C语言编程火车订票系统源代码Word格式.docx》由会员分享,可在线阅读,更多相关《C语言编程火车订票系统源代码Word格式.docx(16页珍藏版)》请在冰豆网上搜索。
![C语言编程火车订票系统源代码Word格式.docx](https://file1.bdocx.com/fileroot1/2022-10/28/4af4ba0f-add5-45c1-8916-099674d0d770/4af4ba0f-add5-45c1-8916-099674d0d7701.gif)
/*票数*/
};
/*订票人的信息*/
structman
charnum[10];
/*ID*/
charname[10];
/*姓名*/
/*需求的票数*/
/*定义火车信息链表的结点结构*/
typedefstructnode
structtraindata;
structnode*next;
}Node,*Link;
/*定义订票人链表的结点结构*/
typedefstructpeople
structmandata;
structpeople*next;
}bookMan,*bookManLink;
/*初始界面*/
voidprintInterface()
puts("
********************************************************"
);
*Welcometousethesystemofbookingtickets*"
*Youcanchoosetheoperation:
*"
*1:
Insertatraininformation*"
*2:
Inquireatraininformation*"
*3:
Bookatrainticket*"
*4:
Updatethetraininformation*"
*5:
Advicetoyouaboutthetrain*"
*6:
saveinformationtofile*"
*7:
quitthesystem*"
}
/*添加一个火车信息*/
voidInsertTraininfo(Linklinkhead)
structnode*p,*r,*s;
r=linkhead;
s=linkhead->
next;
while(r->
next!
=NULL)
r=r->
while
(1)
{
printf("
pleaseinputthenumberofthetrain(0-return)"
scanf("
%s"
num);
if(strcmp(num,"
0"
)==0)
break;
/*判断是否已经存在*/
while(s)
if(strcmp(s->
data.num,num)==0)
thetrain'
%s'
hasbeenborn!
\n"
return;
}
s=s->
p=(structnode*)malloc(sizeof(structnode));
strcpy(p->
data.num,num);
Inputthecitywherethetrainwillreach:
"
p->
data.city);
Inputthetimewhichthetraintakeoff:
data.takeoffTime);
Inputthetimewhichthetrainreceive:
&
p->
data.receiveTime);
Inputthepriceofticket:
%d"
data.price);
Inputthenumberofbookedtickets:
data.bookNum);
next=NULL;
r->
next=p;
r=p;
shoudsave=1;
/*打印火车票信息*/
voidprintTrainInfo(structnode*p)
\nThefollowingistherecordyouwant:
>
numberoftrain:
%s\n"
data.num);
citythetrainwillreach:
thetimethetraintakeoff:
%s\nthetimethetrainreach:
data.takeoffTime,p->
thepriceoftheticket:
%d\n"
thenumberofbookedtickets:
structnode*Locate1(Linkl,charfindmess[],charnumorcity[])
Node*r;
if(strcmp(numorcity,"
num"
r=l->
while(r)
if(strcmp(r->
data.num,findmess)==0)
returnr;
elseif(strcmp(numorcity,"
city"
data.city,findmess)==0)
return0;
/*查询火车信息*/
voidQueryTrain(Linkl)
Node*p;
intsel;
charstr1[5],str2[10];
if(!
l->
next)
Thereisnotanyrecord!
Choosetheway:
\n>
1:
accordingtothenumberoftrain;
2:
accordingtothecity:
sel);
if(sel==1)
Inputthethenumberoftrain:
str1);
p=Locate1(l,str1,"
if(p)
printTrainInfo(p);
else
mark1=1;
\nthefilecan'
tbefound!
elseif(sel==2)
Inputthecity:
str2);
p=Locate1(l,str2,"
/*订票子模块*/
voidBookTicket(Linkl,bookManLinkk)
Node*r[10],*p;
charch,dem;
bookMan*v,*h;
inti=0,t=0;
charstr[10],str1[10],str2[10];
v=k;
while(v->
v=v->
Inputthecityyouwanttogo:
"
str);
p=l->
while(p!
if(strcmp(p->
data.city,str)==0)
r[i]=p;
i++;
p=p->
\n\nthenumberofrecordhave%d\n"
i);
for(t=0;
t<
i;
t++)
printTrainInfo(r[t]);
if(i==0)
\n\t\t\tSorry!
Can'
tfindthetrainforyou!
\ndoyouwanttobookit?
<
1/0>
ch);
if(ch==1)
h=(bookMan*)malloc(sizeof(bookMan));
Inputyourname:
str1);
strcpy(h->
data.name,str1);
Inputyourid:
str2);
data.num,str2);
InputyourbookNum:
dem);
h->
data.bookNum=dem;
v->
next=h;
v=h;
\nLucky!
youhavebookedaticket!
getch();
shoudsave=1;
bookMan*Locate2(bookManLinkk,charfindmess[])
bookMan*r;
r=k->
mark=1;
/*修改火车信息*/
voidUpdateInfo(Linkl)