




已阅读5页,还剩54页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/*-城市公交查询系统-*作者:胡辉衡 *学校:长沙学院 *功能:实现城市公交查询的基本功能 *实现技术:C语言及数据结构 *指导老师:钟旭 *完成时间 :2015年12月21日 -*/ #include #include#include #include#includestruct user/记录账号信息 int identity;/用户身份,值等于false时为普通用户,否则为管理员int userId;/用户编号char loginName40;/用户登录名char loginPassword20;/登录密码 struct user *next;/指向下一个用户信息的指针,便于建立链表 ;struct city/记录城市信息 int cityId;/城市编号 char cityName20;/城市名 struct city *next;/指向下一个城市信息的指针,便于建立链表 ;struct station /记录车站信息 int stationId;/车站编号char stationName20;/车站名称int cityId;/所属城市编号 struct station *next;/指向下一个站点信息的指针,便于建立链表 ;struct road /记录公交线路信息 int roadId;/公交线路编号char roadName20;/公交线路名称int cityId;/所属城市编号struct road *next;/指向下一个公交线路信息的指针,便于建立链表 ;struct relation/记录车站与公交线路之间的关系和站与站之间的信息 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(tt你的身份:);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);elsewhile(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;elsep = 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 stationName20;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(nn本城市已有的公交站点:n);/将本城市已有的公交站点全部显示出来 while(p != NULL)/printf(a);if(p-cityId = g_cityId)printf(%st,p-stationName);if(i%5 = 0)printf(n);i+; p = p-next; /*if(p = NULL)printf(nn本城市暂时还没有添加任何公交站点!n);elseprintf(nn本城市已有的公交站点:n);while(p != NULL)/printf(a);printf(t%s,p-stationName);if(i%5 = 0)printf(n);i+;p = p-next; */printf(nnn请输入你想要增加的公交站点名(输入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) 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);elseprintf(文件city打开失败!);system(pause);return;elseprintf(nnnnntt文件station.txt打开失败!nnn);system(pause);return;/system(pause); void SiteChange()system(cls);printf(-站点修改界面-);FILE *fp;int i = 1;bool mark = false;int stationId,cityId;char stationName20;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(nn本城市已有的公交站点:n);/将本城市已有的公交站点全部显示出来 while(p != NULL)/printf(a);if(p-cityId = g_cityId)printf(%st,p-stationName);if(i%5 = 0)printf(n);i+; p = p-next; printf(nnn请输入你想要修改的公交站点名(输入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) 20 | strlen(stationName) stationName,stationName);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);elseprintf(文件city打开失败!);system(pause);return;elseprintf(nnnnntt文件station.txt打开失败!nnn);system(pause);return;/system(pause);void SiteDeleteDeal(int stationId) /站点删除处理函数/printf(n所有经过该站点的公交线路都将跳过该站点!n);/printf(%dn,stationId);FILE *fp,*fp2;int sep;struct relation *head,*p,*q;struct road *head2,*p2,*q2;fp = fopen(relation.txt,r);if(fp)head = (struct relation*)malloc(sizeof(struct relation);head-next = NULL;head2 = (struct road*)malloc(sizeof(struct road);head2-next = NULL;while(!feof(fp)p = (struct relation*)malloc(sizeof(struct relation);p-next = NULL;fscanf(fp, %d %d %d %d %d %d,&p-stationId,&p-roadId,&p-sep,&p-distance,&p-time,&p-cityId);if(p-stationId = stationId)p2 = (struct road*)malloc(sizeof(struct road);p2-next = NULL;p2-roadId = p-roadId;printf( %d ,p-roadId);strcpy(p2-roadName,);p2-next = head2-next;head2-next = p2;p-next = head-next;head-next = p;fclose(fp);p2 = head2-next;while(p2 != NULL)p = head-next;while(p != NULL)if(p-roadId = p2-roadId & p-stationId = stationId)sep = p-sep;/printf( %d n,sep);break;p = p-next;p = head-next;while(p != NULL)if(p-roadId = p2-roadId & p-sep sep)/printf(%d,p-sep);p-sep-;p = p-next;p2 = p2-next;q = head;p = head-next;while(p != NULL)if(p-stationId = stationId)q-next = q-next-next;free(p);p = q;q = p;p = p-next; fp2 = fopen(relation.txt,w);if(fp2)p = head-next;while(p != NULL)fprintf(fp, %d %d %d %d %d %d,p-stationId,p-roadId,p-sep,p-distance,p-time,p-cityId);p = p-next;fclose(fp2);elseprintf(nnnnntt文件station.txt打开失败!nnn);system(pause);return;p = head-next;while(p != NULL)head-next = head-next-next;free(p);p = head-next;free(head);p2 = head2-next;while(p2 != NULL)head2-next = head2-next-next;free(p2);p2 = head2-next;free(head2);elseprintf(nnnnntt文件station.txt打开失败!nnn);system(pause);return;/system(pause);void SiteDelete()system(cls);printf(-站点删除界面-);FILE *fp;int i = 1;char option;bool mark = false;int stationId,cityId;char stationName20;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(nn本城市已有的公交站点:n);/将本城市已有的公交站点全部显示出来 while(p != NULL)/printf(a);if(p-cityId = g_cityId)printf(%st,p-stationName);if(i%5 = 0)printf(n);i+; p = p-next; printf(nnn请输入你想要删除的公交站点名(输入0表示返回):);/对输入的公交站名做正确性验证 while(1)fflush(stdin);gets(stationName);if(!strcmp(stationName,0)/把输入0作为模块出口 return;q = head;p = head-next;mark = false;while(p != NULL)if(!strcmp(p-stationName,stationName) & p-cityId = g_cityId)mark = true;/表示公交站点已存在,可以删除 break;q = p;p = p-next;if(mark)break; else if(strlen(stationName) 20 | strlen(stationName) stationName);LineShow(p-stationId);printf(n删除该站后经过该站的公交线路都会跳过该站!);printf(n是否确定删除%s站(1.是 2.否):,p-stationName);while(1)fflush(stdin);option = getch();if(option = 49 | option = 50)break;elseprintf(n输入错误!请重新输入:);stationId = p-stationId;switch(option)case 49:SiteDeleteDeal(stationId);break;default:return;/printf(xx);q-next = q-next-next;free(p);/printf(yy);elsep = head-next;while(p != NULL)/更新公交站点文件信息 head-next = head-next-next;free(p);/释放链表结点,节省内存 p = head-next;free(head);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);system(cls);printf(nnnnn%s站删除成功!nnnn,stationName);system(pause);elseprintf(文件city打开失败!);system(pause);return;elseprintf(nnnnntt文件station.txt打开失败!nnn);system(pause);return;/system(pause);void ChangeCity()system(cls);printf(n-切换城市页面-nnnnn);FILE *fp;struct city *head,*p;int i = 0;char cityName20 = 长沙; bool mark = false;/记录输入的城市是否已收录 head = (struct city*)malloc(sizeof(struct city);/建立存放城市信息的链表 head-next = NULL;fp = fopen(city.txt,r);if(fp)printf(已收录的城市:n);/将文件中的数据读取到链表中 while(!feof(fp)p = (struct city*)malloc(sizeof(struct city);p-next = NULL;fscanf(fp, %d %s,&p-cityId,p-cityName);printf(t%s,p-cityName);i+;if(i%5 = 0)printf(n);p-next = head-next;head-next = p;printf(n请输入你想要切换到的城市(输入0表示返回):);/对输入的城市名做验证 while(1)fflush(stdin);gets(cityName);if(!strcmp(cityName,0)break;p = head-next;mark = false;while(p != NULL)if(!strcmp(p-cityName,cityName)mark = true;break;p = p-next;if(mark)break;else if(strlen(cityName) 20 | strlen(cityName) cityId;/将记录当前城市的全局变量更改为要切换的城市 p = head-next;/将无用的链表进行释放 while(p != NULL)fprintf(fp, %d %s,p-cityId,p-cityName);head-next = head-next-next;free(p);/释放链表结点,节省内存 p = head-next;free(head);fclose(fp);elseprintf(文件city打开失败!);system(pause);return;/system(pause); void AddCity()system(cls);printf(n-增加城市页面-nnnnn);FILE *fp;struct city *head,*p;int i = 0;char cityName20 = 长沙;/char a5 = 0; bool mark = false;/用于标记城市名是否存在 head = (struct city*)malloc(sizeof(struct city);/建立存放城市信息的链表 head-next = NULL;fp = fopen(city.txt,r);if(fp)printf(已收录的城市:n);while(!feof(fp)p = (struct city*)malloc(sizeof(struct city);p-next = NULL;fscanf(fp, %d %s,&p-cityId,p-cityName);/将文件中的信息取出放到链表中,便于操作 printf(t%s,p-cityName);i+;if(i%5 = 0)printf(n);p-next = head-next;head-next = p;printf(nnn请输入你想要增加的城市名(输入0表示返回):);/对输入的城市名做正确性验证 while(1)fflush(stdin);gets(cityName);if(!strcmp(cityName,0)/把输入0作为模块出口 break;p = head-next;mark = false;while(p != NULL)if(!strcmp(p-cityName,cityName)mark = true;/表示城市已收录,不需要再添加 break;p = p-next;if(mark)printf(此城市已存在!请重新输入城市名(输入0表示返回):);else if(strlen(cityName) 20 | strlen(cityName) next = NULL;p-cityId = i;g_cityId = i;strcpy(p-cityName,cityName);p-next = head-next;head-next = p;fclose(fp);fp = fopen(city.txt,w);if(fp)p = head-next;while(p != NULL)/更新城市文件信息 /printf(b);fprintf(fp, %d %s,p-cityId,p-cityName);hea
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年整形美容科隆胸手术操作规范考核答案及解析
- 2025年心脏病学常见心律失常鉴别诊断模拟测试卷答案及解析
- 工程力学 课件 空间力系
- 2025年肿瘤内科多学科协作病例分析答案及解析
- 2025年神经病学帕金森病诊断标准模拟考试试卷答案及解析
- 2025年消化科学科肝硬化腹水引流术后护理注意事项模拟测验答案及解析
- 2025年内科病人护理技能考核试卷答案及解析
- 民族团结知识宣传课件
- 2025年影像学影像诊断解读技能考核试卷答案及解析
- 2025年遗传病学基因诊断技术考核测试卷答案及解析
- GA/T 1471-2018居民身份证制作中心(所)建设规范
- 小学特色作业经验汇报课件
- 粘膜免疫 2课件
- 统计业务知识(统计法规)课件
- 艾滋病个案流行病学调查表
- 广告策划与创意课件-2
- 地质勘察任务书模板
- 全国中心血站上岗证考试题库
- 新湘科版科学五年级上册全册课件(精品PPT)
- 环境社会学整本书课件完整版电子教案全套课件最全教学教程ppt(最新)
- 人教A版必修第二册8.6.2直线与平面垂直的性质 课件(共25张PPT)
评论
0/150
提交评论