数据结构课设订票系统源代码.docx
- 文档编号:7917738
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:22
- 大小:20.34KB
数据结构课设订票系统源代码.docx
《数据结构课设订票系统源代码.docx》由会员分享,可在线阅读,更多相关《数据结构课设订票系统源代码.docx(22页珍藏版)》请在冰豆网上搜索。
数据结构课设订票系统源代码
#include
#include
#include
#include
#definemaxrailway100
#definemaxorder1000
typedefstructTime
{
intmonth;//月
intday;//日
inthour;//小时
intminute;//分钟
}Time,*Ptime;
typedefstructRailway
{
charNum[15];//列车号
charcorp[15];//铁路公司名称
charrail[15];//列车车型
charfrom[15];//始发站点
charto[15];//终点站
Ptimetakeoff;//发车时间
Ptimearrive;//到站时间
intprice;//票价
floatdiscount;//折扣,小于100大于0的浮点数
intvaculmn;//乘客容量
intrest;//剩余座位数
structRailway*next;
}Railway,*Pst_Rail;
typedefstructOrder
{
charNum[15];//列车号
charcusname[20];//乘客姓名
charIDcardnum[20];//乘客身份证号
intticketnum;//订票总数
intnum;//订单编号
structOrder*next;
}Order,*Pst_Order;
FILE*data,*order;//分别保存列车线路记录和订单记录
Pst_Railhead_rail;//列车链表表头
Pst_Orderhead_order;//订单链表表头
intflag;//退出操作的标记
intnumofrail;//记录列车线路数目
intnumoforder;//记录订单数目
intlastorder;//记录最后一个订单的序号
voidpause()
{
intt,now_time;
now_time=clock();//取出当前时间
for(;(t=(clock()-now_time))<2*(CLOCKS_PER_SEC););
system("cls");//在pause()函数中放一个清屏函数
}
//时钟程序,用来控制用户界面的输出,每两个界面中间暂停2秒钟
voidInuput()
{
inti;
Pst_Railp,q;
p=head_rail;
for(i=0;i
q=(Pst_Rail)malloc(sizeof(Railway));
q->takeoff=(Ptime)malloc(sizeof(Time));
q->arrive=(Ptime)malloc(sizeof(Time));
p->next=q;
//为记录开辟空间
printf("PleaseinputRailwayinformation:
\n");
printf("Number:
\tCorparation:
\tTypeofrailway:
\n");
scanf("%s%s%s",q->Num,q->corp,q->rail);
//输入列车线路的车号、铁路公司名称、列车车型
printf("\nPassengervaculmn:
\tTakeoffposition:
\tArriveposition:
\n");
scanf("%d%s%s",&q->vaculmn,q->from,q->to);
//输入列车的乘客容量、始发、终点
q->rest=q->vaculmn;
//剩余的座位初始时为乘客容量
printf("\nTakeofftime:
\tArrivetime:
\tPrice:
\tDiscount:
\nTimee.g.:
6/2512:
30\n");
scanf("%d/%d%d:
%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->takeoff->minute);
scanf("%d/%d%d:
%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive->minute);
//输入列车发车的时间和到站时间
scanf("%d%f",&q->price,&q->discount);
//输入车票价格和折扣
numofrail+=1;
}
voidFile_Scanf_Data()
{
Pst_Railp,q;
p=head_rail;
while(!
feof(data))
{
q=(Pst_Rail)malloc(sizeof(Railway));
q->takeoff=(Ptime)malloc(sizeof(Time));
q->arrive=(Ptime)malloc(sizeof(Time));//为记录开辟空间
fscanf(data,"%s%s%s",q->Num,q->corp,q->rail);
fscanf(data,"%d%s%s",&q->vaculmn,q->from,q->to);
fscanf(data,"%d/%d%d:
%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->takeoff->minute);
fscanf(data,"%d/%d%d:
%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive->minute);
fscanf(data,"%d%f%\n",&q->price,&q->discount);
q->next=NULL;
numofrail+=1;
p->next=q;
p=p->next;
}//从文件中读取列车线路记录
}
voidFile_Scanf_Order()
{
Pst_Orderp,q;
p=head_order;
while(!
feof(order))
{
q=(Pst_Order)malloc(sizeof(Order));//为记录开辟空间
fscanf(order,"NO.%d:
%s\t%s\t%dticketsforrailway:
%s\n",&q->num,q->cusname,q->IDcardnum,&q->ticketnum,q->Num);
q->next=NULL;
numofrail+=1;
p->next=q;
p=p->next;
}//从文件中读取订单记录
}
voidFile_write()
{
Pst_Railp;
Pst_Orderq;
p=head_rail;
q=head_order;
while(p->next!
=NULL)
{
p=p->next;
fprintf(data,"%s%s%s\n",p->Num,p->corp,p->rail);
fprintf(data,"%d%s%s\n",p->vaculmn,p->from,p->to);
fprintf(data,"%d/%d%d:
%d-",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);
fprintf(data,"%d/%d%d:
%d",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute);
fprintf(data,"%d%.2f%%\n",p->price,p->discount);
}
while(q->next!
=NULL)
{
q=q->next;
fprintf(order,"NO.%d:
%s\t%s\t%dticketsforrailway:
%s\n",q->num,q->cusname,q->IDcardnum,q->ticketnum,q->Num);
}
}//向文件中写入数据
voidChange_item(intn)
{
inti,choose;
Pst_Railp;
p=head_rail;
for(i=0;i
printf("Whichitemdoyouwanttochange?
\n");
printf("0:
Number\n1:
Corparation\n2:
Typeofrailway\n3:
Passengervaculmn\n\
4:
Takeoffposition\n5:
Arriveposition\n6:
Takeofftime\n7:
Arrivetime\n\
8:
Price\n9:
Discount\n\n");
scanf("%d",&choose);
system("cls");
switch(choose)
{
case0:
{
printf("TheoldNumberis%s\nPleaseinputthenewone:
\n",p->Num);
scanf("%s",p->Num);
break;
}//显示列车号并输入新的列车号
case1:
{
printf("TheoldCorparationis%s\nPleaseinputthenewone:
\n",p->corp);
scanf("%s",p->corp);
break;
}//显示原铁路公司并输入新的公司名称
case2:
{
printf("TheoldTypeofrailwayis%s\nPleaseinputthenewone:
\n",p->rail);
scanf("%s",p->rail);
break;
}//显示原列车车型并输入新的车型
case3:
{
printf("TheoldPassengervaculmnis%d\nPleaseinputthenewone:
\n",p->vaculmn);
scanf("%d",&p->vaculmn);
break;
}//显示原乘客容量并输入新的容量
case4:
{
printf("TheoldTakeoffpositionis%s\nPleaseinputthenewone:
\n",p->from);
scanf("%s",p->from);
break;
}//显示原列车始发站并输入新的站名
case5:
{
printf("TheoldArrivepositionis%s\nPleaseinputthenewone:
\n",p->to);
scanf("%s",p->to);
break;
}//显示原列车终点站并输入新的终点站
case6:
{
printf("TheoldTakeofftimeis%d/%d%d:
%d\nPleaseinputthenewone:
\n",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);
scanf("%d/%d%d:
%d",&p->takeoff->month,&p->takeoff->day,&p->takeoff->hour,&p->takeoff->minute);
break;
}//显示原列车发车时间并输入新的时间
case7:
{
printf("TheoldArrivetimeis%d/%d%d:
%d\nPleaseinputthenewone:
\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute);
scanf("%d/%d%d:
%d",&p->arrive->month,&p->arrive->day,&p->arrive->hour,&p->arrive->minute);
break;
}//显示原列车到站时间并输入新的时间
case8:
{
printf("TheoldPriceis%d\nPleaseinputthenewone:
\n",p->price);
scanf("%d",&p->price);
break;
}//显示原列车价格并输入新的价格
case9:
{
printf("TheoldDiscountis%.2f%%\nPleaseinputthenewone:
\n",p->discount);
scanf("%f",&p->discount);
break;
}//显示原车票折扣并输入新的折扣
}
}//由Change_main()函数调用,用来选择性地改变记录中的某一项
voidChange_main()
{
charchange[15],e;
Pst_Railp,q;
p=head_rail;
q=head_rail;
inti,flag_find;
do
{
for(i=0;i { p=p->next; if(p! =NULL) break; } if(i==numofrail) { printf("Thereisnorailwayinformation! \n"); break; }//如果pa[]数组所有元素都为空指针则退出do...while()循环,并显示没有列车信息 flag_find=0; printf("Pleseinputthenumberoftherailwayyouwanttochange: \n"); scanf("%s",change); for(i=0;i { q=q->next; if(strcmp(change,q->Num)==0) { flag_find=1; break; } }//逐一匹配输入与数组指针指向的结构体的Num项,若相等则标记找到 if(flag_find==0) { printf("Nosuchrailwayexist! \n"); printf("Doyouwanttotryagain? (Y/N)\n"); do { scanf("%c",&e); }while(e=='\n'); if(e=='N')flag_find=1; } system("cls"); }while(flag_find==0); do { system("cls"); Change_item(i);//修改飞机线记录中的一项 printf("Doyouwanttocontinue? (Y/N)\n"); do { scanf("%c",&e); }while(e=='\n');//排除%c输入时,回车号的干扰 }while(e=='Y'); }//用来查找需要修改的记录,并调用Change_item()函数 voidQuiry_number() { charquiry[15],e; Pst_Railp; p=head_rail; inti,flag_quiry_number; do { system("cls"); printf("Pleaseinputthenumberoftherailway: \n"); flag_quiry_number=0; scanf("\n%s",quiry);//输入需要查询的列车号 for(i=0;i { p=p->next; if(strcmp(quiry,p->Num)==0) { system("cls"); printf("Number: %s\t",p->Num); printf("From: %s\tTo: %s\n",p->from,p->to); printf("Time: %d/%d%d: %d-",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute); printf("%d/%d%d: %d\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute); printf("Price: %d\tDiscount: %.2f\t",p->price,p->discount); if(p->rest! =0)printf("Thereare%dseatsavaliable! \n",p->rest); elseprintf("NOseatavaliable! \n"); flag_quiry_number=1; break; }//匹配输入与记录的列车号,若相同则输出列车始发站、时间以及票价、折扣和是否满座的信息 } if(! flag_quiry_number) { printf("Thereisnosuchrailwayexist! \n"); printf("Doyouwanttotryagain? (Y/N)\n"); do { scanf("%c",&e); }while(e=='\n'); if(e=='N')flag_quiry_number=1; } }while(! flag_quiry_number); system("pause"); }//按照列车号查询 voidQuiry_position() { charquiry[2][15]; Pst_Railp; p=head_rail; inti,j,flag_quiry_position; do { printf("Pleaseinputthetakeoffandarrivepositionoftheairline: \n"); flag_quiry_position=0; scanf("%s%s",quiry[0],quiry[1]);//输入需要查询的始发、终点站名 for(i=0;i { p=p->next; if((strcmp(quiry[0],p->from)==0)&&(strcmp(quiry[1],p->to)==0)) { pause(); printf("Number: %s\t",p->Num); printf("From: %s\tTo: %s\n",p->from,p->to); printf("Time: %d/%d%d: %d-",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute); printf("%d/%d%d: %d\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute); printf("Price: %d\tDiscount: %.2f\n",p->price,p->discount); flag_quiry_position=1; break; }//匹配输入与记录的地点,若相同则输出始发、终点站、时间以及票价、折扣和是否满座的信息 } if(! flag_quiry_position)printf("\nThereisnosuchairlineexist! Pleaseinputagain! \n"); }while(! flag_quiry_position); pause(); }//按照始发、终点站地点查询 voidQuiry_main() { charchoose;//选择按照列车号还是始发、终点站查询 printf("Pleasechoosethetypeofquiry: \n1: Number\t2: Takeoffandarriveposition\n"); do { do { scanf("%c",&choose); }while(choose=='\n');//排除回车的干扰 system("cls"); if(choose=='1') { Quiry_number();//选择1则调用Quiry_number()函数 break; } elseif(choose=='2') { Quiry_position();//选择2则调用Quiry_position()函数 break; } elseprintf("Wronginputnumber! Pleaseinputagain! \n"); }while (1); }//用来选择查询的方式,并调用Quiry_number();或Quiry_position(); voidOrder_mai
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 订票 系统 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)