列车时刻表信息管理系统实践报告C语言源代码
(完整word版)列车管理系统C++

#include<iostream>#include〈iomanip>#include<cstring〉using namespace std;int j;struct lieche{char no[10]; //列车车次号char starttime[20];//列车发车时间char reachtime[20];//列车到达时间float price;//票价};struct chengke{char NO[10];//乘客需要的列车号int year;//列车出发的年int month;//月int day;//日char name[10];//乘客姓名char number[20];//乘客身份证号};class program{public://void mainmenu();//主菜单,用于管理员密码输入void luru();//输入菜单void search();//查询菜单void Delete();//删除菜单void add();//增加菜单void xiugai();//修改列车信息void yuding();//预定菜单//void weluse();//退出界面private:lieche a[20];chengke b[20];};void program::luru(){int i;cout〈〈endl<〈endl;cout〈〈"请输入列车的数量:\n”;cin>>j;for(i=1;i<=j;i++){cout〈〈"请输入列车的编号:"<〈endl;cin〉>a[i].no;cout<<endl<〈endl〈〈"出发时间:"<〈endl;cin〉>a[i].starttime;cout〈〈endl〈<endl<<"到达时间:”<<endl;cin〉〉a[i].reachtime;cout〈〈endl〈〈endl〈〈"票价:”〈〈endl;cin〉〉a[i]。
列车车次信息的查询与检索(程序设计报告 C++)

题目:列车车次信息的查询与检索专业学生姓名班级学号指导教师指导单位计算机软件教学中心日期2012年5月21日列车车次信息的查询与检索一、课题内容和要求用C/C++设计,能实现对列车车次的信息情况进行电脑管理,建立一个以文件为存储的管理信息系统;能实现对列车车次的信息进行查询与检索、添加、修改等功能,能对列车车次的情况进行记录和管理。
(1)具有简单的字符界面菜单;(2)可以添加和删除列车车次信息;(3)可以按列车车次的车次号、起点站、到达站、出发时间以及到达时间等信息进行查询;(4)程序中必须有面向对象/结构体的基本概念,比如类、对象/结构体类型的变量等;列车车次记录用一个文件存储,文件类型可以是文本文件或是二进制文件。
二、需求分析列车车次信息的查询与检索系统浏览添加查询修改删除退出1)提供可操作的主菜单:输出个菜单,用于显示若干个可选的功能选项。
根据用户输入的选项来运行不同的功能,运行不同的函数。
一次运行程序能进行多次选择执行不同的功能。
2)进行文本信息的显示:从指定的文件中读取所有的车次信息并显示。
这里文件是在编译时就已经指定好的、存在的文本,需设计者预先自己建立好。
3)添加一个新的车次信息功能:将用户希望添加的车次信息添加到文件末尾。
提示用户按照正确的格式输入。
能录入新数据添加到车次记录文件中,当录入了重复的车次时,则提示数据录入重复并取消录入;录入的新数据能按递增的顺序自动进行条目编号。
4)查找车次信息功能:以用户输入的车次号或者终点站进行查找对应的火车车次信息(通过比对数据进行对应的查找)。
并将此车次中所有数据的信息,如车次、出发时间、起点站、终点站、行驶时间、额定载量等信息输出。
5)进行车次信息的修改:根据用户提供的车次号,找到对应的数据,将内存中的信息重置。
内容应有用户输入,由一系列读写函数实现。
6)删除一个车次信息的功能:根据用户提供的车次号,找到对应的数据,在车次记录中的相应数据进行删除,并自动调整后续条目的编号。
用C写得车票管理系统源码

