#include
#include
#include
#include
#include
struct user
{
int identity;
否则为管理员
int userId;
char loginName[40];
char loginPassword[20];
struct user *next;
链表
};
struct city{
int cityId;
char cityName[20];
struct city *next;
链表
};
struct station
{
int stationId;
char stationName[20];
int cityId;
struct station *next;
链表
};
struct road
{
int roadId;
char roadName[20];
int cityId;
struct road *next;
建立链表
};
struct relation{
//记录账号信息
//用户身份,值等于 false 时为普通用户,
//用户编号
//用户登录名
//登录密码
//指向下一个用户信息的指针,便于建立
//记录城市信息
//城市编号
//城市名
//指向下一个城市信息的指针,便于建立
//记录车站信息
//车站编号
//车站名称
//所属城市编号
//指向下一个站点信息的指针,便于建立
//记录公交线路信息
//公交线路编号
//公交线路名称
//所属城市编号
//指向下一个公交线路信息的指针,便于
//记录车站与公交线路之间的关系和站
与站之间的信息
int stationId;
int roadId;
int sep;
int distance;
距离(单位:km)
int time;
需要的时间(单位:min)
int cityId;
struct relation *next;
针,便于建立链表
};
//车站编号
//公交线路编号
//车站在此公交线路的序号
//在此公交线路下这个车站到下一站的
//在此公交线路下这个车站到下一站所
//所属城市编号
//指向下一个站点与线路映射信息的指
int g_cityId = 0;
//记录当前城市编号的全局变量
int MainInterface();
struct user *Login();
struct user *Register();
struct user*FindPassword();
void initialize();
int UserInterface(struct user* p);
int AdminInterface(struct user* p);
struct user*Logout(struct user* p);
void LineManage();
void SiteManage();
void LineQuery();
void SiteQuery();
void SiteToSiteQuery();
struct user*ChangePassword(struct user* p);
void Inputpw(char *password,int len);
void ChangeCity();
void AddCity();
void SiteAdd();
void SiteChange();
void SiteDelete();
void SiteDeleteDeal(int stationId);
void LineAdd();
void LineChange();
void LineDelete();
void LineInsertSite(int roadId);
void LineDeleteSite(int roadId);
void LineShow(int roadId);
void SiteShow(int stationId);
void ShowAllWay(int start,int end);
//主界面
//登录函数
//注册函数
//找回密码
//初始化
//用户界面
//管理员界面
//注销函数
//线路管理函数
//站点管理函数
//线路查询函数
//站点查询函数
//站站查询函数
//修改密码函数
//密码掩盖函数
//切换城市
//增加城市
//站点增加函数
//站点修改函数
//站点删除函数
//站点删除处理函数
//线路增加函数
//线路修改函数
//线路删除函数
//插入站点形成公交线路
//删除公交线路上所有的站点
//显示公交线路上所有的公交站点
//显示经过公交站点所有的公交线路
//显示从起点到终点两次换乘及以下的
所有乘车方式
void graphFound();
成一张图
void showRoadName(int roadId);
void showStationName(int stationId);
int main(){
struct user *p;
int option;
initialize();
while(1){
//将当前城市所有的公交线路和站点构
//根据线路编号显示公交线路名
//根据站点编号显示公交站点名
system("cls");
option = MainInterface();
switch(option){
case 49:p = Login();break;
case 50:p = Register();break;
case 51:p = FindPassword();break;
default:exit(-1);
}
//printf("a");
if(p == NULL){
continue;
}else{
//printf("\t\t 你的身份:");
if(p->identity){
while(p){
b:option = AdminInterface(p);
switch(option){
//避免函数调用函数导致内存爆炸
case 49:LineManage();break;
case 50:SiteManage();break;
case 51:ChangeCity();break;
case 52:AddCity();break;
case 53:goto a;/*UserInterface(p)*/;break;
case 54:p = Logout(p);break;
default:exit(-1);
}
}
}else{
while(p){
//避免函数调用函数导致内存爆炸
a:option = UserInterface(p);
switch(option){
case 49:LineQuery();break;
case 50:SiteQuery();break;
case 51:SiteToSiteQuery();break;
case 52:ChangeCity();break;
case 53:p = ChangePassword(p);break;
case 54:
if(p->identity){
goto b;
}else{
p = Logout(p);break;
}
default:exit(-1);
}
}
}
}
//system("pause");
}
return 0;
}
void SiteAdd(){
system("cls");
printf("--------------------------站点增加界面-------------------------");
FILE *fp;
int i = 1;
bool mark = false;
int stationId,cityId;
int stationIdMark = 0;
char stationName[20];
struct station *head,*p,*q;
head = (struct station*)malloc(sizeof(struct station));
head->next = NULL;
fp = fopen("station.txt","r");
if(fp){
//记录新建公交站点的编号(应大于所有已有的公交站点)
while(!feof(fp)){
//产生链表
p = (struct station*)malloc(sizeof(struct station));
p->next = NULL;
fscanf(fp," %d %s %d",&p->stationId,p->stationName,&p->cityId);
if(p->stationId > stationIdMark){
stationIdMark = p->stationId;
}
p->next = head->next;
head->next = p;
//printf(" %d %s %d",stationId,stationName,cityId);
/*if(cityId == g_cityId){
p->cityId = cityId;
p->stationId = stationId;
strcpy(p->stationName,stationName);
p->next = head->next;
head->next = p;
}*/
}
p = head->next;
printf("\n\n 本城市已有的公交站点:\n");
//将本城市已有的公交站点全部显示出来
while(p != NULL){
//printf("a");
if(p->cityId == g_cityId){
printf("%s\t",p->stationName);
if(i%5 == 0){
printf("\n");
}
i++;
}
p = p->next;
}
/*if(p == NULL){
printf("\n\n 本城市暂时还没有添加任何公交站点!\n");
}else{
printf("\n\n 本城市已有的公交站点:\n");
while(p != NULL){
//printf("a");
printf("\t%s",p->stationName);
if(i%5 == 0){
printf("\n");
i++;
}
p = p->next;
}
} */
printf("\n\n\n 请输入你想要增加的公交站点名(输入 0 表示返回):");
//对输入的公交站名做正确性验证
while(1){
fflush(stdin);
gets(stationName);
if(!strcmp(stationName,"0")){
入 0 作为模块出口
break;
// 把 输
}
p = head->next;
mark = false;
while(p != NULL){
if(!strcmp(p->stationName,stationName) && p->cityId == g_cityId){
公交站点已存在,不需要再添加
mark = true;
// 表 示
break;
}
p = p->next;
}
if(mark){
printf("此公交站点已存在!请重新输入公交站点名(输入 0 表示返回):");
}else if(strlen(stationName) > 20 || strlen(stationName) < 4){
printf("公交站点名长度不符合要求!请重新输入公交站点名(输入 0 表示
返回):");
}else{
break;
}
}
//将新建的公交站点结点插入到链表中
if(strcmp(stationName,"0")){
p = (struct station*)malloc(sizeof(struct station));
p->next = NULL;
stationIdMark++;
p->stationId = stationIdMark;
p->cityId = g_cityId;
strcpy(p->stationName,stationName);
p->next = head->next;
head->next = p;
}
fclose(fp);
fp = fopen("station.txt","w");
if(fp){
p = head->next;
while(p != NULL){
站点文件信息
//printf("b");
fprintf(fp," %d %s %d",p->stationId,p->stationName,p->cityId);
head->next = head->next->next;
free(p);
p = head->next;
//释放链表结点,节省内存
}
free(head);
// 更 新 公 交
fclose(fp);
}else{
printf("文件'city'打开失败!");
system("pause");
return;
}
}else{
printf("\n\n\n\n\n\t\t 文件'station.txt'打开失败!\n\n\n");
system("pause");
return;
}
//system("pause");
}
void SiteChange(){
system("cls");
printf("--------------------------站点修改界面-------------------------");
FILE *fp;
int i = 1;
bool mark = false;
int stationId,cityId;
char stationName[20];
struct station *head,*p,*q;
head = (struct station*)malloc(sizeof(struct station));
head->next = NULL;
fp = fopen("station.txt","r");
if(fp){
while(!feof(fp)){
//产生链表
p = (struct station*)malloc(sizeof(struct station));
p->next = NULL;
fscanf(fp," %d %s %d",&p->stationId,p->stationName,&p->cityId);
p->next = head->next;
head->next = p;
}
p = head->next;
printf("\n\n 本城市已有的公交站点:\n");
//将本城市已有的公交站点全部显示出来
while(p != NULL){
//printf("a");
if(p->cityId == g_cityId){
printf("%s\t",p->stationName);
if(i%5 == 0){
printf("\n");
}
i++;
}
p = p->next;
}
printf("\n\n\n 请输入你想要修改的公交站点名(输入 0 表示返回):");
//对输入的公交站名做正确性验证
while(1){
fflush(stdin);
gets(stationName);
if(!strcmp(stationName,"0")){
入 0 作为模块出口
break;
}
p = head->next;
mark = false;
while(p != NULL){
if(!strcmp(p->stationName,stationName) && p->cityId == g_cityId){
mark = true;
公交站点已存在,可以修改
break;
}
p = p->next;
}
if(mark){
break;
// 把 输
// 表 示
}else if(strlen(stationName) > 20 || strlen(stationName) < 4){
printf("公交站点名长度不符合要求!请重新输入公交站点名(输入 0 表示
返回):");
}else{
printf("此公交站点不存在!请重新输入公交站点名(输入 0 表示返回):");
}
}
if(strcmp(stationName,"0")){
printf("请输入新的公交站点名:");
while(1){
fflush(stdin);
gets(stationName);
if(strlen(stationName) > 20 || strlen(stationName) < 4){
printf("公交站点名长度不符合要求!请重新输入新的公交站点名:");
}else{
break;
}