c语言程序运行不了但是没有报错
(1)程序改成录入班次信息(信息用文件保存),可不定时地增加班次数据
(2)浏览班次信息,可显示出所有班次当前状总(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。
(3)查询路线:可按班次号查询 ,可按终点站查询
(4)售票和退票功能
#include<stdio.h>
#include<string.h>
#include <string.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
void show();
void showone();
void function1();
void function2();
void function3();
void function4();
struct Huoche
{
const char* TrainNumber; //车次
double StartTime; //开车时间
const char* StartingStation; //起点站
const char* EndingStation; //终点站
};
struct Huoche Huo[100] = { {"一 ", 8.00 , "郫县" , "广汉"},
{"二" , 6.30 , "郫县" , "成都"},
{"三" , 7.00 , "郫县" , "成都"},
{"四" , 10.00 , "郫县" , "成都"}
};
struct chenke
{
float ArriveTime[20]; //到达时间
float erding; //额定乘客
float yiding; //已定乘客
};
struct chenke ke[100] = { 2,45,30,0.5,40,40,0.5,40,20,0.5,40,2 };
int i, n;
void main()
{
do
{
printf("************************************\n");
printf("** 欢迎使用火车票管理系统 **\n");
printf("* 1.添加车次信息 *\n");
printf("* 2.查询车次信息 *\n");
printf("* 3.统计火车车次 *\n");
printf("* 4.浏览火车时刻 *\n");
printf("* 0.退出 *\n");
printf("************************************\n");
int a;
printf("请输入执行操作代码:");
scanf_s("%d", &a);
switch (a)
{
case 1:function1();break;
case 2:function2();break;
case 3:function3();break;
case 4:function4();break;
case 0:printf("程序结束!!!!!\n");exit(-1);
}
} while (1);
}
//循环显示
void show()
{
for (int i = 0;i < 10;i++)
printf("%s\t\t%s\t\t%s\t\t%s\t\t%f\t\t%f\t\t%f\n", Huo[i].TrainNumber, Huo[i].StartTime, Huo[i].StartingStation, Huo[i].EndingStation, ke[i].ArriveTime, ke[i].erding, ke[i].yiding);
printf("\n\n");
}
//显示匹配项
void showone()
{
printf("%s\t\t%s\t\t%s\t\t%s\t\t%f\t\t%f\t\t%f\n", Huo[i].TrainNumber, Huo[i].StartTime, Huo[i].StartingStation, Huo[i].EndingStation, ke[i].ArriveTime, ke[i].erding, ke[i].yiding);
printf("\n\n");
}
void function1() {
printf("请输入录入个数:");
scanf_s("%d", &n);
printf("请输入:\n");
printf("车次\t发车时间\t起点\t终点\t行车时间\t额定乘客\t已定乘客\n");
for (i = 0;i < n;i++)
scanf_s("%s%s%s%s%f%f%f", &Huo[i].TrainNumber, &Huo[i].StartTime, &Huo[i].StartingStation, &Huo[i].EndingStation, &ke[i].ArriveTime, &ke[i].erding, &ke[i].yiding);
printf("!!!!!录入完成!!!!!\n\n");
}
void function2() {
printf("1——按照车次查询\n");
printf("2——按照起点和终点查询\n");
int a;
printf("请输入执行操作代码:");
scanf_s("%d", &a);
switch (a)
{
case 1:
{
char checi[20];
printf("请输入所要查询的车次:");
scanf_s("%s", checi);
/* cin>>checi;*/
printf("车次\t\t发车时间\t\t起点\t\t终点\t\t行车时间\t\t额定乘客\t\t已定乘客\n");
for (i = 0;i < n;i++)
{
if (strcmp(checi, Huo[i].TrainNumber) == 1)
showone();
}
}
break;
case 2:
{
char qidian[20], zhongdian[20];
printf("请输入起点:");
scanf_s("%s", &qidian);
printf("请输入终点:");
scanf_s("%s", &zhongdian);
printf("车次\t\t发车时间\t\t起点\t\t终点\t\t行车时间\t\t额定乘客\t\t已定乘客\n");
for (i = 0;i < n;i++)
{
if (strcmp(qidian, Huo[i].StartingStation) == 0 && strcmp(zhongdian, Huo[i].EndingStation) == 0)
{
showone();
}
}
}
break;
}
};
void function3() {
printf("1——按起点统计\n");
printf("2——按终点统计\n");
int a;
printf("请输入执行操作代码:");
scanf_s("%d", &a);
switch (a)
{
case 1:
{
char qidian1[20];
printf("请输入起点:");
scanf_s("%s", &qidian1);
printf("车次\t\t发车时间\t\t起点\t\t终点\t\t行车时间\t\t额定乘客\t\t已定乘客\n");
for (i = 0;i < n;i++)
{
if (strcmp(qidian1, Huo[i].StartingStation) == 0)
{
showone();
}
}
}
break;
case 2:
{
char zhongdian1[20];
printf("请输入终点:");
scanf_s("%s", &zhongdian1);
printf("车次\t\t发车时间\t\t起点\t\t终点\t\t行车时间\t\t额定乘客\t\t已定乘客\n");
for (i = 0;i < n;i++)
{
if (strcmp(zhongdian1, Huo[i].EndingStation) == 0)
{
showone();
}
}
}
break;
}
};
void function4() {
for (i = 0;i < n - 1;i++)
{
for (int j = 0;j < n - 1 - i;j++)
if (Huo[j].StartTime > Huo[j + 1].StartTime)
{
Huoche t = Huo[j];
Huo[j] = Huo[j + 1];
Huo[j + 1] = t;
}
}
printf("车次\t\t发车时间\t\t起点\t\t终点\t\t行车时间\t\t额定乘客\t\t已定乘客\n");
show();
};