车票管理系统详细说明:1.程序功能一车站每天有n个发车班次,每个班次都有一班次号(1、2、3、…、n),固定的发车时间,固定的路线(起始站、终点站),大致的行车时间,固定的额定载客量。
如:班次发车时间起点站终点站行车时间额定载量已定票人数1 8:00 重庆昆明 10 45 302 6:30 重庆成都 4 40 403 7:00 重庆成都4 40 204 10:00 重庆成都 4 40 2……现要求设计一个管理系统,能完成如下功能:(1)录入班次信息(信息用文件保存),可不定时地增加班次数据;(2)浏览班次信息,可显示出所有班次当前状况(如果当前系统时间超过了某班次的发车时间,则显示"此班已发出"的提示信息);(3)查询路线:可按班次号查询,也可按终点站查询;(4)售票和退票功能。
①:当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数;②:退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数。
2.设计思想此系统可参照学生成绩管理系统的部份设计方法而设计。
1车票管理系统车票管理系统一车站每天有n个发车班次,每个班次都有一班次号(1、2、3…n),固定的发车时间,固定的路线(起始站、终点站),大致的行车时间,固定的额定载客量。
如班次发车时间起点站终点站行车时间额定载量已定票人数1 8:00 郫县广汉2 45 302 6:30 郫县成都0.5 40 403 7:00 郫县成都0.5 40 204 10:00 郫县成都0.5 40 2…(一)功能要求:用c/c++设计一系统,能提供下列服务:(1)录入班次信息(信息用文件保存),可不定时地增加班次数据(2)浏览班次信息,可显示出所有班次当前状态(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。
(3)查询路线:可按班次号查询,可按终点站查询(4)售票和退票功能A:当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数B:退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数(二)其它要求:(1) 只能使用C/C++语言,源程序要有适当的注释,使程序容易阅读(2) 至少采用文本菜单界面(如果能采用图形菜单界面更好)(3) 学生可自动增加新功能模块******************************************************************* ************************************************/ #include<stdio.h>#include<stdlib.h>#include<dos.h>#include<time.h>#include<conio.h>#include<string.h>const int MAX=20;const int N=50;const int MAXFILENAME=100; enum {FALSE,TRUE};struct time{int hour;int minutes;};struct ticket{int SerialNumber;struct time SetOut;char DeparturePoint[MAX];char TerminalPoint[MAX];float LastTime;int FixNumber;int FixedNumber;}car[N];int RecordNumber;int FLAG=FALSE;/**********************************************/ int ShowMessage(void); //载入原始数据void mainmenu(void); //主菜单void InsertMessage(void); //录入班次信息void SearchMenu(void); //查询路线子菜单void SearchByNumber(void); //按班次号查询void SearchByAddress(void); //按终点站查询void TicketManagement(void); //车票售出与退回void TicketOrder(void); //售票void TicketDelete(void); //退票void exit(void); //退出该系统/********************************************/ int main(void){RecordNumber=ShowMessage();if(1)do{mainmenu();}while(FLAG==FALSE);return 0;}void mainmenu(void){system("color 1f");system("mode con: cols=140 lines=130");char functionNumber;printf(" 车票管理系统\n\n");printf(" 制作:hmm182007\n");printf(" 日期:2007/11/25/19:57\n");printf("=========================================================== =============== ==\n");printf(" 1.录入班次信息\t\n");printf(" 2.浏览班次信息\t\n");printf(" 3.查询行车路线\t\n");printf(" 4.售票与退票系统\t\n");printf(" 5.退出该系统\t\n");printf("=========================================================== =============== ==\n");printf("请选择你所需要的功能:");scanf("%c",&functionNumber);switch(functionNumber){case '1':{InsertMessage();printf("\n按任意键回主菜单......\n"); getchar();getchar();}break;case '2':{ShowMessage();printf("\n按任意键回主菜单......\n"); getchar();getchar();}break;case '3':{SearchMenu();printf("\n按任意键回主菜单......\n"); getchar();getchar();}break;case '4':{TicketManagement();getchar();getchar();}break;case '5':FLAG=TRUE;exit();break;default:{printf("输入错误,请确保你的输入为1--5.\n"); printf("按任意键回主菜单......\n");getchar();getchar();}}//switch endsFLAG=FALSE;}void InsertMessage(void){FILE *fp;char filename[MAXFILENAME];int i;printf("请输入文件名或者文件路径名:");scanf("%s",filename);if((fp=fopen(filename,"r"))==NULL){printf("文件%s不可读,请确认文件%s存在或者文件路径正确.\n\n",filename,filename);mainmenu();}for(i=RecordNumber;!feof(fp)&&!ferror(fp);i++){fscanf(fp,"%d%d%d",&car[i].SerialNumber,&car[i].SetOut.hour,&car[i] .SetOut.minutes);fscanf(fp,"%s%s%f%d%d",&car[i].DeparturePoint,&car[i].TerminalPoint ,&car[i].LastTime,&car[i].FixNumb er,&car[i].FixedNumber);}int count=i;printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");for(i=0;i<count;i++){printf("%d\t%d:%d\t\t",car[i].SerialNumber,car[i].SetOut.hour,car[i ].SetOut.minutes);printf("%s\t%s\t\t%.1f\t%d\t\t%d\n",car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,c ar[i].FixNu mber,car[i].FixedNumber);}fclose(fp);}int ShowMessage(void){int i;FILE *fp;if((fp=fopen("add.txt","r"))==NULL){printf("读取数据失败,请检查文件add.txt是否存在.\n"); exit(-1);}for(i=0;!feof(fp)&&!ferror(fp);i++){。
火车票管理系统——C语言程序设计实训报告

题 目: 学生成绩管理系统院 系: 信息科技学院专 业: 计算机科学与技术姓 名: 何荣荣学 号: 1751200204指导教师: 王小琼日 期: 2018年6月28日桂林电子科技大学信息科技学院前 言课程设计环节是应用型本科院校非常重要的一个教学环节,是学完一门课后应用本课知识及以前的知识积累而进行的综合性、开放性的训练。
通过课程设计,不仅能够使学生得到系统的技能训练,巩固和加强所学得专业理论知识,而且能够培养学生工程意识、创新能力、团队精神等综合素质,培养学生的设计能力和解决实际问题的能力。
C语言由于其强大的功能,丰富的表达能力,高效的代码,良好的移植性和灵活性,自1972年问世以来,经久不衰,即使现在出现了面向对象的程序设计方法和开发工具,但它仍然是人们学习程序设计的首选语言,用它训练和提高编程技术,以及开发应用程序等。
我们通过《C语言程序设计》这门课程的学习,已经能编写解决小问题的程序,对程序的开发也有了初步的认识,还掌握了C 语言的基本语法,这一过程确确实实令我们感到欣喜,有点计算机可以完成自我任务的成就感。
但是,对于程序设计而言,学习C 的步伐不应该停留于此。
我们最终的目的应该是掌握开发大型综合程序的方法,即遵循软件工程的开发步骤和结构化程序设计思想,用C 语言开发出解决复杂问题的大型综合程序。
可是对于多数学生来说,学习了C语言后,除了应付各种考试之外,别无它用,对Turbo C语言丰富的函数知之甚少,加上DOS环境所限,因而对C语言兴趣不大,也感到C语言比较难以掌握。
本实训就是为了让学生在学完C语言后进一步了解C语言的知识,掌握C语言在软件开发方面的使用方法,希望通过此次实训,不仅能提高学生学习C语言的兴趣,更为今后学习其它专业知识及开发程序打下坚实的基础。
本指导书中有些内容借鉴了互联网上相关程序的设计思想,在此对相关者表示衷心的感谢。
由于时间、经验及水平的原因,不当、不足之处,请大家提出宝贵意见。
c语言车票系统报告

struct information *next;
}INFORMATION,*PINF;
void main() /*主函数*/
{
switch(i){ case 1:{
Insert(); printf("\n按任意键回主菜单......\n");getchar();getchar();}break;/*录入*/
case 2:{Scan();printf("\n按任意键回主菜单......\n");getchar();getchar();}break;/*浏览*/
case 3:SearchMenu();break;/*查询*/
case 4:Buyticket();break;/*订票*/
case 5:TicketDelete();break;/*退票*/
p=p->next;
}
fclose(fp);
}
void Scan()
{
PINF p=head->next;
printf("\n各班次信息如下:\n");
printf("\n班次号\t出发时间\t起点\t终点\t行车时间额定载客量已订票人数\n");
printf("____________________________________________________________________________\n");
void Save_In(); //把数据重新保存到文件中
void exit(); //退出该系统
input();
int i=0;
while(i!=6)
C语言 车票管理系统源程序

#include〈stdio。
h〉#include〈time.h> /*时间库函数*/#include<stdlib。
h> /*调用系统函数*/#include〈string。
h> /*串操作及内存操作函数*/ #include〈conio.h〉#include〈math。
h〉#define N 80 /*宏定义多条记录*/void maipiao(int s,int t);/*函数定义*/float times(int k);int hour(int k){switch(k){case 1:return 07;break;case 2:return 10;break;case 3:return 13;break;case 4:return 16;break;case 5:return 19;break;case 6:return 21;break;/*d到闽清一天的发车时间小时段*/ case 7:return 07;break;case 8:return 11;break;case 9:return 15;break;case 10:return 19;break;case 11:return 23;break; /*d到长乐一天的发车时间小时段*/ case 12:return 07;break;case 13:return 11;break;case 14:return 15;break;case 15:return 19;break;case 16:return 23;break;/*d到连江一天的发车时间小时段*/ case 17:return 07;break;case 18:return 11;break;case 19:return 16;break;case 20:return 20;break;/*d到永泰一天的发车时间小时段*/ case 21:return 07;break;case 22:return 12;break;case 23:return 17;break;case 24:return 22;break; /*d到福清一天的发车时间小时段*/ case 25:return 07;break;case 26:return 14;break;case 27:return 19;break;case 28:return 22;break;/*d到罗源一天的发车时间小时段*/ }}/*开车时间段*/ int minute(int k){switch(k){case 1:return 00;break;case 2:return 00;break;case 3:return 00;break;case 4:return 00;break;case 5:return 00;break;case 6:return 00;break;/*d到闽清一天的发车时间分钟段*/ case 7:return 00;break;case 8:return 00;break;case 9:return 00;break;case 10:return 00;break;case 11:return 00;break;/*d到长乐一天的发车时间分钟段*/ case 12:return 00;break;case 13:return 00;break;case 14:return 00;break;case 15:return 00;break;case 16:return 00;break;/*d到连江一天的发车时间分钟段*/ case 17:return 00;break;case 18:return 30;break;case 19:return 00;break;case 20:return 30;break;/*d到永泰一天的发车时间分钟段*/ case 21:return 00;break;case 22:return 30;break;case 23:return 00;break;case 24:return 30;break;/*d到福清一天的发车时间分钟段*/ case 25:return 30;break;case 26:return 00;break;case 27:return 30;break;case 28:return 30;break;/*d到罗源一天的发车时间分钟段*/ }}/*开车时间段*/ void wap(int k){switch(k){case 1:printf("闽清”);break;case 2:printf(”长乐");break;case 3:printf(”连江”);break;case 4:printf(”永泰”);break;case 5:printf(”福清”);break;case 6:printf("罗源");break;}}/*输入终点站的函数*/int shijian(){struct tm *ptr;time_t lt;lt =time(NULL);ptr=gmtime(<);printf(ctime(<));return 0;}/*输出当前时间的函数*/float times(int k){float t;if(k==1)t=1.5;if(k==2)t=3.0;if(k==3||k==4)t=4.0;if(k==5||k==6)t=4.5;return t;}/*输入行车时间的函数*/ int number(int k){int f;if(k==1||k==2)f=30;if(k==3||k==4)f=40;if(k==5||k==6)f=45;return f;}/*输入最大载客量的函数*/ int nownumber(int k,int i){int n=0;char filename[10];switch(i){case 1:strcpy(filename,”qiu1.txt”);break;case 2:strcpy(filename,”qiu2。
C语言火车票管理系统 (1)

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>#include<conio.h>#define N 1000typedefstruct 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(i nt 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();b reak;case 2: Display();b reak;case 3: search();b reak;case 4: add();break;case 5: buyticket();break;case 6: deleteticket();break;case 7: change();b reak;case 8: deletemessage();b reak;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(i nt 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语言编程---火车订票系统源代码

火车订票系统源码#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];/*ID*/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 trainreach: %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("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);}/*保存订票人的信息*/void SaveBookmanInfo(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 ;int sel ;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;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include"stdio.h"#include"stdlib.h"#include"string.h"/*定义头文件,处理文件及字符数组时要用到相应功能*/#define N 10void fmenu(){system("cls");printf("************************欢迎使用苏州列车时刻表信息管理系统v1.20*****************\n");printf("\t\t\t\t %c1. 查询列车\n",3);printf("\n");printf("\t\t\t\t %c2. 修改列车\n",3);printf("\n");printf("\t\t\t\t %c3. 增加列车\n",3);printf("\n");printf("\t\t\t\t %c4. 取消列车\n",3);printf("\n");printf("\t\t\t\t %c5. 保存信息\n",3);printf("\n");printf("\t\t\t\t %c0. 退出\n",3);printf("********************************************************************* ***********\n");printf("请选择要执行的操作:\n");/*菜单程序,用于各种功能的选择*/}struct train/*定义结构体*/{char name[8];char checi[6];int year;int month;int day;int hour;int minute;}lieche[N];/*定义一个结构体数组*/void paixu(struct train *p);/*函数声明*/void chaxun(struct train *p)/*子程序,其功能是查询列车*/{paixu(lieche);/*先排序一下,方便查看*/char a[8];/*定义一个字符数组,输入要查询的列车*/int k=0,i,c;printf("请输入要查询的列车:\n");scanf("%s",a);for(i=0;i<N;i++){if(strcmp(p[i].name,a)==0){printf("苏州—%s\t%s(车次)\t%d年%d月%d日\t%d:%02d\n",p[i].name,p[i].checi,p[i].year,p[i].month,p[i].day,p[i].hour,p[i].minute);/*将所查列车的信息全部打出*/k++;}}if(k==0)printf("抱歉,没有这趟列车\n");/*没有查到时,打出通知*/printf("按1 继续,按0 退出\n");/*选择继续或者退出*/scanf("%d",&c);if(c!=0)chaxun(lieche);}void xiugai(struct train *p)/*子程序,用于修改列车时间*/{char a[8],b[6];int i,x,c,k=0,h,mi,y,m,d,q;printf("请输入要修改的列车:\n");scanf("%s",a);for(i=0;i<N;i++){if(strcmp(p[i].name,a)==0){printf("苏州—%s\t%s()车次\t%d年%d月%d日\t%d:%02d\n",p[i].name,p[i].checi,p[i].year,p[i].month,p[i].day,p[i].hour,p[i].minute);printf("要修改这趟列车吗?\n1.是0.否\n");scanf("%d",&q);if(q==1){printf("请输入修改后的车次:\n");scanf("%s",b);printf("请输入修改后的年月日:\n");scanf("%d%d%d",&y,&m,&d);scanf("%d%d",&h,&mi);printf("确定修改吗?\n1.是2.否\n");/*选择是否确定修改列车时间,防止错误操作*/scanf("%d",&x);if(x==1){strcpy(p[i].checi,b);p[i].year=y;p[i].month=m;p[i].day=d;p[i].hour=h;p[i].minute=mi;printf("已经修改此列车");}}k++;}}if(k==0)printf("抱歉,没有这趟列车\n");/*没有查到时,打出通知*/ printf("按1 继续,按0 退出\n");scanf("%d",&c);if(c!=0)xiugai(lieche);}void zengjia(struct train *p)/*子程序,用于列车增加*/{struct train a;char b[]={"0000000"};/*空白位置,在此处插入所填列车*/int x,c,i;printf("请输入要增加的列车目的地:\n");scanf("%s",);printf("请输入修改后的车次:\n");scanf("%s",a.checi);printf("请输入所增加列车的年月日:\n");scanf("%d%d%d",&a.year,&a.month,&a.day);printf("请输入所增加列车的小时和分钟:\n");scanf("%d%d",&a.hour,&a.minute);printf("确定要增加这一趟列车吗?\n1.是0.否\n");scanf("%d",&x);if(x==1)for(i=0;i<N-1;i++){if(strcmp(p[i].name,b)==0){strcpy(p[i].name,);strcpy(p[i].checi,a.checi);p[i].year=a.year;p[i].month=a.month;p[i].day=a.day;p[i].hour=a.hour;p[i].minute=a.minute;strcpy(p[i+1].name,b);/*找到位置,插入列车,并把0000000给后面一个结构体*/printf("已经增加这趟列车");break;}}paixu(lieche);printf("按1 继续,按0 退出\n");scanf("%d",&c);if(c!=0)zengjia(lieche);}void paixu(struct train *p)/*子程序,用于同名列车时刻排序*/{int i,x;char a[6];for(i=0;i<N;i++){if(strcmp(p[i].name,p[i+1].name)==0)/*先找到相同名字的列车*/{if(p[i].year>p[i+1].year)//根据年份排序{strcpy(a,p[i].checi);strcpy(p[i].checi,p[i+1].checi);strcpy(p[i+1].checi,p[i].checi);x=p[i].year;p[i].year=p[i+1].year;p[i+1].year=x;x=p[i].month;p[i].month=p[i+1].month;p[i+1].month=x;x=p[i].day;p[i].day=p[i+1].day;p[i+1].day=x;x=p[i].hour;p[i].hour=p[i+1].hour;p[i+1].hour=x;x=p[i].minute;p[i].minute=p[i+1].minute;p[i+1].minute=x;}else if(p[i].year==p[i+1].year){if(p[i].month>p[i+1].month)//相同年数,根据月份排序。
{strcpy(a,p[i].checi);strcpy(p[i].checi,p[i+1].checi);strcpy(p[i+1].checi,p[i].checi);x=p[i].month;p[i].month=p[i+1].month;p[i+1].month=x;x=p[i].day;p[i].day=p[i+1].day;p[i+1].day=x;x=p[i].hour;p[i].hour=p[i+1].hour;p[i+1].hour=x;x=p[i].minute;p[i].minute=p[i+1].minute;p[i+1].minute=x;}else if(p[i].month==p[i+1].month){if(p[i].day>p[i+1].day)//相同月份,根据天排序{strcpy(a,p[i].checi);strcpy(p[i].checi,p[i+1].checi);strcpy(p[i+1].checi,p[i].checi);x=p[i].day;p[i].day=p[i+1].day;p[i+1].day=x;x=p[i].hour;p[i].hour=p[i+1].hour;p[i+1].hour=x;x=p[i].minute;p[i].minute=p[i+1].minute;p[i+1].minute=x;}else if(p[i].day==p[i+1].day){if(p[i].hour>p[i+1].hour)//相同天数,根据小时排序{strcpy(a,p[i].checi);strcpy(p[i].checi,p[i+1].checi);strcpy(p[i+1].checi,p[i].checi);x=p[i].hour;p[i].hour=p[i+1].hour;p[i+1].hour=x;x=p[i].minute;p[i].minute=p[i+1].minute;p[i+1].minute=x;}else if(p[i].hour==p[i+1].hour)//相同小时,根据分钟排序{strcpy(a,p[i].checi);strcpy(p[i].checi,p[i+1].checi);strcpy(p[i+1].checi,p[i].checi);x=p[i].minute;p[i].minute=p[i+1].minute;p[i+1].minute=x;}}}}}}}void quxiao(struct train *p)/*子程序,用于取消列车*/{char a[8];char b[]={"0000000"};int i,x,c,k=0,s;printf("请输入要取消的列车\n");scanf("%s",a);for(i=0;i<N;i++){if(strcmp(p[i].name,a)==0){printf("苏州—%s\t%s(车次)\t%d年%d月%d日\t%d:%02d\n",p[i].name,p[i].checi,p[i].year,p[i].month,p[i].day,p[i].hour,p[i].minute);printf("确定要删除这一次列车吗?\n1.是0.否\n");/*询问是否取消*/scanf("%d",&x);if(x==1){for(s=i;s<N-1;s++){strcpy(p[s].name,p[s+1].name);strcpy(p[s].checi,p[s+1].checi);p[s].year=p[s+1].year;p[s].month=p[s+1].month;p[s].day=p[s+1].day;p[s].hour=p[s+1].hour;p[s].minute=p[s+1].minute;/*将列车取消,把后一个结构体往前移一位*/}printf("此列车已取消");}k++;}}if(k==0)printf("抱歉,没有这趟列车\n");/*先查一下有没有要取消的列车*/ printf("按1 继续,按0 退出\n");scanf("%d",&c);if(c!=0)quxiao(lieche);}void baocun(struct train *p)/*子程序,用于数据保存*/{int c,i=0,x;char b[]={"0000000"};printf("确定要保存修改吗?\n1.是2.否\n");scanf("%d",&x);if(x!=0){char a[20];printf("请输入要保存的路径及文件名(扩展名为.txt):\n");/*自己指定位置*/scanf("%s",a);FILE *pps;if((pps=fopen(a,"w+"))==NULL)/*打开一个新的文本文件*/{printf("不能打开此文件\n");exit(0);}while(strcmp(lieche[i].name,b)!=0){fprintf(pps,"%s %s %d %d %d %d:%02d\n",p[i].name,p[i].checi,p[i].year,p[i].month,p[i].day ,p[i].hour,p[i].minute);/*将结构体数组的数据写进里面*/i++;}fprintf(pps,"%s",b);printf("文件已保存\n");}printf("按1 继续,按0 退出\n");scanf("%d",&c);if(c!=0)baocun(lieche);}void main()/*主程序,负责整个程序架构及函数调用等*/{system("color 3b");/*更改前景和背景颜色*/char b[]={"0000000"};FILE *fp;/**/int x,i;if((fp=fopen("d:\\实践\\wenjian.txt","r+"))==NULL)/*打开文件,输入数据*/{printf("不能打开数据库文件\n");exit(0);}for(i=0;i<N;i++)fscanf(fp,"%s%s%d%d%d%d:%02d",lieche[i].name,lieche[i].checi,&lieche[i].year,&lieche[i ].month,&lieche[i].day,&lieche[i].hour,&lieche[i].minute);fmenu();scanf("%d",&x);while (x!=0)/*选择所要操作的功能*/{switch(x){case 1:chaxun(lieche);break;//选择查询功能case 2:xiugai(lieche);break;//选择修改功能case 3:zengjia(lieche);break;//选择增加功能case 4:quxiao(lieche);break;//选择取消功能case 5:baocun(lieche);break;//选择保存功能}fmenu();/*循环调用菜单*/scanf("%d",&x);}}。