#include<stdio.h>#include<string.h>#include<stdlib.h>#include <conio.h>#define N 100 struct subway//定义一个结构体 { char num[N]; char line[N];//地铁线路 char sstation[N];//起始站 char ostation[N];//终点站 char wstation[N];//途径站数 char charge[N];//票价 }sub[N];//给结构体起别名sub; int k=1,n,m; char readfile();//文件读取 void save();//将信息保存至文件 void insert();//增加地铁信息 void Delete();//删除地铁信息 void Search();//查询地铁信息 void Print();//浏览地铁信息 void Update();//更新地铁信息 void menu();//主菜单调用其他函数 int main(){ while(k) menu(); system("pause"); return 0;} char readfile(){ FILE *fp;//要读取的文件指针 int i=0;//数组移动 if ((fp=fopen("subway.txt","r"))==NULL)//打开操作不成功 { printf("Open file is error!"); system("pause"); exit(0); }

时间: 2024-01-04 16:03:19 浏览: 31
//文件打开成功 while(!feof(fp)){//feof函数判断是否到达文件末尾 fscanf(fp,"%s",sub[i].num);//读取地铁编号 fscanf(fp,"%s",sub[i].line);//读取地铁线路 fscanf(fp,"%s",sub[i].sstation);//读取起始站 fscanf(fp,"%s",sub[i].ostation);//读取终点站 fscanf(fp,"%s",sub[i].wstation);//读取途径站数 fscanf(fp,"%s",sub[i].charge);//读取票价 i++; } fclose(fp);//关闭文件 return 'r';//返回'r'表示读取成功 } void save(){ FILE *fp;//要写入的文件指针 int i; if ((fp=fopen("subway.txt","w"))==NULL)//打开操作不成功 { printf("Open file is error!"); system("pause"); exit(0); } for(i=0;i<n;i++){ fprintf(fp,"%s %s %s %s %s %s\n",sub[i].num,sub[i].line,sub[i].sstation,sub[i].ostation,sub[i].wstation,sub[i].charge);//将信息写入文件中 } fclose(fp);//关闭文件 printf("Save successfully!\n"); } void insert(){ printf("Please input the number of subway:"); scanf("%s",sub[n].num); printf("Please input the line of subway:"); scanf("%s",sub[n].line); printf("Please input the start station of subway:"); scanf("%s",sub[n].sstation); printf("Please input the end station of subway:"); scanf("%s",sub[n].ostation); printf("Please input the passing stations of subway:"); scanf("%s",sub[n].wstation); printf("Please input the charge of subway:"); scanf("%s",sub[n].charge); n++;//增加地铁信息数量 printf("Insert successfully!\n"); } void Delete(){ int i,j; char num[N];//要删除的地铁编号 printf("Please input the number of subway you want to delete:"); scanf("%s",num); for(i=0;i<n;i++){ if(strcmp(num,sub[i].num)==0){//查找到要删除的地铁信息 for(j=i;j<n-1;j++){ sub[j]=sub[j+1];//将后面的信息前移 } n--;//减少地铁信息数量 printf("Delete successfully!\n"); return; } } printf("Can't find the subway information!\n"); } void Search(){ int i; char num[N];//要查询的地铁编号 printf("Please input the number of subway you want to search:"); scanf("%s",num); for(i=0;i<n;i++){ if(strcmp(num,sub[i].num)==0){//查找到要查询的地铁信息 printf("Number:%s\tLine:%s\tStart Station:%s\tEnd Station:%s\tPassing Stations:%s\tCharge:%s\n",sub[i].num,sub[i].line,sub[i].sstation,sub[i].ostation,sub[i].wstation,sub[i].charge); return; } } printf("Can't find the subway information!\n"); } void Print(){ int i; for(i=0;i<n;i++){ printf("Number:%s\tLine:%s\tStart Station:%s\tEnd Station:%s\tPassing Stations:%s\tCharge:%s\n",sub[i].num,sub[i].line,sub[i].sstation,sub[i].ostation,sub[i].wstation,sub[i].charge); } } void Update(){ int i; char num[N];//要更新的地铁编号 printf("Please input the number of subway you want to update:"); scanf("%s",num); for(i=0;i<n;i++){ if(strcmp(num,sub[i].num)==0){//查找到要更新的地铁信息 printf("Please input the new line of subway:"); scanf("%s",sub[i].line); printf("Please input the new start station of subway:"); scanf("%s",sub[i].sstation); printf("Please input the new end station of subway:"); scanf("%s",sub[i].ostation); printf("Please input the new passing stations of subway:"); scanf("%s",sub[i].wstation); printf("Please input the new charge of subway:"); scanf("%s",sub[i].charge); printf("Update successfully!\n"); return; } } printf("Can't find the subway information!\n"); } void menu(){ printf("******************************************\n"); printf("* Subway System *\n"); printf("* *\n"); printf("* 1.Read file *\n"); printf("* 2.Save *\n"); printf("* 3.Insert *\n"); printf("* 4.Delete *\n"); printf("* 5.Search *\n"); printf("* 6.Print *\n"); printf("* 7.Update *\n"); printf("* 0.Exit *\n"); printf("* *\n"); printf("******************************************\n"); printf("Please input the number of function you want to execute:"); scanf("%d",&m); switch(m){ case 1:if(readfile()=='r') printf("Read file successfully!\n");break; case 2:save();break; case 3:insert();break; case 4:Delete();break; case 5:Search();break; case 6:Print();break; case 7:Update();break; case 0:k=0;break; default:printf("Input error! Please input again!\n");break; } }

