C语言编程,设计编写一个传统的小型学生信息管理系统,需要完整代码。 1、该系统可以用于管理一个班的学生信息。学生人数在50人左右。 2、该系统存放了有关学生的某些方面的信息:如学号、姓名、性别、出生日期、成绩、所在系等,具体包含的数据内容由设计者分析确定。 3、所有学生信息的数据结构及其存储结构由设计者分析确定。 4、所有学生的信息数据可以用文件形式存放。(可选项) 5、该系统具有相关的数据输入、输出、查询、修改、插入、删除、统计、排序等功能。(功能的多少设计者可根据需要自行调整,但必须具备输出、输出、查询、某一方面数据统计的基本功能。) 6、系统应具有友好的用户界面,并能够让用户通过菜单进行相应功能的选择。 7、选用适当的算法和数据结构,建立相应的程序代码。

时间: 2023-07-10 09:17:03 浏览: 43
以下是一个简单的学生信息管理系统的C语言代码,实现基本的增删改查和文件存储功能,具体细节可以根据实际需求进行修改和完善: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STU_NUM 50 #define FILE_NAME "student.dat" typedef struct { char id[20]; char name[20]; char gender[5]; char birth[20]; int score; char department[20]; } Student; Student stuList[MAX_STU_NUM]; int stuNum = 0; void printMenu() { printf("1. Add a student\n"); printf("2. Delete a student\n"); printf("3. Modify student information\n"); printf("4. Query student information\n"); printf("5. Display all students\n"); printf("6. Save to file\n"); printf("7. Load from file\n"); printf("8. Exit\n"); } void addStudent() { if (stuNum >= MAX_STU_NUM) { printf("The student list is full!\n"); return; } Student newStu; printf("Please input the student ID: "); scanf("%s", newStu.id); printf("Please input the student name: "); scanf("%s", newStu.name); printf("Please input the student gender: "); scanf("%s", newStu.gender); printf("Please input the student birth: "); scanf("%s", newStu.birth); printf("Please input the student score: "); scanf("%d", &newStu.score); printf("Please input the student department: "); scanf("%s", newStu.department); stuList[stuNum++] = newStu; printf("Add student successfully!\n"); } void deleteStudent() { char id[20]; printf("Please input the ID of the student you want to delete: "); scanf("%s", id); int index = -1; for (int i = 0; i < stuNum; i++) { if (strcmp(stuList[i].id, id) == 0) { index = i; break; } } if (index == -1) { printf("The student is not found!\n"); return; } for (int i = index; i < stuNum - 1; i++) { stuList[i] = stuList[i + 1]; } stuNum--; printf("Delete student successfully!\n"); } void modifyStudent() { char id[20]; printf("Please input the ID of the student you want to modify: "); scanf("%s", id); int index = -1; for (int i = 0; i < stuNum; i++) { if (strcmp(stuList[i].id, id) == 0) { index = i; break; } } if (index == -1) { printf("The student is not found!\n"); return; } Student newStu; printf("Please input the new student ID (or press Enter to skip): "); fgets(newStu.id, 20, stdin); if (newStu.id[0] != '\n') { newStu.id[strcspn(newStu.id, "\n")] = 0; } printf("Please input the new student name (or press Enter to skip): "); fgets(newStu.name, 20, stdin); if (newStu.name[0] != '\n') { newStu.name[strcspn(newStu.name, "\n")] = 0; } printf("Please input the new student gender (or press Enter to skip): "); fgets(newStu.gender, 5, stdin); if (newStu.gender[0] != '\n') { newStu.gender[strcspn(newStu.gender, "\n")] = 0; } printf("Please input the new student birth (or press Enter to skip): "); fgets(newStu.birth, 20, stdin); if (newStu.birth[0] != '\n') { newStu.birth[strcspn(newStu.birth, "\n")] = 0; } printf("Please input the new student score (or press Enter to skip): "); char buf[10]; fgets(buf, 10, stdin); if (buf[0] != '\n') { newStu.score = atoi(buf); } else { newStu.score = stuList[index].score; } printf("Please input the new student department (or press Enter to skip): "); fgets(newStu.department, 20, stdin); if (newStu.department[0] != '\n') { newStu.department[strcspn(newStu.department, "\n")] = 0; } stuList[index] = newStu; printf("Modify student information successfully!\n"); } void queryStudent() { char id[20]; printf("Please input the ID of the student you want to query: "); scanf("%s", id); int index = -1; for (int i = 0; i < stuNum; i++) { if (strcmp(stuList[i].id, id) == 0) { index = i; break; } } if (index == -1) { printf("The student is not found!\n"); return; } printf("ID: %s\n", stuList[index].id); printf("Name: %s\n", stuList[index].name); printf("Gender: %s\n", stuList[index].gender); printf("Birth: %s\n", stuList[index].birth); printf("Score: %d\n", stuList[index].score); printf("Department: %s\n", stuList[index].department); } void displayAll() { if (stuNum == 0) { printf("No student information is stored!\n"); return; } printf("ID\tName\tGender\tBirth\tScore\tDepartment\n"); for (int i = 0; i < stuNum; i++) { printf("%s\t%s\t%s\t%s\t%d\t%s\n", stuList[i].id, stuList[i].name, stuList[i].gender, stuList[i].birth, stuList[i].score, stuList[i].department); } } void saveToFile() { FILE *fp = fopen(FILE_NAME, "wb"); if (fp == NULL) { printf("Failed to open file!\n"); return; } fwrite(&stuNum, sizeof(int), 1, fp); fwrite(stuList, sizeof(Student), stuNum, fp); fclose(fp); printf("Save to file successfully!\n"); } void loadFromFile() { FILE *fp = fopen(FILE_NAME, "rb"); if (fp == NULL) { printf("Failed to open file!\n"); return; } fread(&stuNum, sizeof(int), 1, fp); fread(stuList, sizeof(Student), stuNum, fp); fclose(fp); printf("Load from file successfully!\n"); } int main() { int choice; while (1) { printMenu(); printf("Please input your choice: "); scanf("%d", &choice); switch (choice) { case 1: addStudent(); break; case 2: deleteStudent(); break; case 3: modifyStudent(); break; case 4: queryStudent(); break; case 5: displayAll(); break; case 6: saveToFile(); break; case 7: loadFromFile(); break; case 8: exit(0); default: printf("Invalid choice!\n"); break; } } return 0; } ```

相关推荐

最新推荐

recommend-type

C语言数组实现学生信息管理系统设计

主要为大家详细介绍了C语言数组实现学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言实现班档案管理系统课程设计

主要为大家详细介绍了C语言实现班档案管理系统课程设计,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言实现简单学生学籍管理系统

主要为大家详细介绍了C语言实现简单学生学籍管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言实现简单学生选课管理系统

主要为大家详细介绍了C语言实现简单学生选课管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

大一C语言课程设计图书信息管理系统.doc

大一C语言课程设计图书信息管理系统.doc
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用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

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