-
Notifications
You must be signed in to change notification settings - Fork 0
/
公交查询系统.cpp
224 lines (221 loc) · 6.21 KB
/
公交查询系统.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#define N 1000000
void menu();//菜单
void input();//输入公交车信息
void xiugai();//修改公交车信息
void tianjia();//添加公交车信息
void search();//查询公交车信息
struct bus //用结构体定义公交车信息
{
char xianl[100];//公交线路
char shif[100];//始发站
char zhongd[100];//终点站
char zhongt[100];//中途站点
char time[100];//发车时间
};
struct bus b[N];
int x = 0;//输入的数据总数
int main(void)//主函数
{
int number;
while (1)
{
system("color 3e");
menu();
printf("请选择功能:\n");
scanf("%d", &number);
system("cls");
switch (number)
{
case 1: input(); break;//输入公交车信息
case 2: xiugai(); break;//修改公交车信息
case 3: tianjia(); break;// 添加公交车信息
case 4: search(); break;// 查询公交车信息
case 5: exit(0); break;// 退出系统
}
}
return 0;
}
void menu()//菜单函数
{
printf(" ==============================================\n");
printf(" ==** **==\n");
printf(" == 公交查询系统 ==\n");
printf(" == ==\n");
printf(" == 1.输入公交车信息 ==\n");
printf(" == 2.修改公交车信息 ==\n");
printf(" == 3.添加公交车信息 ==\n");
printf(" == 4.查询公交车信息 ==\n");
printf(" == 5.退出系统 ==\n");
printf(" ==** **==\n");
printf(" ==============================================\n");
}
void input()//输入公交车信息
{
FILE* f1 = NULL;
f1 = fopen("gongjiao.txt", "w");//把信息存入gongjiao.txt文件中
int i;
printf("请输入共有多少组数据:");
scanf("%d", &x);
printf("请输入公交车信息(公交线路,始发站,终点站,中途站点,发车时间):\n");
for (i = 0; i < x; i++)
{
scanf("%s%s%s%s%s", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
fprintf(f1, "%s %s %s %s %s\n", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
}
}
void xiugai()//修改公交车信息
{
int i, n;
char xianl1[100], xianl[100];
char shif1[100], shif[100];
char zhongd1[100], zhongd[100];
char zhongt1[100], zhongt[100];
char time1[100], time[100];
printf("---1按公交线路修改 ---2按始发站修改 ---3按终点站修改 ---4按中途站点修改 ---5按发车时间修改\n");
scanf("%d", &n);
if (n == 1)
{
printf("按公交线路修改\n");
getchar();
printf("请输入公交路线:\n");
scanf("%s", xianl1);
printf("请输入修改的公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
if (strcmp(xianl1, b[i].xianl) == 0)
{
scanf("%s%s%s%s%s", xianl, shif, zhongd, zhongt, time);
strcpy(b[i].xianl, xianl);
strcpy(b[i].shif, shif);
strcpy(b[i].zhongd, zhongd);
strcpy(b[i].zhongt, zhongt);
strcpy(b[i].time, time);
}
}
}
if (n == 2)
{
printf("按始发站修改\n");
getchar();
printf("请输入始发站:\n");
scanf("%s", shif1);
printf("请输入修改的公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
if (strcmp(shif1, b[i].shif) == 0)
{
scanf("%s%s%s%s%s", xianl, shif, zhongd, zhongt, time);
strcpy(b[i].xianl, xianl);
strcpy(b[i].shif, shif);
strcpy(b[i].zhongd, zhongd);
strcpy(b[i].zhongt, zhongt);
strcpy(b[i].time, time);
}
}
}
if (n == 3)
{
printf("按终点站修改\n");
getchar();
printf("请输入终点站:\n");
scanf("%s", zhongd1);
printf("请输入修改的公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
if (strcmp(zhongd1, b[i].zhongd) == 0)
{
scanf("%s%s%s%s%s", xianl, shif, zhongd, zhongt, time);
strcpy(b[i].xianl, xianl);
strcpy(b[i].shif, shif);
strcpy(b[i].zhongd, zhongd);
strcpy(b[i].zhongt, zhongt);
strcpy(b[i].time, time);
}
}
}
if (n == 4)
{
printf("按中途站点修改\n");
getchar();
printf("请输入中途站点:\n");
scanf("%s", zhongt1);
printf("请输入修改的公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
if (strcmp(zhongt1, b[i].zhongt) == 0)
{
scanf("%s%s%s%s%s", xianl, shif, zhongd, zhongt, time);
strcpy(b[i].xianl, xianl);
strcpy(b[i].shif, shif);
strcpy(b[i].zhongd, zhongd);
strcpy(b[i].zhongt, zhongt);
strcpy(b[i].time, time);
}
}
}
if (n == 5)
{
printf("按发车时间修改\n");
getchar();
printf("请发车时间:\n");
scanf("%s", time1);
printf("请输入修改的公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
if (strcmp(time1, b[i].time) == 0)
{
scanf("%s%s%s%s%s", xianl, shif, zhongd, zhongt, time);
strcpy(b[i].xianl, xianl);
strcpy(b[i].shif, shif);
strcpy(b[i].zhongd, zhongd);
strcpy(b[i].zhongt, zhongt);
strcpy(b[i].time, time);
}
}
}
printf("请输出修改后所有公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
printf("%s %s %s %s %s \n", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
}
}
void search()//查询公交车信息
{
int i, n = 0;
char xianl[100];
printf("按公交线路查询\n");
getchar();
printf("请输入公交路线:");
scanf("%s", xianl);
printf("请输出查询到的公交信息:(公交线路,始发站,终点站,中途站点,发车时间) \n");
for (i = 0; i < x; i++)
{
if (strcmp(xianl, b[i].xianl) == 0)
{
printf("%s %s %s %s %s\n", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
}
}
}
void tianjia()//添加公交车信息
{
FILE* f1 = NULL;
f1 = fopen("gongjiao.txt", "w");//把信息存入gongjiao.txt文件中
int i, t;
printf("请输入新加入多少组信息数据:");
scanf("%d", &t);
printf("请输入公交车信息(公交线路,始发站,终点站,中途站点,发车时间):\n");
for (i = x; i < x + t; i++)
{
scanf("%s%s%s%s%s", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
}
printf("输出所有的公交信息\n");
for (i = 0; i < x + t; i++)
{
printf("%s %s %s %s %s \n", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
fprintf(f1, "%s %s %s %s %s\n", b[i].xianl, b[i].shif, b[i].zhongd, b[i].zhongt, b[i].time);
}
}