相关推荐

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <graphics.h> #include <conio.h> #include <mmsystem.h> #pragma comment(lib,"winmm.lib") IMAGE background; IMAGE array[16]; IMAGE arrayY[16]; struct bgInfo { int x; int y; int speed; }; struct bgInfo bg = { 1000, 0, 5 }; enum 方向 { LEFT, RIGHT }; struct roleInfo { int x; int y; int direct; }; struct roleInfo role = { 300, 400 ,RIGHT }; void loadResource() { loadimage(&background, "Background\\background.jpg"); for (int i = 0; i < 16; i++) { char fileName[50] = ""; sprintf(fileName, "Helix_attack\\Helix_attack_r%d.gif", i + 1); loadimage(array + i, fileName); sprintf(fileName, "Helix_attack\\Helix_attacky_r%d.gif", i + 1); loadimage(arrayY + i, fileName); } } void drawStand(int i) { putimage(0, 0, 1000, 700, &background, bg.x, bg.y); putimage(role.x, role.y, arrayY + i, SRCAND); putimage(role.x, role.y, array + i, SRCPAINT); } void drawKey(int beginFrame, int endFrame) { int i = beginFrame; while (i < endFrame) { putimage(0, 0, 1000, 700, &background, bg.x, bg.y); putimage(role.x, role.y, arrayY + i, SRCAND); putimage(role.x, role.y, array + i, SRCPAINT); i++; Sleep(50); } } DWORD WINAPI playMusic(LPVOID lpVoid) { mciSendString("open 1.mp3", 0, 0, 0); mciSendString("play 1.mp3 wait", 0, 0, 0); mciSendString("close 1.mp3", 0, 0, 0); return 0; } void keyDown() { fflush(stdin); char userKey = _getch(); switch (userKey) { case 'a': case 'A': case 75: bg.x -= bg.speed; role.x -= 5; if (bg.x <= 0) bg.x = 0; break; case 'd': case 'D': case 77: bg.x += bg.speed; role.x += 5; if (bg.x >= background.getwidth() - 1000) bg.x = background.getwidth() - 1000; break; case 'w': case 'W': case 72: role.y -= 5; break; case 's': case 'S': case 80: role.y += 5; break; case ' ': CreateThread(0, 0, playMusic, 0, 0, 0); drawKey(4, 16); break; } } int main() { loadResource(); initgraph(1000, 700); int i = 0; while (1) { drawStand(i); i++; if (i == 4) i = 0; Sleep(50); if (_kbhit()) { keyDown(); } } _getch(); closegraph(); return 0; }

