|
|
|
@ -2,7 +2,7 @@
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h> //时间库函数
|
|
|
|
#include <time.h> //时间库函数
|
|
|
|
|
|
|
|
|
|
|
|
int class_num = 0; //初始班次总数为0
|
|
|
|
int class_num = 0; //初始班次总数为0
|
|
|
|
|
|
|
|
|
|
|
|
@ -44,8 +44,9 @@ void Menu()
|
|
|
|
struct tm *timeinfo;
|
|
|
|
struct tm *timeinfo;
|
|
|
|
time(&rawtime);
|
|
|
|
time(&rawtime);
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
printf(" 系统当前时间:%d:%d\n", timeinfo->tm_hour, timeinfo->tm_min);
|
|
|
|
printf("系统当前时间:%d:%d\n", timeinfo->tm_hour, timeinfo->tm_min);
|
|
|
|
int InputNumber;
|
|
|
|
int InputNumber;
|
|
|
|
|
|
|
|
printf("/* 当前班次信息: */\n");
|
|
|
|
printf("/* 1、购票 */\n");
|
|
|
|
printf("/* 1、购票 */\n");
|
|
|
|
printf("/* 2、退票 */\n");
|
|
|
|
printf("/* 2、退票 */\n");
|
|
|
|
printf("/* 3、查询路线 */\n");
|
|
|
|
printf("/* 3、查询路线 */\n");
|
|
|
|
@ -61,7 +62,7 @@ void Menu()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
printf("输入错误,请输入正确的选项!!\n");
|
|
|
|
printf("请输入正确选项!!\n");
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
Menu();
|
|
|
|
Menu();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -106,7 +107,7 @@ void Scanf(int i, int j) //
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("输入错误!\n");
|
|
|
|
printf("输入错误!\n");
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("请输入起点站:\n");
|
|
|
|
printf("请输入起点站:\n");
|
|
|
|
@ -135,19 +136,15 @@ void Save() //
|
|
|
|
FILE *fp1, *fp2;
|
|
|
|
FILE *fp1, *fp2;
|
|
|
|
if ((fp1 = fopen("sql.txt", "wb")) == NULL)
|
|
|
|
if ((fp1 = fopen("sql.txt", "wb")) == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("车次数据文件不存在,请先录入数据\n");
|
|
|
|
printf("车次数据文件不存在\n");
|
|
|
|
system("pause");
|
|
|
|
exit(0);
|
|
|
|
Menu();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((fp2 = fopen("num.txt", "wb")) == NULL)
|
|
|
|
if ((fp2 = fopen("num.txt", "wb")) == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("车次序号数据文件不存在,请先录入数据\n");
|
|
|
|
printf("车次序号数据文件不存在\n");
|
|
|
|
system("pause");
|
|
|
|
exit(0);
|
|
|
|
Menu();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("数据保存中,请稍后\n");
|
|
|
|
printf("数据保存中,请稍后\n");
|
|
|
|
fp2 = fopen("num.txt", "wb");
|
|
|
|
|
|
|
|
fp1 = fopen("sql.txt", "wb");
|
|
|
|
|
|
|
|
fwrite(&class_num, sizeof(int), 1, fp2); //写入文件信息
|
|
|
|
fwrite(&class_num, sizeof(int), 1, fp2); //写入文件信息
|
|
|
|
fwrite(records, sizeof(CLASS), class_num, fp1);
|
|
|
|
fwrite(records, sizeof(CLASS), class_num, fp1);
|
|
|
|
fclose(fp1);
|
|
|
|
fclose(fp1);
|
|
|
|
@ -156,35 +153,29 @@ void Save() //
|
|
|
|
void Load() //加载数据文件
|
|
|
|
void Load() //加载数据文件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FILE *fp1, *fp2;
|
|
|
|
FILE *fp1, *fp2;
|
|
|
|
if ((fp1 = fopen("sql.txt", "rb")) == NULL)
|
|
|
|
if ((fp1 = fopen("sql.txt", "rb+")) == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
printf("车次数据文件不存在,请先录入数据\n");
|
|
|
|
printf("车次数据文件不存在\n");
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
Menu();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((fp2 = fopen("num.txt", "rb")) == NULL)
|
|
|
|
if ((fp2 = fopen("num.txt", "rb+")) == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
printf("车次序号数据文件不存在,请先录入数据\n");
|
|
|
|
printf("车次序号数据文件不存在\n");
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
Menu();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fp1 = fopen("sql.txt", "rb");
|
|
|
|
|
|
|
|
fp2 = fopen("num.txt", "rb");
|
|
|
|
|
|
|
|
fread(&class_num, sizeof(int), 1, fp2); //读入信息
|
|
|
|
fread(&class_num, sizeof(int), 1, fp2); //读入信息
|
|
|
|
if (sizeof(CLASS) > sizeof(class_num))
|
|
|
|
fread(records, sizeof(CLASS), class_num, fp1); //读入信息
|
|
|
|
{
|
|
|
|
|
|
|
|
fread(records, sizeof(CLASS), class_num, fp1); //读入信息
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp1);
|
|
|
|
fclose(fp1);
|
|
|
|
fclose(fp2);
|
|
|
|
fclose(fp2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int Judge(int i) //判断时间是否超出
|
|
|
|
int Judge(int i) //判断时间是否超出
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct tm *local; //时间结构体
|
|
|
|
struct tm *local; //时间结构体
|
|
|
|
time_t t;
|
|
|
|
time_t t; //把当前时间给t
|
|
|
|
time(&t);
|
|
|
|
|
|
|
|
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))
|
|
|
|
if (local->tm_hour < atoi(records[i].hour) || local->tm_hour == atoi(records[i].hour) && local->tm_min < atoi(records[i].min))
|
|
|
|
//atoi函数将字符串转换成一个整数值
|
|
|
|
//atoi函数将字符串转换成一个整数值
|
|
|
|
@ -202,7 +193,7 @@ int FindCarByNum(char s1[]) //
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
printf("|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour,
|
|
|
|
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);
|
|
|
|
records[i].min, records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
h += 2;
|
|
|
|
h += 2;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -213,6 +204,7 @@ int FindCarByNum(char s1[]) //
|
|
|
|
void Import()
|
|
|
|
void Import()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i = 0, j = 5, h;
|
|
|
|
int i = 0, j = 5, h;
|
|
|
|
|
|
|
|
char s[5];
|
|
|
|
FILE *fp;
|
|
|
|
FILE *fp;
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
if ((fp = fopen("num.txt", "rb")) != NULL)
|
|
|
|
if ((fp = fopen("num.txt", "rb")) != NULL)
|
|
|
|
@ -238,7 +230,7 @@ void Import()
|
|
|
|
scanf("%s", records[i].number);
|
|
|
|
scanf("%s", records[i].number);
|
|
|
|
for (h = 0; h < i; h++)
|
|
|
|
for (h = 0; h < i; h++)
|
|
|
|
if (strcmp(records[h].number, records[i].number) == 0)
|
|
|
|
if (strcmp(records[h].number, records[i].number) == 0)
|
|
|
|
//判断字符串是否相等
|
|
|
|
//判断字符串是否相等
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("输入错误!该班次已存在!\n");
|
|
|
|
printf("输入错误!该班次已存在!\n");
|
|
|
|
break; ///返回
|
|
|
|
break; ///返回
|
|
|
|
@ -271,12 +263,11 @@ void Buy()
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
Query();
|
|
|
|
Query();
|
|
|
|
printf("请输入要订票的班次(若无请输入0):\n");
|
|
|
|
printf("请输入要订票的班次(若无请输入0):\n");
|
|
|
|
num[0] = '\0';
|
|
|
|
|
|
|
|
scanf("%s", num);
|
|
|
|
scanf("%s", num);
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
if (strcmp(num, records[i].number) == 0)
|
|
|
|
if (strcmp(num, records[i].number) == 0)
|
|
|
|
if (records[i].max > records[i].bought && Judge(i) == 1)
|
|
|
|
if (records[i].max > records[i].bought && Judge(i) == 1)
|
|
|
|
//判断时间是否超出当前系统时间并且已售车票没超出最大客量
|
|
|
|
//判断时间是否超出当前系统时间并且已售车票没超出最大客量
|
|
|
|
{
|
|
|
|
{
|
|
|
|
records[i].bought++;
|
|
|
|
records[i].bought++;
|
|
|
|
printf("通向%s班次为%s的票订票成功!\n", records[i].to, records[i].number);
|
|
|
|
printf("通向%s班次为%s的票订票成功!\n", records[i].to, records[i].number);
|
|
|
|
@ -335,7 +326,7 @@ void Refund()
|
|
|
|
void Query()
|
|
|
|
void Query()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
char s1[10] = { '\0' }, s2[10] = { '\0' };
|
|
|
|
char s1[10] = {'\0'}, s2[10] = {'\0'};
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
printf("1. 按班次查询\n");
|
|
|
|
printf("1. 按班次查询\n");
|
|
|
|
printf("2. 按终点站查询\n");
|
|
|
|
printf("2. 按终点站查询\n");
|
|
|
|
@ -376,7 +367,7 @@ void Find(char s1[], char s2[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour, records[i].min,
|
|
|
|
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);
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
h += 2;
|
|
|
|
h += 2;
|
|
|
|
if (m == 1)
|
|
|
|
if (m == 1)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -401,7 +392,7 @@ void Insert()
|
|
|
|
scanf("%s", records[class_num].number);
|
|
|
|
scanf("%s", records[class_num].number);
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
if (strcmp(records[class_num].number, records[i].number) == 0)
|
|
|
|
if (strcmp(records[class_num].number, records[i].number) == 0)
|
|
|
|
//判断车次是否重复
|
|
|
|
//判断车次是否重复
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("输出车次已存在!\n");
|
|
|
|
printf("输出车次已存在!\n");
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
@ -427,11 +418,11 @@ void Exploer() //
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
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,
|
|
|
|
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].min, records[i].from, records[i].to, records[i].hours,
|
|
|
|
records[i].max, records[i].bought);
|
|
|
|
records[i].max, records[i].bought);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
printf("|%10s| 已发车 |%10s|%10s|%8.1f|%8d|%8d|", records[i].number,
|
|
|
|
printf("|%10s| 已发车 |%10s|%10s|%8.1f|%8d|%8d|", records[i].number,
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ShowTableFoot();
|
|
|
|
ShowTableFoot();
|
|
|
|
printf("\n");
|
|
|
|
printf("\n");
|
|
|
|
|