#include <stdio.h> #include<string.h> #include<stdlib.h> struct student { char name[10]; char number[10]; char class1[5]; char class2[5]; char class3[5]; float average; }; int X;int num=0; struct student Stu[1000]; int addstu() { while(1) { printf("请输入学号,名字,成绩1,成绩2,成绩3\n"); scanf("%s%s%s%s%s",Stu[num].number,Stu[num].name,Stu[num].class1,Stu[num].class2,Stu[num].class3); double grade1=atoi(Stu[num].class1); double grade2=atoi(Stu[num].class2); double grade3=atoi(Stu[num].class3); Stu[num].average=(grade1+grade2+grade3)/3; num++; printf("是否添加?"); getchar(); if (getchar()=='n') { break; } } return num; } void stu_display(int i) { printf("%8s,%s,%s,%s,%s",Stu[i].number,Stu[i].name,Stu[i].class1,Stu[i].class2,Stu[i].class3); } int stu_findnumber(char number[]) { int i; for(i=0;i<num;i++) { if(strcmp(Stu[i].number, number)==0) { return i; } } return -1; } void stu_find() { while(1) { char number[20]; int index; printf("请输入学号"); scanf("%s",number); getchar(); index=stu_findnumber(number); if(index==-1){ printf("学生不存在"); } else{ printf("学号,姓名,课程1成绩,课程2成绩,课程3成绩分别为"); stu_display(index); } break; } } void Stu_sort() { int i,j; struct student x; for(i=0;i<num-1;i++) { for(j=1;j<num-i;j++) { if(Stu[j-1].average<Stu[j].average) { x=Stu[j-1]; Stu[j-1]=Stu[j]; Stu[j]=x; } } } printf("排序后的结果学号,姓名,课程1成绩,课程2成绩,课程3成绩分别为\n"); for(int q=0;q<num;q++) { stu_display(q); } } int main() { while(1) { printf(" 学生成绩管理系统 \n"); printf(" 1、成绩录入\n"); printf(" 2、成绩查询\n"); printf(" 3、成绩统计\n"); printf(" 4、退出系统\n"); printf("请选择1-4\n "); scanf("%d",&X); getchar(); switch(X) { case 1: addstu(); break; case 2: stu_find(); break; case 3: Stu_sort(); break; case 4: exit(0); break; } } }此程序中各函数之间的调用关系

时间: 2024-04-28 07:26:15 浏览: 11
该程序中各函数之间的调用关系如下: 1. main函数调用addstu、stu_find、Stu_sort函数; 2. addstu函数内部调用stu_display函数; 3. stu_find函数内部调用stu_findnumber和stu_display函数; 4. Stu_sort函数内部调用stu_display函数。
相关问题

修改程序:#include <stdio.h> #include <stdlib.h> #include <string.h> #define Element 6 struct Student { char name[8]; char id[12]; int sex; int age; float total_gpa; } student[Element]; int main() { int i; FILE *fp; if ((fp = fopen("stu.dat", "rb")) == NULL) { printf("Can't open file!\n"); exit(0); } for(i=0;i<Element;i++) { fread(&student[i],sizeof(struct student_type),6,fp); printf("%-10s% %4s %4d %4d %-15f\n",student[i].id, student[i].name, student[i].sex, student[i].age, student[i].total_gpa) } fclose(fp); return 0; }

