|
|
|
@ -9,12 +9,12 @@ int class_num = 0; //
|
|
|
|
|
|
|
|
|
|
typedef struct car
|
|
|
|
|
{
|
|
|
|
|
char number[10]; //车次编号
|
|
|
|
|
char hour[3]; //时间,,小时
|
|
|
|
|
char min[3]; //分钟
|
|
|
|
|
char number[10]; //车次序号
|
|
|
|
|
char hour[3]; //发车时间小时
|
|
|
|
|
char min[3]; //发车时间分钟
|
|
|
|
|
char from[10]; //起始站
|
|
|
|
|
char to[10]; //终点站
|
|
|
|
|
float hours; //车程实际时间
|
|
|
|
|
float hours; //车程时间
|
|
|
|
|
int max; //最大车载容量
|
|
|
|
|
int bought; //已售票数
|
|
|
|
|
} CLASS;
|
|
|
|
@ -97,7 +97,7 @@ void Menu()
|
|
|
|
|
}
|
|
|
|
|
} while (InputNumber != 0);
|
|
|
|
|
}
|
|
|
|
|
void Scanf(int i, int j) // 用户用来输入班次
|
|
|
|
|
void Scanf(int i, int j) //用户用来输入班次
|
|
|
|
|
{
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
@ -134,7 +134,7 @@ void Scanf(int i, int j) //
|
|
|
|
|
}
|
|
|
|
|
void Save() //文件保存函数
|
|
|
|
|
{
|
|
|
|
|
FILE *fp1, *fp2; //文件指针
|
|
|
|
|
FILE *fp1, *fp2;
|
|
|
|
|
if ((fp1 = fopen("sql.txt", "wb")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("车次数据文件不存在\n");
|
|
|
|
@ -173,14 +173,13 @@ void Load() //
|
|
|
|
|
fclose(fp1);
|
|
|
|
|
fclose(fp2);
|
|
|
|
|
}
|
|
|
|
|
int Judge(int i) //判断时间是否超出函数***
|
|
|
|
|
int Judge(int i) //判断时间是否超出
|
|
|
|
|
{
|
|
|
|
|
struct tm *local; //时间结构体
|
|
|
|
|
time_t t; //把当前时间给t
|
|
|
|
|
t = time(NULL); //NULL在stdio.h中定义为0
|
|
|
|
|
local = localtime(&t); /////获取当前系统时间
|
|
|
|
|
local = 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将字符串转换成一个整数值
|
|
|
|
|
//atoi函数将字符串转换成一个整数值
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
@ -191,7 +190,7 @@ int FindCarByNum(char s1[]) //
|
|
|
|
|
ShowTableHead();
|
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(s1, records[i].number) == 0) //判断字符串比较是否相等,如果符合则输出车次等信息
|
|
|
|
|
if (strcmp(s1, records[i].number) == 0) //判断数据文件中的车次号与输入车次号是否相等,如果符合则输出车次信息
|
|
|
|
|
{
|
|
|
|
|
printf("|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour,
|
|
|
|
@ -205,16 +204,16 @@ int FindCarByNum(char s1[]) //
|
|
|
|
|
}
|
|
|
|
|
void Import()
|
|
|
|
|
{
|
|
|
|
|
int i = 0, j = 5, h; ////
|
|
|
|
|
int i = 0, j = 5, h;
|
|
|
|
|
char s[5];
|
|
|
|
|
FILE *fp; ////定义文件型指针变量
|
|
|
|
|
FILE *fp;
|
|
|
|
|
system("cls");
|
|
|
|
|
if ((fp = fopen("num.txt", "rb")) != NULL) //fopen打开文件
|
|
|
|
|
if ((fp = fopen("num.txt", "rb")) != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("车次信息已经存在,请选择添加车次功能!\n");
|
|
|
|
|
printf("按下任意键,返回主菜单\n");
|
|
|
|
|
_getch();
|
|
|
|
|
i = 1; //通过是1
|
|
|
|
|
i = 1;
|
|
|
|
|
}
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
@ -233,7 +232,7 @@ void Import()
|
|
|
|
|
scanf("%s", records[i].number);
|
|
|
|
|
for (h = 0; h < i; h++)
|
|
|
|
|
if (strcmp(records[h].number, records[i].number) == 0)
|
|
|
|
|
//判断字符串比较是否相等,, 待比较的字符串
|
|
|
|
|
//判断字符串是否相等
|
|
|
|
|
{
|
|
|
|
|
printf("输入错误!该班次已存在!\n");
|
|
|
|
|
break; ///返回
|
|
|
|
@ -298,18 +297,18 @@ void Refund()
|
|
|
|
|
Load();
|
|
|
|
|
printf("请输入要退票的班次:\n");
|
|
|
|
|
scanf("%s", num);
|
|
|
|
|
i = FindCarByNum(num); //调用班次查询函数
|
|
|
|
|
if (strcmp(num, records[i].number) == 0) //判断字符串比较是否相等 待比较的字符串
|
|
|
|
|
if (Judge(i)) //判断时间是否超出函数***
|
|
|
|
|
i = FindCarByNum(num); //调用班次查询函数
|
|
|
|
|
if (strcmp(num, records[i].number) == 0)
|
|
|
|
|
if (Judge(i)) //判断时间是否超出当前系统时间
|
|
|
|
|
{
|
|
|
|
|
printf("确定(Y/N)?");
|
|
|
|
|
scanf("%s", num);
|
|
|
|
|
if (num[0] == 'y' || num[0] == 'Y')
|
|
|
|
|
{
|
|
|
|
|
records[i].bought--; //使已售票加1
|
|
|
|
|
records[i].bought--;
|
|
|
|
|
printf("退票成功!\n");
|
|
|
|
|
Save();
|
|
|
|
|
_getch(); //从控制台读取一个字符,但不显示在屏幕上
|
|
|
|
|
_getch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -366,7 +365,6 @@ void Find(char s1[], char s2[])
|
|
|
|
|
m = 0;
|
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
|
if (strcmp(s1, records[i].number) == 0 || strcmp(s2, records[i].to) == 0)
|
|
|
|
|
//判断字符串比较是否相等,, 待比较的字符串
|
|
|
|
|
{
|
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour, records[i].min,
|
|
|
|
@ -419,7 +417,7 @@ void Exploer() //
|
|
|
|
|
for (i = 0, j = 0; i < class_num; i++, j += 2)
|
|
|
|
|
{
|
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
|
if (Judge(i)) //判断时间是否超出函数***
|
|
|
|
|
if (Judge(i))
|
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour,
|
|
|
|
|
records[i].min, records[i].from, records[i].to, records[i].hours,
|
|
|
|
|
records[i].max, records[i].bought);
|
|
|
|
|