可以写出下面代码的流程图吗#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #define N 100 struct st { int num; int s; }; void myprint(); void mycreate(); void mydisplay(); void mysearch(); void mymax(); void myadd(); void mydelete(); void mysort(); int main(void) { char choose='\0',yes_no='\0'; do { myprint();//显示菜单 printf(" "); choose=getch(); //获取用户输入的选项编号 switch(choose) { case '1':mycreate();break; //输入学生信息 case '2':mydisplay();break; //显示学生信息 case '3':mysearch();break; //查找学生信息 case '4':mymax();break; //求最值 case '5':myadd();break; //插入学生信息 case '6':mydelete();break; //删除学生信息 case '7':mysort();break; //排序学生信息 case '0':exit(0); //退出程序 default :printf("\n %c为非法选项!\n",choose); } printf("\n 要继续选择吗(Y/N)?"); do { yes_no=getch(); }while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n'); }while(yes_no=='y'||yes_no=='Y'); } void myprint() { system("cls"); printf(" |~|\n"); printf(" | 请输入选项编号(0~7): |\n"); printf(" |~|\n"); printf(" | 1.输入 |\n"); printf(" | 2.显示 |\n"); printf(" | 3.查找 |\n"); printf(" | 4.最值 |\n"); printf(" | 5.插入 |\n"); printf(" | 6.删除 |\n"); printf(" | 7.排序 |\n"); printf(" | 0.退出 |\n"); printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"); } void mycreate() //从键盘输入若干学号和成绩,并保存在d:\file.txt文件中 { int i=1; struct st temp={0}; FILE *fp=NULL; fp=fopen("D:\file.txt","w"); if(fp==NULL){printf("\nError!\n");exit(0);} printf

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <dos.h> #include <conio.h> #include <time.h> #define FALSE 0 #define TRUE 1 void mainmenu(void); //主菜单函数 void InputMessage(void);//输入信息函数 void ShowMessage(void);//显示信息函数 void SearchMessage(void);//查询信息函数 void searchbynumber();//根据班次号查询函数 void searchbyaddress();//根据终点站查询的函数 void TicketManagement(void);//选择订票/退票的函数 void TicketOrder();//订票实现函数 void TicketDelete();//退票实现函数 int FLAG;//标志 struct time//时间结构体 { int hour; int minutes; }; struct ticket//车票的结构体 { int carnumber;//车次 struct time setout; char beginpoint[20];//起点站 char endpoint[20];//终点站 float lasttime;//行车时间 int fixnumber;//额定载量 int fixednumber;//已定票的人数 }car[4]; int main() {int FLAG=FALSE; do{mainmenu(); }while(FLAG=FALSE); return 0; } void mainmenu() {char functioNnumber; printf("\n\n\n\n\n\t\t\t\t\t\t车站售票管理系统\n\n"); printf("\t\t\t=============================================================\n"); printf(" \t\t\t\t\t\t1.录入班次信息\t\n"); printf("\t\t\t\t\t\t2.浏览班次信息\t\n"); printf("\t\t\t\t\t\t3.查询行车路线\t\n"); printf("\t\t\t\t\t\t4.售票与退票系统\t\n"); printf("\t\t\t\t\t\t5.退出该系统\t\n"); printf("\t\t\t=============================================================\n"); printf("\t\t\t请选择你所需要的功能:"); scanf("%s",&functioNnumber);switch(functioNnumber) { case '1': {system("cls");InputMessage(); printf("\n按任意键返回主菜单\n"); getchar(); getchar(); mainmenu(); };break; case '2':{ system("cls");ShowMessage(); printf("\n按任意键返回主菜单\n"); getchar(); getchar(); mainmenu(); };break; case '3': { system("cls");SearchMessage(); printf("\n按任意键返回主菜单\n"); getchar(); getchar(); mainmenu(); };break; case '4': {system("cls");TicketManagement(); printf("\n按任意键返回主菜单\n"); getchar(); getchar(); mainmenu(); };break; case '5':FLAG=TRUE; printf("*****************************感谢使用本系统***********************************************"); exit(0); break; default: { printf("对不起你的输入有误,请确保你的输入为1-5.\n"); printf("按任意键返回主菜单\n"); getchar(); getchar(); mainmenu(); }; }; F

最新推荐

recommend-type

软考-考生常见操作说明-202405101400-纯图版.pdf

软考官网--2024常见操作说明:包括如何绘制网络图、UML图、表格等 模拟作答系统是计算机技术与软件专业技术资格(水平)考试的电子化考试系统界面、作答过程的仿真系统,为各级别、各资格涉及输入和页面显示的部分题型提供体验性练习。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解释minorization-maximization (MM) algorithm,并给出matlab代码编写的例子

Minorization-maximization (MM) algorithm是一种常用的优化算法,用于求解非凸问题或含有约束的优化问题。该算法的基本思想是通过构造一个凸下界函数来逼近原问题,然后通过求解凸下界函数的最优解来逼近原问题的最优解。具体步骤如下: 1. 初始化参数 $\theta_0$,设 $k=0$; 2. 构造一个凸下界函数 $Q(\theta|\theta_k)$,使其满足 $Q(\theta_k|\theta_k)=f(\theta_k)$; 3. 求解 $Q(\theta|\theta_k)$ 的最优值 $\theta_{k+1}=\arg\min_\theta Q(
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这
recommend-type

帮我实现在Androidstudio调用chapgpt并提供源码

首先,你需要运行一个ChitGPT的服务器,然后通过Android应用程序与该服务器进行通信。以下是一个简单的Android应用程序示例,可以与ChitGPT进行通信: 1. 首先,在Android Studio中创建一个新的项目,并添加以下依赖项: ``` implementation 'com.squareup.okhttp3:okhttp:4.9.0' implementation 'com.google.code.gson:gson:2.8.6' ``` 2. 创建一个新的Java类,用于与ChitGPT服务器通信。以下是一个简单的实现: ```java import com.
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。