修改程序如下: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define Element 6 struct Student { char name[8]; char id[12]; int sex; int age; float total_gpa; } student[Element]; int main() { int i; FILE *fp; if ((fp = fopen("stu.dat", "rb")) == NULL) { printf("Can't open file!\n"); exit(0); } for(i = 0; i < Element; i++) { fread(&student[i], sizeof(struct Student), 1, fp); printf("%-10s %-8s %4d %4d %-15f\n", student[i].id, student[i].name, student[i].sex, student[i].age, student[i].total_gpa); } fclose(fp); return 0; } ``` 修改点如下: 1. 结构体名称应该与定义的一致,即 `student` 而不是 `student_type`; 2. 在 `fread` 中,`sizeof(struct student_type)` 应该改为 `sizeof(struct Student)`,且第三个参数应该为 1 而不是 6; 3. 在 `printf` 中,`% %4s` 应该改为 `%-8s`,即输出 `name` 时保证对齐; 4. `printf` 格式化字符串中,`%-10s` 后应该有一个空格,即输出 `id` 时保证对齐。

#include<stdio.h> #include<stdlib.h> #include<string.h> #include<windows.h> struct stu { int id; char name[10]; float grade[11]; float sum; float average; float gpa; struct stu* next; };按照这个结构体来续写C语言代码。要求将学生信息保存在硬盘文件中,通过制定文件路径和文件名称来导入学生信息;按照学号对所有学生信息进行升序、降序排列,并输出到屏幕显示或输出到文件

好的,以下是续写的代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> struct stu { int id; char name[10]; float grade[11]; float sum; float average; float gpa; struct stu* next; }; void saveToFile(struct stu* head, char* fileName) { FILE* fp = fopen(fileName, "wb"); if (fp == NULL) { printf("Failed to open file!\n"); return; } struct stu* p = head; while (p != NULL) { fwrite(p, sizeof(struct stu), 1, fp); p = p->next; } fclose(fp); printf("Successfully saved to file!\n"); } struct stu* readFromFile(char* fileName) { FILE* fp = fopen(fileName, "rb"); if (fp == NULL) { printf("Failed to open file!\n"); return NULL; } struct stu* head = NULL, *p = NULL, *q = NULL; while (!feof(fp)) { p = (struct stu*)malloc(sizeof(struct stu)); if (p == NULL) { printf("Memory allocation failed!\n"); return NULL; } fread(p, sizeof(struct stu), 1, fp); if (p->id == 0) { free(p); break; } p->next = NULL; if (head == NULL) { head = p; } else { q->next = p; } q = p; } fclose(fp); printf("Successfully read from file!\n"); return head; } void printList(struct stu* head) { if (head == NULL) { printf("The list is empty!\n"); return; } printf("ID\tName\tGrade1\tGrade2\tGrade3\tGrade4\tGrade5\tGrade6\tGrade7\tGrade8\tGrade9\tGrade10\tSum\tAverage\tGPA\n"); struct stu* p = head; while (p != NULL) { printf("%d\t%s\t", p->id, p->name); for (int i = 0; i < 10; i++) { printf("%.2f\t", p->grade[i]); } printf("%.2f\t%.2f\t%.2f\n", p->sum, p->average, p->gpa); p = p->next; } } void swap(struct stu* a, struct stu* b) { struct stu temp = *a; *a = *b; *b = temp; } void sortList(struct stu* head, int order) { if (head == NULL) { printf("The list is empty!\n"); return; } int count = 0; struct stu* p = head; while (p != NULL) { count++; p = p->next; } for (int i = 0; i < count - 1; i++) { p = head; for (int j = 0; j < count - i - 1; j++) { if (order == 1) { if (p->id > p->next->id) { swap(p, p->next); } } else { if (p->id < p->next->id) { swap(p, p->next); } } p = p->next; } } printf("Successfully sorted!\n"); } int main() { struct stu* head = NULL; char fileName[100]; int choice, order; while (1) { system("cls"); printf("1. Import student information from file\n"); printf("2. Save student information to file\n"); printf("3. Print student information\n"); printf("4. Sort student information by ID in ascending order\n"); printf("5. Sort student information by ID in descending order\n"); printf("6. Exit\n"); printf("Please enter your choice: "); scanf_s("%d", &choice); switch (choice) { case 1: printf("Please enter the file path and name: "); scanf_s("%s", fileName, 100); head = readFromFile(fileName); Sleep(2000); break; case 2: printf("Please enter the file path and name: "); scanf_s("%s", fileName, 100); saveToFile(head, fileName); Sleep(2000); break; case 3: printList(head); system("pause"); break; case 4: sortList(head, 1); system("pause"); break; case 5: sortList(head, 2); system("pause"); break; case 6: printf("Goodbye!\n"); return 0; default: printf("Invalid choice!\n"); Sleep(1000); break; } } return 0; } ``` 这段代码实现了以下功能: 1. 将学生信息保存到硬盘文件中,并通过指定文件路径和文件名称来导入学生信息。 2. 按照学号对所有学生信息进行升序、降序排列,并输出到屏幕显示或输出到文件。 3. 通过菜单的方式来选择要执行的操作。 希望对你有所帮助!

相关推荐

最新推荐

recommend-type

grpcio-1.63.0-cp38-cp38-linux_armv7l.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

SQLyog-13.1.3-0.x86Community.exe

SQLyog-13.1.3-0.x86Community
recommend-type

VB自动出题题库系统设计(源代码+系统).rar

计算机专业毕业设计VB精品论文资源
recommend-type

debugpy-1.0.0b2-cp35-cp35m-manylinux1_i686.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

实战自学python如何成为大佬(目录):https://blog.csdn.net/weixin-67859959/artic

实战自学python如何成为大佬(目录):https://blog.csdn.net/weixin-67859959/artic
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

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

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