在这个代码的基础上,加上“各种基本数据的插入。如:在学生选修课程基本信息中插入一条新信息等。”和“基于各种数据的搜索。如:查询某班学生信息,查询某学生的成绩等。”的功能
时间: 2024-04-14 20:27:01 浏览: 24
下面是在之前的代码基础上添加了插入数据和搜索功能的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct {
int studentID;
char name[50];
char gender[10];
char className[50];
float chineseScore;
float mathScore;
float englishScore;
float databaseScore;
} Student;
// 全局变量
Student students[100];
int studentCount = 0;
// 函数声明
void addStudent();
void editStudent();
void deleteStudent();
void displayStudents();
void calculateAverageScore();
void listFailingStudents();
void insertCourseInfo();
void searchStudentInfo();
void exitSystem();
int main() {
int choice;
do {
printf("============== 学生成绩统计管理系统 ==============\n");
printf("1. 录入学生信息\n");
printf("2. 修改学生信息\n");
printf("3. 删除学生信息\n");
printf("4. 显示学生信息\n");
printf("5. 统计平均成绩\n");
printf("6. 列出不及格学生\n");
printf("7. 插入选修课程信息\n");
printf("8. 搜索学生信息\n");
printf("9. 退出系统\n");
printf("请输入你的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
editStudent();
break;
case 3:
deleteStudent();
break;
case 4:
displayStudents();
break;
case 5:
calculateAverageScore();
break;
case 6:
listFailingStudents();
break;
case 7:
insertCourseInfo();
break;
case 8:
searchStudentInfo();
break;
case 9:
exitSystem();
break;
default:
printf("无效的选择!请重新输入。\n");
}
printf("\n");
} while (choice != 9);
return 0;
}
void addStudent() {
// 省略代码
// ...
}
void editStudent() {
// 省略代码
// ...
}
void deleteStudent() {
// 省略代码
// ...
}
void displayStudents() {
// 省略代码
// ...
}
void calculateAverageScore() {
// 省略代码
// ...
}
void listFailingStudents() {
// 省略代码
// ...
}
void insertCourseInfo() {
int studentID, found = 0;
printf("请输入要插入选修课程信息的学生学号:");
scanf("%d", &studentID);
for (int i = 0; i < studentCount; i++) {
if (students[i].studentID == studentID) {
printf("请输入选修课程名称:");
scanf("%s", students[i].courseName);
printf("请输入选修课程成绩:");
scanf("%f", &students[i].courseScore);
found = 1;
printf("选修课程信息插入成功!\n");
break;
}
}
if (!found) {
printf("未找到该学生的信息!\n");
}
}
void searchStudentInfo() {
int choice, studentID, found = 0;
printf("请选择搜索方式:\n");
printf("1. 按学号搜索\n");
printf("2. 按姓名搜索\n");
printf("请输入你的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("请输入要搜索的学生学号:");
scanf("%d", &studentID);
for (int i = 0; i < studentCount; i++) {
if (students[i].studentID == studentID) {
printf("学号:%d\n", students[i].studentID);
printf("姓名:%s\n", students[i].name);
printf("性别:%s\n", students[i].gender);
printf("班级:%s\n", students[i].className);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生的信息!\n");
}
break;
case 2:
// 省略代码,根据姓名进行搜索
break;
default:
printf("无效的选择!\n");
}
}
void exitSystem() {
printf("感谢使用学生成绩统计管理系统,再见!\n");
exit(0);
}
```
在上面的代码中,我们添加了两个新的功能函数:`insertCourseInfo()`用于在学生选修课程信息中插入一条新信息,`searchStudentInfo()`用于根据学号或姓名搜索学生信息。你可以根据需要进一步修改和扩展这些功能函数,以满足你的实际需求。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)