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<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;}。