C语言编程火车订票系统源代码之欧阳数创编Word格式文档下载.docx
- 文档编号:16894128
- 上传时间:2022-11-26
- 格式:DOCX
- 页数:16
- 大小:17.39KB
C语言编程火车订票系统源代码之欧阳数创编Word格式文档下载.docx
《C语言编程火车订票系统源代码之欧阳数创编Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C语言编程火车订票系统源代码之欧阳数创编Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。
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)
Node*p;
charfindmess[20],ch;
\nthereisn'
trecordforyoutomodify!
QueryTrain(l);
if(mark1==0)
\nDoyouwanttomodifyit?
getchar();
%c"
if(ch=='
y'
\nInputthenumberofthetrain:
findmess);
p=Locate1(l,findmess,"
Inputnewnumberoftrain:
Inputnewcitythetrainwillreach:
Inputnewtimethetraintakeoff"
Inputnewtimethetrainreach:
Inputnewpriceoftheticket:
:
Inputnewnumberofpeoplewhohavebookedticket:
\nmodifyingrecordissucessful!
\t\t\tcan'
tfindtherecord!
mark1=0;
/*系统给用户的提示信息*/
voidAdvicedTrains(Linkl)
charstr[10];
intmar=0;
Iuputthecityyouwanttogo:
str);
data.city,str)==0&
&
data.bookNum<
200)
mar=1;
\nyoucanselectthefollowingtrain!
\n\npleaseselectthefourthoperationtobooktheticket!
printTrainInfo(r);
if(mar==0)
\n\t\t\tyoucan'
tbookanyticketnow!
/*保存火车信息*/
voidSaveTrainInfo(Linkl)
FILE*fp;
intcount=0,flag=1;
fp=fopen("
c:
\\train.txt"
"
wb"
if(fp==NULL)
thefilecan'
tbeopened!
while(p)
if(fwrite(p,sizeof(Node),1,fp)==1)
count++;
flag=0;
if(flag)
thenumberoftherecordwhichhavebeensavedis%d\n"
count);
shoudsave=0;
fclose(fp);
/*保存订票人的信息*/
voidSaveBookmanInfo(bookManLinkk)
bookMan*p;
\\man.txt"
p=k->
if(fwrite(p,sizeof(bookMan),1,fp)==1)
intmain()
FILE*fp1,*fp2;
Node*p,*r;
charch1,ch2;
Linkl;
bookManLinkk;
bookMan*t,*h;
l=(Node*)malloc(sizeof(Node));
r=l;
k=(bookMan*)malloc(sizeof(bookMan));
k->
h=k;
fp1=fopen("
ab+"
if((fp1==NULL))
can'
topenthefile!
while(!
feof(fp1))
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp1)==1)
count1++;
fclose(fp1);
fp2=fopen("
if((fp2==NULL))
feof(fp2))
t=(bookMan*)malloc(sizeof(bookMan));
if(fread(t,sizeof(bookMan),1,fp2)==1)
t->
next=t;
h=t;
count2++;
fclose(fp2);
system("
cls"
printInterface();
pleasechoosetheoperation:
if(sel==8)
if(shoudsave==1)
\nthefilehavebeenchanged!
doyouwanttosaveit(y/n)?
ch1);
if(ch1=='
||ch1=='
Y'
)
SaveBookmanInfo(k);
SaveTrainInfo(l);
\nThankyou!
!
Youarewelcometoo\n"
switch(sel)
case1:
InsertTraininfo(l);
case2:
case3:
BookTicket(l,k);
case4:
UpdateInfo(l);
case5:
AdvicedTrains(l);
case6:
case7:
return0;
\npleasepressanykeytocontinue......."
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 编程 火车 订票 系统 源代码 欧阳 创编
![提示](https://static.bdocx.com/images/bang_tan.gif)