c语言火车票管理系统基本代码
- 格式:docx
- 大小:22.10 KB
- 文档页数:12
#include <iostream>#include <cstring>#include <fstream>using namespace std;struct hangban{string banhao;string mudi;string xtime;string riqi;int yupiao;};struct chengke{string xingming;string mima;string card;int zuowei;};struct piao{hangban elem[1000];chengke data[1000];int length;};void makenull(piao &l){l.length=0;}void dingpiao(piao &l,chengke q,hangban p) //订票函数{ifstream input;input.open("信息.txt");hangban *p1;chengke *q1;p1=&(l.elem[l.length]);p1->banhao=p.banhao;string hbming;string jutishijian;string dimu;while(!input.eof()){input>>hbming>>jutishijian>>dimu;if (hbming==p1->banhao){p1->xtime=jutishijian;p1->mudi=dimu;break;}}input.close();p1->riqi=p.riqi;q1=&(l.data[l.length]);q1->xingming=q.xingming;q1->mima=q.mima;q1->card=q.card;int m=l.length-1;for (m; m>-1; m--){if (l.elem[m].banhao==p1->banhao&&l.elem[m].riqi==p1->riqi){q1->zuowei=l.data[m].zuowei+1;p1->yupiao=l.elem[m].yupiao-1;break;}}if (m==-1){q1->zuowei=1;p1->yupiao=499;}l.length++;}int chaxun(piao &l,string mname,string mingma)//乘客查询{int m=1;chengke *p;p=l.data;while(m<=l.length&& p[m-1].xingming!=mname)m++;if ( p[m-1].mima==mingma)return m;else return 0;}void shuchu(piao &l,int am)//输出指定的线性表元素{cout<<"姓名"<<l.data[am-1].xingming<<endl;cout<<"身份证号"<<l.data[am-1].card<<endl;cout<<"航班号"<<l.elem[am-1].banhao<<endl;cout<<"飞行日期"<<l.elem[am-1].riqi<<endl;cout<<"具体时间"<<l.elem[am-1].xtime<<endl;cout<<"目的地"<<l.elem[am-1].mudi<<endl;cout<<"座位号"<<l.data[am-1].zuowei<<endl;cout<<endl;}int chaxun1(piao &l,string af,string sa)//航班查询{int m=l.length;hangban *p;p=l.elem;for (m;m>0;m--){if (p[m-1].banhao==af&&p[m-1].riqi==sa){return m;}}return 0;}int hangxin(piao &l,int am)//显示航班信息{cout<<"航班号"<<l.elem[am-1].banhao<<endl;cout<<"飞行日期"<<l.elem[am-1].riqi<<endl;cout<<"具体时间"<<l.elem[am-1].xtime<<endl;cout<<"目的地"<<l.elem[am-1].mudi<<endl;cout<<"余票额"<<l.elem[am-1].yupiao<<endl; }int xiangmu()//主项目函数{cout<<" 功能表"<<endl;cout<<"1、输出航班信息"<<endl;cout<<"2、查询航班信息"<<endl;cout<<"3、预订机票"<<endl;cout<<"4、退票"<<endl;cout<<"5、退出"<<endl;cout<<"输入选择项";int a;for(;;){cin>>a;if(a<6){cout<<endl;return a;}}}void deldian(piao &l,int a)//退票{string str1,str2;str1=l.elem[a].banhao;str2=l.elem[a].riqi;for (int i=a;i<l.length-1;i++){l.elem[i].banhao=l.elem[i+1].banhao;l.elem[i].mudi=l.elem[i+1].mudi;l.elem[i].xtime=l.elem[i+1].xtime;l.elem[i].riqi=l.elem[i+1].riqi;l.elem[i].yupiao=l.elem[i+1].yupiao;}for (int i=a;i<l.length;i++){l.data[i].xingming=l.data[i+1].xingming;l.data[i].mima=l.data[i+1].mima;l.data[i].card=l.data[i+1].card;l.data[i].zuowei=l.data[i+1].zuowei;}l.length--;for (int m=l.length-1;m>-1;m--){if (l.elem[m].banhao==str1&&l.elem[m].riqi==str2){l.elem[m].yupiao++;break;}}}int main(){piao lil;makenull(lil);ifstream input;for(;;){switch(xiangmu()){case 1:{string a1;string a2;string a3;input.open("信息.txt");while (!input.eof()){input>>a1>>a2>>a3;cout<<a1<<" "<<a2<<" "<<a3<<endl;}input.close();break;}case 2:{int ab;cout<<"1.按航班查询 2.按乘客查询请选择";cin>>ab;if (ab==2){string ming,mma;cout<<"输入姓名";cin>>ming;cout<<"请输入密码";cin>>mma;int len;cout<<endl;len=chaxun(lil,ming,mma);if (len!=0)shuchu(lil,len);elsecout<<"无法查询"<<endl;}else if(ab==1){string str1,str2;cout<<"输入航班信息";cin>>str1;cout<<"输入航班日期";cin>>str2;int m=chaxun1(lil,str1,str2);if (m!=0){hangxin(lil,m);}else{input.open("信息.txt");string x1,x2,x3;while (!input.eof()){input>>x1>>x2>>x3;if(x1==str1)break;}input.close();cout<<"航班号"<<str1<<endl;cout<<"飞行日期"<<str2<<endl;cout<<"具体时间"<<x2<<endl;cout<<"目的地"<<x3<<endl;cout<<"余票额500"<<endl;}}break;}case 4:{cout<<"输入姓名";string nameming;cin>>nameming;cout<<"输入密码";string yanzheng;cin>>yanzheng;int hao;hao=chaxun(lil,nameming,yanzheng);if (hao==0)cout<<"无法退票"<<endl;else{hao--;deldian(lil,hao);cout<<"退票成功"<<endl;}break;}case 3:{ chengke q;hangban p;cout<<"输入姓名";cin>> q.xingming;cout<<"输入身份证号";cin>>q.card;cout<<"请设置密码";cin>>q.mima;cout<<"输入预订的航班号";cin>>p.banhao;cout<<"输入预订的日期";cin>>p.riqi;dingpiao(lil,q,p);break;}case 5:return 0;}}return 0;}。
include<stdio.h>//预处理函数include<stdlib.h>//标准库函数include<string.h>//字符串函数include<conio.h>//通过键盘来控制程序调试int o=0;typedef struct zuowei{int a;//车座int b;//车厢}seat;typedef struct Tmess{//定义一个结构体存储火车订票的信息char tnum8;//火车车次char time18;//发车时间char station18;//出发站char station28;//终点站char tujingstation8;//途经站char time28;//到站时间char money5;//票价}tmess;typedef struct in{//定义一个结构体存储火车座位信息tmess data;//调用火车的信息int reseat;//剩余票seat seatnum;struct in next;//定义next指针}in;typedef struct pmess{//定义一个结构体存储乘客信息char name10;//姓名char tel15;//电话char id20;//身份证char booknum3;//订票数目char checi8;//车次}pmess;typedef struct people{//乘客信息pmess m;//调用pmess结构体struct people next;//定义next指针}people;struct dingdan{int danhao;char tnum8;//火车车次char time18;//发车时间char station18;//出发站char station28;//终点站char tujingstation8;//途经站char time28;//到站时间char money5;char name10;//姓名char tel15;//电话char id20;//身份证char booknum3;//订票数目char seat10;char seatnum10;}dingdan100;void end;void admin;void bookin h;people k;void cancel;void chaxuntrainin h;in fangshiin h;char findmess;char numorcity; void print;void passenger;void putoutticketin p;void putticketin h;void widows;int main{forint i=0;i<100;i++{dingdani.danhao=i+1000;}in h;p;people k;v;int wp;h=inmalloc sizeof in;h->next=NULL;k=peoplemalloc sizeof people;k->next=NULL;p=h;v=k;while1{system"cls";widows;scanf"%d";℘fflushstdin;system"cls";switch wp{case 1:putticketh;break;case 2:chaxuntrainp;break;case 3:bookp;v;break;case 4:print;break;case 5:cancel;break;default:break;}printf"\n请按任何键结束\n";getch;}return 0;}void end{//结束页面函数puts"";printf" 谢谢使用\n";}void widows{//初始页面函数;printf"\n";printf" \n";printf" \n";printf" \n";printf" \n";printf" \n";printf" \n";printf" \n";printf" \n";printf" \n";printf"\n";printf" ☆1;输入车次信息\n";printf" ☆2;查询车次\n";printf" ☆3;订票\n";printf" ☆4;订单查询\n";printf" ☆5;退票 \n";printf" ☆6;退出系统 \n";printf" \n";printf"\n";printf" 请输入选择:";}void putticketin h{//输入车次信息in p;l;s;//定义了三个指针变量char num8;//定义了数组p=h;//p指向尾节点l=h->next;//l指针遍历火车信息while p->next{p=p->next;}while1{printf"请输入要添加的火车车次按0退出\n";scanf"%s";#fflushstdin;if strcmpnum;"0"==0break;while l{if strcmpl->data.tnum;num==0{//比较的输入车次与之前存在车次printf"该车次已经存在\n";return ;}l=l->next;//l++}s=in malloc sizeof in;strcpys->data.tnum;num;//复制函数;加入新的车次printf"请输入出发时间:\n";scanf"%s";&s->data.time1;fflushstdin;printf"请输入出发城市:\n";scanf"%s";&s->data.station1;fflushstdin;printf"请输入到达时间:\n";scanf"%s";&s->data.time2;fflushstdin;printf"请输入到达城市:\n";scanf"%s";&s->data.station2;fflushstdin;printf"请输入途径大站:\n";scanf"%s";&s->data.tujingstation;fflushstdin;printf"请输入票价:\n";scanf"%s";&s->data.money;fflushstdin;s->seatnum.a=1;s->seatnum.b=1;s->reseat=-1;s->next=NULL;p->next=s;p=s;}}void putoutticketin p{//打印火车信息printf"\n下面是火车信息\n";printf"车次:%s\n";p->data.tnum;printf"出发时间:%s\n";p->data.time1;printf"始发站:%s\n";p->data.station1;printf"到达时间:%s\n";p->data.time2;printf"终点站:%s\n";p->data.station2;printf"途经站:%s\n";p->data.tujingstation;printf"票价:%s\n";p->data.money;printf"剩余票数:%d";1000-p->reseat;}in fangshiin h;char findmess;char numorcity{//查询方式in p;if strcmpnumorcity;"num"==0{//按车次查询p=h->next;while p{if strcmpp->data.tnum;findmess==0{//查到与车次信息相符的return p;//返回所查到的信息}p=p->next;}}if strcmpnumorcity ;"city"==0{//按城市查询p=h->next;while p{if strcmpp->data.station2;findmess==0{//查到与城市信息相符的return p;//返回所查到的信息}p=p->next;}}return 0;}void chaxuntrainin h{//信息查询in p;char str110;int sel;if h->next==NULL{printf"没有任何火车信息\n";return ;}printf"\n请选择查询方式\n1.车次查询 2.城市查询\n";scanf"%d";&sel;fflushstdin;if sel==1{printf"请输入车次\n";scanf"%s";str1;fflushstdin;p=fangshih;str1;"num";if p{putoutticketp;}else {printf"\n没有找到\n";}}else if sel==2{printf"请输入到达城市\n";scanf"%s";str1;fflushstdin;p=fangshih;str1;"city";if p{putoutticketp;}else {printf"\n没有找到\n";}}}void bookin h;people k{//订票输入乘客信息;订票数in p;l;//定义两个in结构体下的指针变量people v;s;//定义两个people结构体下的指针变量int i=0;t=0;wp;i2=1;char str110;str210;//定义两个数组分别用来存储到达城市和车次信息l=h;v=k;extern int o;while v->nextv=v->next;//v指针遍历火车信息printf"请输入想要达到的城市\n";scanf"%s";&str1;fflushstdin;p=fangshil;str1;"city";//按城市搜索的查询方式printf"请输入想要的车次\n";scanf"%s";&str2;fflushstdin;p=fangshil;str2;"num";//按车次搜索的查询方式if p{printf"\n没有找到到达该城市的车次\n";return ;}else {putoutticketp;//调用outoutticket函数printf"是否要订这个车次<0/1>\n";scanf"%d";℘fflushstdin;if wp{s=peoplemalloc sizeof people;printf"请输入姓名:";scanf"%s";&s->;fflushstdin;printf"请输入电话:";scanf"%s";&s->m.tel;fflushstdin;printf"请输入身份证号:";scanf"%s";&s->m.id;fflushstdin;printf"请输入要订的票数:";scanf"%s";&s->m.booknum;fflushstdin;s->next=NULL;v->next=s;v=s;strcpys->m.checi;p->data.tnum;p->reseat=p->reseat+int atofs->m.booknum;if p->seatnum.a<8{sprintfdingdano.seatnum;"%d/%d";p->seatnum.a;p->seatnum.b;p->seatnum.a=p->seatnum.a+1;}elseif p->seatnum.b<8{sprintfdingdano.seatnum;"%d/%d";p->seatnum.a;p->seatnum.b;p->seatnum.b=p->seatnum.b+1;p->seatnum.a=1;}printf"\nOK订票成功\n";strcpydingdano.tnum;p->data.tnum;strcpydingdano.time1;p->data.time1;strcpydingdano.station1;p->data.station1;strcpydingdano.station2;p->data.station2;strcpydingdano.tujingstation;p->data.tujingstation;strcpydingdano.time2;p->data.time2;strcpydingdano.money;p->data.money;;s->;strcpydingdano.tel;s->m.tel;strcpydingdano.id;s->m.id;strcpydingdano.booknum;s->m.booknum;printf"订单号为:%d\n";dingdano.danhao;printf"座位号为:%s座位号/车厢号\n";dingdano.seatnum; o++;getch;}}}void cancel{int count=0;extern int o;char q5="失效";int p;int s=0;char passname20;printf"请输入乘客姓名:";scanf"%s/n";passname;forint i=0;i<o;i++{if strcmppassname;==0{printf"\n";printf" 这是订单号为%d的订单信息\n";dingdani.danhao;printf"\n";printf" 火车车次:%s\n";dingdani.tnum;printf" 发车时间:%s\n";dingdani.time1;printf" 出发站:%s\n";dingdani.station1;printf" 终点站:%s \n";dingdani.station2;printf" 途径站:%s \n";dingdani.tujingstation;printf" 到站时间:%s \n";dingdani.time2;printf" 票价:%s \n";dingdani.money;printf" 姓名:%s\n";;printf" 电话:%s\n";dingdani.tel;printf" 身份证:%s\n";dingdani.id;printf" 订票数目:%s\n";dingdani.booknum;printf" 座位号:%s<座位号/车厢号>\n";dingdani.seatnum;printf"\n";printf"----------------------------------------------------------------------------\n";count++;}}if count==0{printf"未找到该乘客的订票信息\n";goto low;}printf"请输入要删除的订单编号:";scanf"%d\n";&p;for s=0;s<o;s++{if p==dingdans.danhao{ strcpydingdans.tnum;q;strcpydingdans.time1;q;strcpydingdans.station1;q;strcpydingdans.station2;q;strcpydingdans.tujingstation;q;strcpydingdans.time2;q;strcpydingdans.money;q;;q;strcpydingdans.tel;q;strcpydingdans.id;q;strcpydingdans.booknum;q;printf"\n";printf" 这是订单号为%d的订单信息\n";dingdans.danhao;printf"\n";printf" 火车车次:%s\n";dingdans.tnum;printf" 发车时间:%s\n";dingdans.time1;printf" 出发站:%s\n";dingdans.station1;printf" 终点站:%s \n";dingdans.station2;printf" 途径站:%s \n";dingdans.tujingstation;printf" 到站时间:%s \n";dingdans.time2;printf" 票价:%s \n";dingdans.money;printf" 姓名:%s\n";;printf" 电话:%s\n";dingdans.tel;printf" 身份证:%s\n";dingdans.id;printf" 订票数目:%s\n";dingdans.booknum;printf" 座位号:%s<座位号/车厢号>\n";dingdani.seatnum;printf"\n";printf"----------------------------------------------------------------------------\n";}}low:;}void admin{int password=1;extern int o;int n;printf"请输入管理员密码:";scanf"%d\n";&n;fflushstdin;if password==n{forint i=0;i<o;i++{printf"\n";printf" 这是订单号为%d的订单信息\n";dingdani.danhao;printf"\n";printf" 火车车次:%s\n";dingdani.tnum;printf" 发车时间:%s\n";dingdani.time1;printf" 出发站:%s\n";dingdani.station1;printf" 终点站:%s \n";dingdani.station2;printf" 途径站:%s \n";dingdani.tujingstation;printf" 到站时间:%s \n";dingdani.time2;printf" 票价:%s \n";dingdani.money;printf" 姓名:%s\n";;printf" 电话:%s\n";dingdani.tel;printf" 身份证:%s\n";dingdani.id;printf" 订票数目:%s\n";dingdani.booknum;printf" 座位号:%s<座位号/车厢号>\n";dingdani.seatnum;printf"\n";printf"----------------------------------------------------------------------------\n";}}}void passenger{char passname20;printf"请输入乘客姓名:";scanf"%s/n";passname;fflushstdin;forint i=0;i<o;i++{if strcmppassname;==0{printf"\n";printf" 这是订单号为%d的订单信息\n";dingdani.danhao;printf"\n";printf" 火车车次:%s\n";dingdani.tnum;printf" 发车时间:%s\n";dingdani.time1;printf" 出发站:%s\n";dingdani.station1;printf" 终点站:%s \n";dingdani.station2;printf" 途径站:%s \n";dingdani.tujingstation;printf" 到站时间:%s \n";dingdani.time2;printf" 票价:%s \n";dingdani.money;printf" 姓名:%s\n";;printf" 电话:%s\n";dingdani.tel;printf" 身份证:%s\n";dingdani.id;printf" 订票数目:%s\n";dingdani.booknum;printf" 座位号:%s<座位号/车厢号>\n";dingdani.seatnum;printf"\n";printf"----------------------------------------------------------------------------\n";}}}void print{printf"\n";printf" 1:管理员登陆需管理员密码 \n";printf" 2:乘客登陆 \n";printf"\n";printf"请选择登录方式:";int m;scanf"%d\n";&m;fflushstdin;switch m{case 1:admin;break;case 2:passenger;break;default:break;}}。
c语言购票课程设计一、课程目标知识目标:1. 理解C语言中基本的数据类型和运算符,并能够运用到实际编程中;2. 学会使用C语言进行顺序结构、选择结构和循环结构的编程;3. 掌握C语言数组的使用,并能实现对数据的存储和操作;4. 了解C语言函数的定义和调用,能够编写简单的函数实现特定功能;5. 了解结构体类型,能够使用结构体表示实际问题的数据结构。
技能目标:1. 能够运用C语言编写一个简单的购票系统,实现票务的查询、购买和退票功能;2. 培养学生独立分析问题、设计算法和编写程序的能力;3. 提高学生调试程序、解决问题的实际操作能力。
情感态度价值观目标:1. 激发学生对计算机编程的兴趣,培养学习编程的积极态度;2. 培养学生团队合作意识,提高沟通协调能力;3. 增强学生面对困难的勇气和信心,培养克服困难的毅力;4. 引导学生认识到编程在实际生活中的应用,体会科技改变生活的价值。
课程性质:本课程为C语言编程实践课程,以项目驱动的方式进行教学,让学生在实际编程过程中掌握C语言的基本知识和技能。
学生特点:学生已具备一定的计算机操作能力,对编程有初步的了解,但实际编程经验不足。
教学要求:注重理论与实践相结合,强化动手实践,培养学生编程思维和解决问题的能力。
通过项目实践,使学生能够将所学知识运用到实际编程中,达到学以致用的目的。
二、教学内容1. C语言基础知识回顾:数据类型、变量、常量、运算符、表达式;2. 控制结构:顺序结构、选择结构(if语句、switch语句)、循环结构(for循环、while循环、do-while循环);3. 数组:一维数组、二维数组,数组的使用和操作;4. 函数:函数定义、函数调用、函数参数传递、递归函数;5. 结构体:结构体定义、结构体变量声明和初始化、结构体数组、结构体指针;6. 指针:指针的基本概念、指针的使用、指针与数组、指针与函数、指针与结构体;7. 文件操作:文件打开与关闭、文件的读写操作、文件定位;8. 购票系统设计:需求分析、系统设计、模块划分、功能实现;- 票务查询功能:查询可用票数、票价等信息;- 购票功能:选择座位、支付、生成订单;- 退票功能:退票、退款处理。
火车订票系统c++程序第一篇:火车订票系统c++程序/* 头文件 */ #include //标准输入、输出头文件#include //包含字符串函数处理头文件#include //包含动态存储与释放函数头文件 /* 宏定义 */ #define GESHI “ 车次站数起始站终点站开车时间到达时间票数n” //输出表头#define PRINT “ %5s%10s%10s%10s%13s%13s%10dn”,s[i].code,s[i].data,s[i].l p,s[i].ap,s[i].lt,s[i].at,s[i].count //输出记录格式 #define N 1000 //最大列车组数/* 结构定义*/ struct train //定义结构体数组{ char code[10];//车次char data[10];//站数char lp[20];//起始站char ap[20];//终点站char lt[10];//开车时间char at[10];//到达时间int count;//票数 }s[N];/* 全局变量 */ int i;//输入计数器 int m=0;//合计计数器 char l[20];//纠错空间/* 函数声明*/ void INPUT();//输入车次信息void PRINTF();//输出车次信息 void save();//保存车次信息 void read();//读取车次信息void search();//查找车次信息void dingpiao();//订票信息 void tuipiao();//退票信息 void WRONG();//纠错模块/////////////////////////////////////////////////////////////////// ////////////////////主函数 void main(){int j;do { system(“cls”);//清屏语句printf(“ ********************************************************** ***n”);printf(“ 欢迎进入火车票务管理系统n”);printf(“ ***************************************************** ********”);printf(“ n请输入选项nn”);printf(“ 1.添加列车信息nn” “2.查找nn” “3.订票nn” “4.退票nn” “5.退出nn”);printf(“ **************************************************** *********nn”);printf(“请选择:”);scanf(“%d”,&j);gets(l);switch(j){ case 1: INPUT();//调用输入模块break;case 2:search();//调用查找模块break;case 3:dingpiao();//调用订票模块break;case 4:tuipiao();//调用退票模块break;case 5:;break;default:WRONG();break;} }while(j!=5);//判断结束printf(“n王志强1241班201210913124 n ”);printf(“n--------”);printf(“n 正在退出,请按任意键退出”);printf(“n--------n ”);}//主函数结束/////////////////////////////////////////////////////////////////// ///////////////////////输入模块 void INPUT(){int y;system(“cls”);printf(“n ====================欢迎进入录入火车时刻信息界面====================nn”);for(i=0;iprintf(“请输入车次号: ”);scanf(“%s”,&s[i].code);//读取车次号printf(“请输入站数: ”);scanf(“%s”,&s[i].data);//读取站数printf(“请输入起始站: ”);scanf(“%s”,s[i].lp);//读取起始站printf(“请输入终点站: ”);scanf(“%s”,s[i].ap);//读取终点站printf(“请输入开车时间: ”);scanf(“%s”,s[i].lt);//读取开车时间printf(“请输入到达时间: ”);scanf(“%s”,s[i].at);//读取到达时间printf(“请输入车票数: ”);scanf(“%d”,&s[i].count);//读取票数m++;printf(“第%d个信息已经输完.按任意键继续,按0 结束:”,m);scanf(“%d”,&y);gets(l);if(y==0){ save();//将结构体信息存盘 PRINTF();//输出输入的列车信息printf(“n 按任意键返回上级菜单: ”);gets(l);break;} }}////////////////////////////////////////////////////////////////////////保存模块程序 void save(){ FILE *fp,*fp1;//定义文件指针if((fp=fopen(“chen.dat”,“wb”))==NULL)//打开文件并判断是否出错{ printf(“创建文件失败!nn”);//打印出错提示getchar();ret urn;} if((fp1=fopen(“hao.dat”,“wb”))==NULL)//打开文件并判断是否出错{ printf(“创建文件失败!nn”);//打印出错提示 getchar();return;}for(i=0;iprintf(“向文件输入数据失败!nn”);fprintf(fp1,“%d”,m);fclose(fp);//关闭文件fclose(fp1);//关闭文件 }/////////////////////////////////////////////////////////////////// ////文件读取模块 void read(){ FILE *fp,*fp1;//定义文件指针if((fp=fopen(“chen.dat”,“rb”))==NULL)//打开文件,并判断是否出错{ printf(“出错,请检查文件是否存在,按任意键返回住菜单”);//打印出错提示getchar();} if((fp1=fopen(“hao.dat”,“rb”))==NULL)//打开文件并判断是否出错{ printf(“创建文件失败!nn”);//打印出错提示getchar();return;} fscanf(fp1,“%d”,&m);fclose(fp1);//关闭文件for(i=0;i/////////////////////////////////////////////////////////////////// ///////////查询模块void search(){ char name1[20];char name2[20];char ii[10];int nk;char no[10];do { system(“cls”);//清屏语句printf(“nn ====================欢迎进入查询火车时刻信息界面====================n”);printf(“n++++++++++++++++++请选择查找方式++++++++++++++++++nn”);printf(“----1.显示所有列车信息2.按车次查询3.按始发站查询----n”);printf(“-----4.按终点站查询5.返回主菜单----n”);printf(“n 请选择:”);scanf(“%d”,&nk);//读取查找方式gets(l);if(nk==5)break;switch(nk){ case 1:PRINTF();//调用打印模块break;case 2: printf(“请输入车次号:n”);scanf(“%s”,&no);//车次号break;case 3: printf(“请输入始发站名称:n”);scanf(“%s”,name1);//读取始发站break;case 4: printf(“请输入终点站名称:n”);scanf(“%s”,name2);//终点站 break;default: WRONG();break;} read();//调用读取函数 for(i=0;i>是否继续查找?(y/n)<--------nntt”);scanf(“%s”,ii);}while(strcmp(ii,“y”)==0);//判断结束} //////////////////////////////////////////////////////////////////////// ///////////订票模块void dingpiao(){ int n;char a[10];do { system(“cls”);search();//调用查询模块printf(“请输入您要订的车票数以回车键结束:”);scanf(“%d”,&n);//读取所订机票数if(n<0){ system(“cls”);WRONG();//scanf(“%s”,l);//gets(l);break;} if(s[i].count!=0&&s[i].count>=n)//判断是否出错{ s[i].count=s[i].count-n;//调用保存函数system(“cls”);printf(“订票成功!nn”);printf(“ntt按任意键返回主菜单: ”);scanf(“%s”,l);break;} if(s[i].countbreak;} printf(“是否继续?(y/n):n”);//判断是否继续订票scanf(“%s”,a);}while(!strcmp(a,“y”));//判断结束}//////////////////////////////////////////////////////////////////////// ///////退票模块 void tuipiao(){ int n;char a;do { search();//调用查询模块printf(“请输入您要退的机票数目:n”);scanf(“%d”,&n);//输入所退票数gets(l);if(n<0)//判断票数是否有效{WRONG();break;} s[i].count=s[i].count+n;do{system(“cls”);//借鉴而来的清屏语句,好用!printf(“nn-->退票成功<--”);printf(“nn-->继续 y,返回主菜单n <--”);a=getchar();gets(l);if(a!='y'&&a!='n')WRONG();}while(a!='y'&&a!='n');}while(a!='n');//判断并跳出循环} //////////////////////////////////////////////////////////////////////// ///////////////纠错模块void WRONG(){ system(“cls”);//借鉴而来的清屏语句,好用!printf(“nn--->!!输入错误,请按任意键返回!!<---”);gets(l);}第二篇:火车订票管理系统学号11~15 选题三:火车票订票管理系统1.基本要求:为方便管理火车票购买信息,编写一个火车票订票管理系统软件。
数据库课程设计报告 -------火车售票管理信息系统软件学院软件工程2013级x班姓名: xx学号:2013xxxxxxxx目录一、系统开发平台 (1)四、需求分析 (2)4.1 用户需求说明 (2)4.1.1 数据需求 (2)4.1.2 事务需求 (3)4.2 系统需求说明 (4)五、数据库逻辑设计 (4)5.1 ER图 (4)5.2 数据字典 (5)5.3 关系表 (7)六、数据库物理设计 (7)6.1 索引 (7)6.2 视图本节可选 (8)6.3 安全机制 (8)七、应用程序设计 (8)7.1 功能模块 (8)7.2 界面设计 (15)7.3 事务设计 (15)八、测试和运行 (16)九、总结 (16)一、系统开发平台题目:对火车站的售票进行管理。
主要功能:车次管理(车次、起止地点、到达时间、开车时间)、每一车次的车票管理(车厢号、座位号)、售票、退票、查询、异常处理。
开发工具:eclipse数据库:mysql操作系统:windows8.1二、数据库规划2.1 任务陈述:做一个火车票售票管理系统:对火车站的售票进行管理。
主要功能:车次管理(车次、起止地点、到达时间、开车时间)、每一车次的车票管理(车厢号、座位号)、售票、退票、查询、异常处理。
2.2 任务目标完成一个火车票售票管理系统,要实现管理员对车票的增添以及删改功能,同时需要实现用户对车票的查询购买,以及出现调整之后的退票服务。
三、系统定义3.1 系统边界管理员:可以对车票以及车次进行删改操作。
用户:可以买票,但是不可以对火车票进行添加操作3.2 用户视图3.2.1 管理员视图(1)列车管理:包括列车的录入、查询、修改和删除。
(2)用户管理:包括系统使用用户的添加、查询、修改、删除等。
在线支付用户身份信息用户注册车次设置管理员车次信息录入用户信息管理票务系统车站实际情况(3)系统数据处理:数据查询,根据关键字过滤,查看当前车次信息,车票信息,用户信息以及处理历史。
火车调度c语言程序实现代码(总3页)本页仅作为文档封面,使用时可以删除This document is for reference only-rar21year.March#define MAXSIZE 100/* 栈、队列的最大容量,设为100 */#include <>#include <>typedef char datatype;typedef struct {datatype stack[MAXSIZE]; /* 装载栈的向量 */int top; /* 栈顶指针 */} seqstack; /* 顺序栈类型定义*/typedef struct{ datatype queue[MAXSIZE];/* MAXSIZE为队列的最大长度 */int front;int rear;} sequeue; /* 顺序队列类型定义*/void setstacknull(seqstack *s ) /* 置空栈 */{ s->top=-1; }datatype pop(seqstack *s ) /* 出栈 */{ if (s->top<0 ){ printf( "stack empty!\n" );return('\0');}else{ s->top--; /* 产生新栈顶指针 */return(s->stack[s->top+1]); /* 返回原栈顶元素值 */ }}int empty(seqstack *s) /* 判断是否为空栈 */{if (s->top<0 ) return(1);else return(0);}void push(seqstack *s,datatype x) /* 入栈 */{ if ( s->top>=MAXSIZE-1 ) /* 上溢 */printf( "stack overflow!\n" );else{ s->top=s->top+1; /* 1.栈顶指针加1 */s->stack[s->top]=x; /* 2.新元素入栈 */}}void setseqnull(sequeue *sq) /* 置空队列 */{sq->front=-1; sq->rear=-1; }void encyque(sequeue *sq,datatype x) /* 入队 */ {if((sq->rear+1)%MAXSIZE==sq->front)printf( "queue overflow!\n" );else{ sq->rear=(sq->rear+1)%MAXSIZE;sq->queue[sq->rear]=x;}}datatype delcyque(sequeue *sq) /* 出队 */{if(sq->front==sq->rear)return(NULL);else{ sq->front=(sq->front+1)%MAXSIZE;return(sq->queue[sq->front]);}}main( ){seqstack *st;sequeue *trainsq;char ch, trains[MAXSIZE],*p=trains;st=(seqstack *)malloc(sizeof(seqstack));trainsq=(sequeue *)malloc(sizeof(sequeue));setstacknull(st);setseqnull(trainsq);printf("enter train serious:\n");gets(trains);putchar('\n');ch=*p;while (ch!='\0'){ ch=*p;if (ch=='L'){ push(st,ch);ch=pop(st);encyque(trainsq,ch);}else{push(st,ch);}p=p+1;}int i=0;p=trains;while(!empty(st)) {ch=pop(st); if(ch=='Q')encyque(trainsq,ch);else{*p=ch;p++;i++;}}if(i>=0){ch=trains[i];push(st,ch);ch=pop(st);encyque(trainsq,ch);i--;}printf("new train serious:\n");while (ch=delcyque(trainsq)) putchar(ch); putchar('\n');}。
c语言火车源代码以下是一个简单的C语言火车源代码示例,用于模拟火车的运行:c复制代码#include<stdio.h>#include<stdlib.h>#include<time.h>#define MAX_TRAIN_LENGTH 100#define TRAIN_SPEED 10typedef struct {int position;int direction; // 0: stop, 1: forward, -1: backward} Train;void move_train(Train *train) {if (train->direction == 1) {train->position += TRAIN_SPEED;} else if (train->direction == -1) {train->position -= TRAIN_SPEED;}}int is_train_at_destination(Train *train) {return train->position >= MAX_TRAIN_LENGTH;}int main() {srand(time(NULL)); // 初始化随机数生成器Train train = {0, 0}; // 初始化火车初始位置和方向for (int i = 0; i < 50; i++) { // 模拟火车运行50次move_train(&train); // 移动火车if (is_train_at_destination(&train)) { // 如果火车到达目的地,重置位置和方向train.position = 0;train.direction = rand() % 2; // 随机选择前进或后退方向}printf("Train position: %d\n", train.position); // 输出火车位置}return0;}这个程序使用了一个结构体来表示火车,其中包含火车的位置和方向。
一、课程设计的原始资料及依据在现代社会,火车以其安全,舒适以及其服务的周到使愈来愈多的人选择了火车为长距离出行的交通工具,这就使火车公司以及车站的工作量愈来愈大,若仍然使用文件或者人工来管理公司、车站、火车、列班、路线、客户以及售票的信息,那无疑在效率上会大打折扣。
21世纪的今天,信息社会占着主流地位,计算机在各行各业中的运用已经得到普及,自动化、信息化的管理越来越广泛应用于各个领域。
利用计算机来储存和管理公司、车站、火车、列班、车线、客户以及售票的信息成为了首选,在这种情况下,火车订票系统就显得非常重要了。
两个客户名单可分别由线性表和队列实现。
为查找方便,已订票客户的线性表应按客户姓名有序,并且,为插入和删除方便,应以链表作存储结构。
由于预约人数无法预计,队列也应以链表作存储结构。
整个系统需汇总各条路线的情况登录在一张线性表上,由于路线基本不变,可采用顺序存储结构,并按车次有序或按终点站名有序。
每条路线是这张表上的一个记录,包含上述8个域,其中乘员名单域为指向乘员名单链表的头指针,等候替补的客户名单域为分别指向队头和队尾的指针。
队列(Queue)是只允许在一端进行插入,而在另一端进行删除的运算受限的线性表。
用队列来进行客户信息的存储。
编辑用户使用菜单,内容包括:输入列班信息,保存列班信息,读取列班信息,查找列班信息,删除列班信息,订票信息,退票信息以及修改信息。
二、课程设计主要内容及要求1. 列车基本信息管理:输入所有列班信息。
每条路线所涉及的信息有:终点站名、车次号、车厢号、开车周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、座位等级1,2或3)以及等候替补的客户名单(包括姓名、所需的票量)。
2.列车基本信息查询:按车次号查找,按抵达站查找,按路线查找三种查找方式进行查找。
3. 订票管理:客户对想要购买的票进行订票。
3. 退票管理:将不想要的票进行退票。
三、对课程设计说明书撰写内容、格式、字数的要求1.课程设计说明书是体现和总结课程设计成果的载体,主要内容包括:设计题目、设计目的、设备器材、设计原理及内容、设计步骤、遇到的问题及解决方法、设计总结、设计小组评语、参考文献等。
火车订票系统源码(一)#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <string.h>intshoudsave=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;/*票价*/intbookNum ;/*票数*/};/*订票人的信息*/struct man{charnum[10];/*ID*/char name[10];/*姓名*/intbookNum ;/*需求的票数*/};/*定义火车信息链表的结点结构*/typedefstruct node{struct train data ;struct node * next ;}Node,*Link ;/*定义订票人链表的结点结构*/typedefstruct people{struct man data ;struct people*next ;}bookMan,*bookManLink ;/* 初始界面*/voidprintInterface(){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("********************************************************"); }/*添加一个火车信息*/voidInsertTraininfo(Link linkhead){struct node *p,*r,*s ;charnum[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 ;}}/*打印火车票信息*/voidprintTrainInfo(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,charfindmess[],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 ;}/*查询火车信息*/voidQueryTrain(Link l){Node *p ;intsel ;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!");}}}/*订票子模块*/voidBookTicket(Link l,bookManLink k){Node*r[10],*p ;charch,dem ;bookMan*v,*h ;int i=0,t=0 ;charstr[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<i;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->,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(bookManLinkk,charfindmess[]) {bookMan*r ;r=k->next ;while(r){if(strcmp(r->data.num,findmess)==0){mark=1 ;return r ;}r=r->next ;}return 0 ;}/*修改火车信息*/voidUpdateInfo(Link l){Node*p ;charfindmess[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 ;}elseprintf("\t\t\tcan't find the record!");}}elsemark1=0 ;}}/*系统给用户的提示信息*/voidAdvicedTrains(Link l){Node*r ;charstr[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");}/*保存火车信息*/voidSaveTrainInfo(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);}/*保存订票人的信息*/voidSaveBookmanInfo(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 ;intsel ;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;}11/11。
火车票查询系统摘要随着网络时代的快速发展,中国网民人数的持续增加,电子商务的普及以及中国现代物流的飞速发展,互联网法律法规的逐步完善,电子商务的环境已经初步形成,网上购物系统作为电子商务的一种主要实现形式必将得到进一步的普及和应用。
该系统主要为用户提供了会员注册、网上查询等功能;在设计方面,系统是典型的电子商务平台, 其开发基于B/S模式的网上销售的实现,采用的是ASP + ACCESS 模式。
该系统设计上采用三层结构、Web Service技术,使之在选用平台、采用技术上具有先进性、前瞻性、扩充性,从而保证建成的系统具有良好的稳定性、可扩充性。
从功能上来说,系统是比较完备的,系统以Web界面与用户交互,为用户提供信息并接受其操作,同时通过数据库管理系统来存储信息数据。
系统实现了对信息数据的浏览、查询、编辑和管理等基本数据库操作,采用了模块化设计方法,根据用户的需求及程序的应用与维护的易用性,将各个部分置于不同的模块当中,方便了程序的扩展与维护,同时建立了程序功能复用的基础。
本文所做火车票网上查询系统是一个根据现有的网上查询系统的现状而设计开发的电子商务平台,可以减少成本,提高工作效率。
关键词:网上查询;电子商务;ASP;交互AbstractWith the increasing number of netizens, the emergence of third--party payment means as well as the rapid development of modern logistic and the improvement of laws and regulations, the environment of e-commerce has formed in china. The shop online system which acted as one way to implement of electronic commerce will become more and more popular in the future.This system mainly to provide users with a registered member, preview tourist attractions, tickets online, provides the ticket for the administrator management, customer information management and information management, advertising spots link management etc. Function. In the design, system is a typical e-commerce sales platform, its development based on B/S model, online sales by ASP + ACCESS mode. Choose ACCESS database of backstage supporter's database. This system is used on three-layer structure design, Web Service technology, make in selecting, using the platform with advanced technology, prospectie, expand, and ensure the completion of the system has a good stability and extensibility. Using software component, system structure, development, business and separated, logic and data: In a unified service interface standard as the core, the use of open standards. From the function, system is relatively complete system with Web interface and the user interaction, and provide information and accept its operation, and through a database management system to store information and data. System of data to browse, query, editing and management database, the basic operating modular design methods, according to user's requirements and procedures of application and maintenance of facility, and the different parts will be placed among modules, convenient maintenance and expansion of the program, and established the basic program function reuse.The tourist attractions do online ticketing system is an online ticketing system according to the current situation of the development and design of e-commerce platform. It not only can expand the scale and influence the market business, and can reduce the operating costs, improve work efficiency.Key words:Online ticketing; e-commerce;ASP; interacti目录1绪论 (4)1.1课题现状 (4)1.2课题开发目的 (4)1.3课题关键技术 (5)1.3.1 ASP简介 (5)1.3.2 Dreamweaver (5)1.3.3 ACCESS (6)1.3.4 HTML(Hyper Text Markup Language) (6)2 可行性研究 (6)2.1资源可行性 (7)2.2技术可行性 (7)2.3经济可行性 (7)2.4社会的可行性 (7)3 系统需求分析 (8)3.1目标和任务 (8)3.2系统功能分析 (8)3.2.1 查询功能分析 (8)3.2.2 网站的界面设计 (8)3.3网站业务流程 (9)3.3.1 火车票网上查询系统的业务流程介绍 (9)3.3.2 系统的设计流程图 (9)4 系统概要设计 (10)4.1系统结构设计目标 (10)4.1.1 系统HIPO图 (10)4.1.2 系统功能模块介绍 (11)4.1.2.1登录模块 (11)4.1.2.2 注册模块 (11)4.1.2.3查询模块 (11)4.1.2.4用户管理模块 (11)4.2数据库结构设计 (11)4.2.1 数据库概念结构设计 (11)4.2.2数据库逻辑结构 (13)5 系统详细设计 (14)5.1系统总体结构图 (14)5.2过程设计 (15)5.2.1.系统用户权限的系统主处理流程 (16)5.2.2.车次信息查询处理流程 (17)6 系统运行与测试 (18)6.1系统调试 (18)6.2测试与运行 (18)6.2.1.系统管理员登陆首页 (18)6.2.2系统用户登陆注册首页 (19)6.2.3.车次查询界面 (19)6.2.4.车次查询结果 (20)结束语 (20)致谢 (21)参考文献 (21)附录 (21)1 绪论网上查询,相对于传统查询方式而言,是随着现代信息技术的发展而产生的一种新型查询方式,是一种消费者和工作人员分离的、非面对面的查询方式,是一种跨地区的查询模式。
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>#include<conio.h>#define N 1000typedef struct TICKET //定义新结构体TICKET {char num[10]; //车次char hour[3];char min[3];char from[10];char to[10];float hours;int max; //车载容量int now; //已售票数}CLASS;int class_num=0;CLASS records[N];int system_time();void message();void ShowTable1();void ShowTable2(int i);void Display();void add();void save();void load(); // 按班次查询void search(); //查询void change(); //修改void quit(); //退出void buyticket(); //售票void deleteticket(); //取消int menu_select(); //菜单int whether(int); //判断购买时间void find(char s1[],char s2[]); //按起点终点查询void deletemessage(); //删除int findnum(char s1[]); //班次查询void get(int,int); //修改及增加班次char*menu[]={" 欢迎使用车票查询系统","\n*******************菜单***********************", "\n 1. 录入班次","\n 2. 浏览班次信息","\n 3. 查询路线","\n 4. 增加班次","\n 5. 售票","\n 6. 退票","\n 7. 修改班次","\n 8. 删除班次","\n 9. 退出"};int main(){system("cls");while(1){switch(menu_select()) //菜单{case 1: message();break;case 2: Display();break;case 3: search();break;case 4: add();break;case 5: buyticket();break;case 6: deleteticket();break;case 7: change();break;case 8: deletemessage();break;case 9: quit();break;}}}int menu_select() //菜单{char s[5];int c,i;system("cls");for(i=0;i<11;i++){printf("%s",menu[i]); //输出菜单}i=0;while(c<0||c>9){printf("\n");printf("\n请输入选项(1-9): ");scanf("%s",s);c=atoi(s);}//输出菜单return c;}void message() //录入{int i=0,j=5,h;char s[5];FILE *fp; //定义文件型指针变量system("cls"); //刷屏if((fp=fopen("d:车票管理系统0.dat","rb"))!=NULL) //fopen打开文件{printf("增加信息\n");printf("请输入任意键返回\n");scanf("%s",s);i=1;}if(i==0){system("cls"); //刷屏printf("请输入班次总数:\n");scanf("%d",&class_num); //指向班次指针system("cls"); //刷屏for(i=0;i<class_num;i++){system("cls"); //刷屏printf("请输入%d班次信息:\n",i+1);h=-1;for(;h!=i;) ///循环输出{printf("请输入班次:\n");scanf("%s",records[i].num);for(h=0;h<i;h++)if(strcmp(records[h].num,records[i].num)==0){printf("该班次已存在\n");break;}}get(i,j); //修改及增加班次j=5;}save(); //调用保存函数}}/*******************************显示所有函数********************************/void Display() //显示所有函数{int i,j;system("cls"); //刷屏load(); // 按班次查询ShowTable1();for(i=0,j=0;i<class_num;i++,j+=2) //按班次顺序输出{if(whether(i)) //判断时间是否超出printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].h our,records[i].min, records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);elseprintf("|%10s| 已发车|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);}ShowTable2(j);printf("\n按任意键继续\n");getch();}void ShowTable1(){int i=2;system("cls"); //刷屏printf(" 班次信息\n");printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");printf("\n| 班次| 发车时间| 起点站| 终点站|行车时间|额定载量| 已售票|\n");}void ShowTable2(int i){printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");}void search() //查询班次{int i;char s1[10]={'\0'},s2[10]={'\0'};system("cls"); //刷屏printf("1. 按班次查询\n");printf("2. 按终点站查询\n");printf("3. 退出\n");printf("请选择(1-3):\n");scanf("%d",&i);load(); //按班次查询switch(i){case 1: printf("请输入要查询的班次:\n");scanf("%s",s1);find(s1,s2);break;case 2: printf("请输入要查询终点站:\n");scanf("%s",s2);find(s1,s2);break;case 3: break;default : printf("输入错误!\n");break;}printf("按任意键继续\n");getch();}void find(char s1[],char s2[]){int i,h=0,m;ShowTable1();if(s2[0]=='\0')m=1;else m=0;for(i=0;i<class_num;i++)if(strcmp(s1,records[i].num)==0||strcmp(s2,records[i].to)==0){printf("\n");printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].h our,records[i].min,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);h+=2;if(m==1)break;}ShowTable2(h);if(h==0)printf("查找的班次不存在\n");}void add(){int i,j=5;load();system("cls");printf("1. 增加班次\n");printf("2. 返回\n");printf("请选择(1-2)\n");scanf("%d",&i);if(i==1){system("cls");printf("1. 输入要增加的班次:\n");scanf("%s",records[class_num].num);for(i=0;i<class_num;i++)if(strcmp(records[class_num].num,records[i].num)==0){printf("输入错误\n");getch();break;}if(i==class_num){get(i,j);class_num++;save();}}}void buyticket(){int i;char num[10];system("cls");printf("1. 售票\n");printf("2. 返回\n");printf("请选择(1-2):\n");scanf("%d",&i);if(i==1){load(); // 按班次查询search();printf("请输入要订票的班次(若无请输入0):\n");scanf("%s",num);for(i=0;i<class_num;i++)if(strcmp(num,records[i].num)==0)if(records[i].max>records[i].now&&whether(i)==1){records[i].now++;printf("通向%s班次为%s的票订票成功\n",records[i].to,records[i].num);save();getch();break;}else{printf("该班次已满或已发出!\n");getch();}}}void deleteticket(){int i;char num[10];system("cls");printf("1. 退票\n");printf("2. 返回\n");printf("请选择(1-2)\n:");scanf("%d",&i);if(i==1){system("cls");load();printf("请输入要退票的班次:\n");scanf("%s",num);i=findnum(num);if(strcmp(num,records[i].num)==0)if(whether(i)){printf("是否确认");scanf("%s",num);if(num[0]=='y'||num[0]=='Y'){records[i].now--;printf("退票成功\n");save();getch();}}else{printf("该班车已发出,无法退票\n");getch();}if(i==class_num){printf("输入错误\n");getch();}}}void change(){char num[10],s[10];int h=0,j=13,i;load();system("cls");printf("请输入要修改的班次:\n");scanf("%s",num);i=findnum(num);if(i==class_num){printf("输入错误\n");getch();}else{printf("确认修改\n");scanf("%s",s);if(s[0]=='y'||s[0]=='Y'){get(i,j);save();}}}void deletemessage(){int i,h=0;char num[10];system("cls");printf("1. 删除班次\n");printf("2. 返回\n");printf("请选择(1-2):\n");scanf("%d",&i);if(i==1){system("cls");printf("请输入要删除的班次:\n");scanf("%s",num);i=findnum(num);if(i==class_num){printf("输入错误\n");getch();}else{printf("是否确认\n");scanf("%s",num);if(num[0]=='y'||num[0]=='Y'){for(;i<class_num-1;i++)records[i]=records[i+1];class_num--;save();printf("删除成功\n");getch();}}}}int findnum(char s1[]){int i,h=0;ShowTable1();for(i=0;i<class_num;i++){if(strcmp(s1,records[i].num)==0){printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].h our,records[i].min,records[i].from,records[i].to,records[i].hours,records[i].max,records[i] .now);h+=2;break;}}ShowTable2(h);return i;}void save(){FILE *fp1,*fp2;if((fp1=fopen("d:车票管理系统.dat","wb"))==NULL) //打开文件{printf("文件打开错误!\n");exit(0);}if((fp2=fopen("d:车票管理系统0.dat","wb"))==NULL){printf("文件打开错误!\n");exit(0);}fwrite(&class_num,sizeof(int),1,fp2);fwrite(records,sizeof(CLASS),class_num,fp1);fclose(fp1);fclose(fp2);}void load(){FILE *fp1,*fp2;if((fp1=fopen("d:车票管理系统.dat","rb"))==NULL){system("cls");printf("文件打开错误\n");getch();exit(0);}if((fp2=fopen("d:车票管理系统0.dat","rb"))==NULL) {system("cls");printf("文件打开错误\n");getch();exit(0);}fread(&class_num,sizeof(int),1,fp2);fread(records,sizeof(CLASS),class_num,fp1);fclose(fp1);fclose(fp2);}void quit(){char s[5];printf("确认退出\n");scanf("%s",s);if(s[0]=='y'||s[0]=='Y')exit(0);}void get(int i,int j){for(;;){printf("请输入发车时间(xx xx)");scanf("%s%s",records[i].hour,records[i].min);if((atoi(records[i].hour)<24&&atoi(records[i].hour)>=0)&&(atoi(records[i].min)<60& &atoi(records[i].min)>=0))break;else{printf("输入错误\n");getch();}}printf("请输入起点站:\n");scanf("%s",records[i].from);printf("请输入终点站:\n");scanf("%s",records[i].to);printf("请输入行车时间:\n");scanf("%f",&records[i].hours);printf("请输入额定载量:\n");scanf("%d",&records[i].max);for(;;){printf("请输入已售票数:\n");scanf("%d",&records[i].now);if(records[i].now<=records[i].max) break;else{printf("输入错误\n");getch();}}}int whether(int i){struct tm *local;time_t t;t=time(NULL); //NULL在stdio.h中定义为0local=localtime(&t); /////获取当前系统时间if(local->tm_hour<atoi(records[i].hour)||local->tm_hour==atoi(records[i].hour)&&local->tm_min<atoi(records[i].min))//atoi将字符串转换成一个整数值return 1;elsereturn 0;}。
c语言火车售票系统课程设计一、课程目标知识目标:1. 理解C语言中数组、函数、指针、结构体等基本概念,并能运用到火车售票系统的设计与实现中;2. 掌握C语言文件操作,实现火车票信息的存储与读取;3. 理解并掌握C语言中模块化编程思想,将火车售票系统划分为多个功能模块。
技能目标:1. 能够运用C语言编写出具有良好结构和可读性的代码;2. 培养学生分析问题、解决问题的能力,通过设计火车售票系统,学会使用C 语言进行实际项目开发;3. 学会使用调试工具,对火车售票系统进行测试和优化。
情感态度价值观目标:1. 培养学生合作意识,学会在团队中共同解决问题,提高沟通与协作能力;2. 激发学生对计算机编程的兴趣,培养勇于探索、积极创新的精神;3. 培养学生关注社会实际问题的责任感,了解信息技术在实际应用中的作用和价值。
课程性质:本课程为C语言程序设计课程的实践环节,通过设计火车售票系统,让学生将所学理论知识运用到实际项目中。
学生特点:学生已具备C语言基础知识和一定的编程能力,但对实际项目的开发流程和模块化编程思想尚不熟悉。
教学要求:注重理论与实践相结合,引导学生自主探究,培养学生实际编程能力和团队协作能力。
在教学过程中,关注学生的个体差异,提供个性化指导,确保每位学生都能达到课程目标。
通过课程学习,使学生具备独立开发小型项目的能力。
二、教学内容1. 火车售票系统需求分析:介绍项目背景,分析系统功能需求,明确学生需要实现的功能模块,如用户登录、车次查询、购票、退票、余票显示等。
2. C语言基础知识回顾:- 数组:回顾一维数组、二维数组的概念和应用;- 函数:介绍函数定义、调用、参数传递等基本概念;- 指针:讲解指针的定义、使用和指针操作;- 结构体:回顾结构体的定义和使用。
3. 火车售票系统设计:- 系统架构设计:引导学生采用模块化设计思想,将系统划分为多个功能模块;- 数据结构设计:介绍如何使用结构体和数组来存储和管理车次、座位、用户等信息。
火车票售票系统的设计可以使用C语言来实现。
下面是一个简单的示例,展示了如何设计一个基本的火车票售票系统:```c#include <stdio.h>#include <stdlib.h>#define MAX_SEATS 100typedef struct {int seat_number;char passenger_name[50];} Ticket;Ticket tickets[MAX_SEATS];int total_tickets = 0;void displayMenu() {printf("\n=== 火车票售票系统 ===\n");printf("1. 购买票\n");printf("2. 查询票\n");printf("3. 取消票\n");printf("4. 退出\n");printf("=====================\n");printf("请输入选项: ");}void buyTicket() {if (total_tickets >= MAX_SEATS) {printf("对不起,票已售完。
\n");return;}Ticket ticket;printf("请输入座位号: ");scanf("%d", &ticket.seat_number);// 检查座位号是否已经被购买for (int i = 0; i < total_tickets; i++) {if (tickets[i].seat_number == ticket.seat_number) {printf("对不起,该座位已被购买。
\n");return;}}printf("请输入乘客姓名: ");scanf("%s", ticket.passenger_name);tickets[total_tickets++] = ticket;printf("购票成功!\n");}void queryTicket() {int seat_number;printf("请输入座位号: ");scanf("%d", &seat_number);for (int i = 0; i < total_tickets; i++) {if (tickets[i].seat_number == seat_number) {printf("座位号: %d\n", tickets[i].seat_number);printf("乘客姓名: %s\n", tickets[i].passenger_name); return;}}printf("对不起,该座位未被购买。
湖北工业大学工程技术学院课程设计报告书课程名称:C语言课程设计班级:物联网一班小组成员:范立恒、陈根、聂俊豪、麦灿文、黄文康组长:范立恒指导教师:楚惟善二○一三年六月1 课程题目及要求及要求题目一:火车售票系统任务:结合C语言中相关知识,设计出火车售票系统。
1 录入北京西站车次信息;2 旅客按车次买票;3 统计某日火车票销售金额。
程序要求:⏹贯彻结构化的程序设计思想。
⏹用户界面友好,功能明确,操作方便。
⏹用户界面中的菜单至少应包括“车次信息录入”、“旅客买票”、“统计某日销售金额”、“退出”4项。
⏹代码应适当缩进,并给出必要的注释,以增强程序的可读性⏹为了保证所有的数据可以长期被使用,要求程序能将相关数据存储在外部数据文件中,具体数据格式和文件名、路径等自定;⏹根据所设计的算法,定义相应函数分别实现系统的各子功能模块,同时由主程序提供友好的用户界面,使用户可通过选择主菜单来调用课程设计中要求完成的各个功能模块,子程序执行完后可返回到主菜单,继续选择其他功能执行。
源程序要求书写规范,结构清晰。
重点函数的重点变量,重点功能部分均要求给出清晰的程序注释。
⏹程序编译、链接成功后,自己设计实现程序功能的一组或多组测试数据,并严格按照此测试数据进行测试,然后分析测试结果。
如果程序不能正常运行或结果不正确,则需对程序进行单步调试,在调试过程中认真查找算法实现中存在的问题,并加以分析和2 程序分设计说明经过对程序设计题目的分析可知,整个程序的设计实现大致分为八个模块,每一个模块对应一个函数。
在这些函数当中,添加车次数据函数,售票函数,查询总额函数的实现严格按照题目的要求,而显示时间函数和显示车次函数属于附加功能。
读取文件函数和保存信息函数对其它函数的实现起辅助作用,主函数及菜单函数控制程序的整体运行。
1. 添加车次函数主要实现程序最初运行时车次的录入;2. 旅客买票函数实现的功能是按照旅客所需车次几所购买车票的数目;3. 查询车票总额按照题目的具体要求实现的是总额的查询;4. 显示函数实现的是显示目前所有的有效车次信息。
火车票查询系统代码.txt41滴水能穿石,只因为它永远打击同一点。
42火柴如果躲避燃烧的痛苦,它的一生都将黯淡无光。
#include <iostream.h>#include <string.h>void welcome(); //欢迎系统void choose(); //选择系统void time(int year,int month,int day); //时间判断系统void booktickets(); //订票子系统void sealticket(); //售票子系统void sealticket(char begin[10],char end[10],int number);void returntickets(); //退票子系统int statisticstrain(char begin[10],char end[10]); //站站查询 |int statisticstrain1(char trainnum[10]); //车次查询 } 统计子系统int statisticstrain2(char station[10]); //车站查询 |void querytrain(); //查询子系统int generateddata(char begin[10],char end[10]); //站站查询 |int generateddata1(char trainnum[10]); //车次查询 } 生成数据子系统int generateddata2(char station[10]); //车站查询 |void quit(); //退出系统//欢迎系统void welcome(){cout<<"********************************************************"<<endl;cout<<"* 欢 * 迎 * 使 * 用 * 火 * 车 * 票 * 订 * 票 * 系 * 统 *"<<endl;cout<<"********************************************************"<<endl;cout<<"* 本订票系统有以下功能: *"<<endl;cout<<"* 1:订购火车票 *"<<endl;cout<<"* 2:预定火车票 *"<<endl;cout<<"* 3:退订火车票 *"<<endl;cout<<"* 4:查询车票信息 *"<<endl;cout<<"* 5:退出系统 *"<<endl;cout<<"********************************************************"<<endl;cout<<"请选择所要执行的功能: "<<endl;choose();}//选择系统void choose(){int i;cin>>i;switch (i)case 1:booktickets();break;case 2:sealticket();break;case 3:returntickets();break;case 4:querytrain();break;case 5:quit();break;default:cout<<"请在数字 1-5 之间重新您的输入选择!"<<endl; choose();break;}}//时间判断系统void time(int year,int month,int day){int jy = 1;int y = year % 4;if(month == 2){if(year % 4 == 0){if((year/100)%4 != 0){if(day > 29){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}else{if(day > 28){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}}else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){if(day > 31){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}else if(month == 4 || month == 6 || month == 9 || month == 12){if(day > 30){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}elsecout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}//订票子系统void booktickets(){char begin[10],end[10];int year,month,day;cout<<"请输入出发地:"<<endl;cin>>begin;cout<<"请输入目的地:"<<endl;cin>>end;cout<<"请输入您所要订购的票的出发日期!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;time(year,month,day); //判断输入的时间是否正确cout<<"出发日期为:"<<year<<"-"<<month<<"-"<<day<<endl; int number;cout<<"请输入所要订购的火车票数量:"<<endl;cin>>number;sealticket(begin,end,number); //调用售票系统(2)}//售票子系统(1)void sealticket(){char begin[10],end[10];cout<<"请输入出发地:"<<endl;cin>>begin;cout<<"请输入目的地:"<<endl;cin>>end;int number;cout<<"请输入所要订购的火车票数量:"<<endl;cin>>number;int j = statisticstrain(begin,end); //调用站站统计子系统if(j == 1){char trainnum[10];cout<<"请选择火车车次:"<<endl;cin>>trainnum;int price;cout<<"请选择票价:"<<endl;cin>>price;cout<<endl;cout<<"您所需要的火车票信息:"<<endl;cout<<"出发地:"<<begin<<'\t'<<"目的地"<<end<<'\t'<<"车次:"<<trainnum<<'\t'<<"票价:"<<price<<endl;cout<<"出发日期为:2010-12-24"<<endl;cout<<"您一共订购了 "<<number<<" 张"<<endl;cout<<endl;cout<<"确认无误后请输入 1 "<<'\t'<<"取消请输入 0 "<<endl;int i;cin>>i;if(i == 1){cout<<endl;cout<<"购买成功!"<<endl;cout<<"继续购买请输入 1 "<<'\t'<<"退出购票系统请输入 0 "<<endl;cin>>end;int j;cin>>j;if(j == 1)sealticket();elsewelcome();}elsewelcome();}else if(j == 0)welcome();}//售票子系统(2)void sealticket(char begin[10],char end[10],int number){int j = statisticstrain(begin,end); //调用站站统计子系统if(j == 1){char trainnum[10];cout<<"请选择火车车次:"<<endl;cin>>trainnum;int price;cout<<"请选择票价:"<<endl;cin>>price;cout<<endl;cout<<"您所需要的火车票信息:"<<endl;cout<<"出发地:"<<begin<<'\t'<<"目的地"<<end<<'\t'<<"车次:"<<trainnum<<'\t'<<"票价:"<<price<<endl;cout<<"您一共订购了 "<<number<<" 张"<<endl;cout<<endl;cout<<"确认无误后请输入 1 "<<'\t'<<"取消请输入 0 "<<endl;int i;cin>>i;if(i == 1){cout<<endl;cout<<"购买成功!"<<endl;cout<<"继续购买请输入 1 "<<'\t'<<"退出购票系统请输入 0 "<<endl;cin>>end;int j;cin>>j;if(j == 1)sealticket();elsewelcome();}elsewelcome();}else if(j == 0)welcome();}//退票子系统void returntickets(){char begin[10],end[10];cout<<"请输入出发地:"<<endl;cin>>begin;cout<<"请输入目的地:"<<endl;cin>>end;char trainnum[10];cout<<"请输入火车车次:"<<endl;cin>>trainnum;int price;cout<<"请选择票价:"<<endl;cin>>price;int number;cout<<"请输入所要退订的火车票数量:"<<endl;cin>>number;cout<<endl;cout<<"您所要退订的火车票信息:"<<endl;cout<<"出发地:"<<begin<<'\t'<<"目的地"<<end<<'\t'<<"车次:"<<trainnum<<"票价:"<<price<<endl;cout<<"您一共退订了 "<<number<<" 张"<<endl;cout<<endl;cout<<"确认无误后请输入 1 "<<'\t'<<"取消请输入 0 "<<endl;int i;cin>>i;if(i == 1){cout<<endl;cout<<"退订成功!"<<endl;cout<<"继续退订请输入 1 "<<'\t'<<"退出退票系统请输入 0 "<<endl;cin>>end;int j;cin>>j;if(j == 1)returntickets();elsewelcome();}elsewelcome();}//查询子系统void querytrain(){int i;cout<<endl;cout<<"请选择您要的查询方式:"<<endl;cout<<"1、(出发)站(到达)站查询"<<endl;cout<<"2、车次查询"<<endl;cout<<"3、车站查询"<<endl;cout<<endl;cin>>i;if(i == 1){char from[10],to[10];cout<<"请输入出发站:"<<endl;cin>>from;cout<<"请输入到达站:"<<endl;cin>>to;cout<<endl;statisticstrain(from,to);cout<<endl;welcome();}else if(i == 2){char trainnum[10];cout<<"请输入车次:"<<endl;cin>>trainnum;cout<<endl;statisticstrain1(trainnum);welcome();}else if(i == 3){char station[10];cout<<"请输入车站:"<<endl;cin>>station;cout<<endl;statisticstrain2(station);welcome();}}//统计子系统——站站查询int statisticstrain(char begin[10],char end[10]) {int i = generateddata(begin,end);cout<<endl;return i;}//生成数据子系统——站站int generateddata(char begin[10],char end[10]){if(!strcmp(begin,"changzhou") && !strcmp(end,"nanjing")){cout<<endl;cout<<"从"<<begin<<"到"<<end<<"的火车有:"<<endl;cout<<endl;cout<<"车次:k8372"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:41"<<'\t'<<"到达时间:02:17"<<'\t'<<"参考价格(元): 硬座:22 软座:34 硬卧(上/中/下):68/73/76 软卧(上/下):103/109"<<endl;cout<<endl;cout<<"车次:2582"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:54"<<'\t'<<"到达时间:02:24"<<'\t'<<"参考价格(元): 硬座:19 软座:31 硬卧(上/中/下):65/70/73 软卧(上/下):100/106"<<endl;cout<<endl;cout<<"车次:g7124"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:07:56"<<'\t'<<"到达时间:08:39"<<'\t'<<"参考价格(元): 一等软座:105"<<endl; return 1;}else{cout<<endl;cout<<"没有从 "<<begin<<" 到 "<<end<<" 的火车!"<<endl;return 0;}}//统计子系统——车次查询int statisticstrain1(char trainnum[10]){int i = generateddata1(trainnum);cout<<endl;return i;}//生成数据子系统——车次int generateddata1(char trainnum[10]){if(!strcmp(trainnum,"k8372")){cout<<endl;cout<<"车次为"<<trainnum<<"的火车有:"<<endl;cout<<endl;cout<<"车次:k8372"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:41"<<'\t'<<"到达时间:02:17"<<'\t'<<"参考价格(元): 硬座:22 软座:34 硬卧(上/中/下):68/73/76 软卧(上/下):103/109"<<endl;return 1;}else if(!strcmp(trainnum,"2582")){cout<<endl;cout<<"车次为"<<trainnum<<"的火车有:"<<endl;cout<<endl;cout<<"车次:2582"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:54"<<'\t'<<"到达时间:02:24"<<'\t'<<"参考价格(元): 硬座:19 软座:31 硬卧(上/中/下):65/70/73 软卧(上/下):100/106"<<endl;return 1;}else if(!strcmp(trainnum,"g7124")){cout<<endl;cout<<"车次为"<<trainnum<<"的火车有:"<<endl;cout<<endl;cout<<"车次:g7124"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:07:56"<<'\t'<<"到达时间:08:39"<<'\t'<<"参考价格(元): 一等软座:105"<<endl; return 1;}else{cout<<endl;cout<<"没有车次为 "<<trainnum<<trainnum[0]<<" 的火车!"<<endl;return 0;}}//统计子系统——车站查询int statisticstrain2(char station[10]){int i = generateddata2(station);cout<<endl;return i;}//生成数据子系统——车站int generateddata2(char station[10]){if(!strcmp(station,"changzhou") || !strcmp(station,"nanjing")){cout<<endl;cout<<"出发站(经过站)为"<<station<<"的火车有:"<<endl;cout<<endl;cout<<"车次:k8372"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:41"<<'\t'<<"到达时间:02:17"<<'\t'<<"参考价格(元): 硬座:22 软座:34 硬卧(上/中/下):68/73/76 软卧(上/下):103/109"<<endl;cout<<endl;cout<<"车次:2582"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:54"<<'\t'<<"到达时间:02:24"<<'\t'<<"参考价格(元): 硬座:19 软座:31 硬卧(上/中/下):65/70/73 软卧(上/下):100/106"<<endl;cout<<endl;cout<<"车次:g7124"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:07:56"<<'\t'<<"到达时间:08:39"<<'\t'<<"参考价格(元): 一等软座:105"<<endl; return 1;}else{cout<<endl;cout<<"没有经过 "<<station<<" 的火车!"<<endl;return 0;}}//退出系统void quit(){cout<<endl;cout<<"感谢您的使用!"<<endl;}void main(){welcome();}。
#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];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 = 0; t<i; 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->, 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;}elseprintf("\t\t\tcan't find the record!");}}elsemark1 = 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("D:\\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("D:\\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("D:\\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("D:\\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;}。