详细设计:
1. 框图
```
+----------------+ +------------------------+
| | | |
| 用户操作界面 |<--------->| 服务器处理 |
| | | |
+----------------+ +------------------------+
```
2. 程序实现
(1)添加学生信息
```
void add_student_info(char* file_name, char* student_id, char* student_name, float student_score) {
FILE* fp = fopen(file_name, "a");
fprintf(fp, "%s\t%s\t%.2f\n", student_id, student_name, student_score);
fclose(fp);
}
```
(2)修改学生信息
```
void modify_student_info(char* file_name, char* student_id, char* student_name, float student_score) {
FILE* fp = fopen(file_name, "r");
FILE* tmp_fp = fopen("tmp.txt", "w");
char buf[1024];
int found = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
char id[10], name[20];
float score;
sscanf(buf, "%s\t%s\t%f", id, name, &score);
if (strcmp(id, student_id) == 0) {
fprintf(tmp_fp, "%s\t%s\t%.2f\n", student_id, student_name, student_score);
found = 1;
} else {
fprintf(tmp_fp, "%s", buf);
}
}
fclose(fp);
fclose(tmp_fp);
if (found) {
remove(file_name);
rename("tmp.txt", file_name);
} else {
remove("tmp.txt");
}
}
```
(3)删除学生信息
```
void delete_student_info(char* file_name, char* student_id) {
FILE* fp = fopen(file_name, "r");
FILE* tmp_fp = fopen("tmp.txt", "w");
char buf[1024];
int found = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
char id[10];
sscanf(buf, "%s", id);
if (strcmp(id, student_id) == 0) {
found = 1;
} else {
fprintf(tmp_fp, "%s", buf);
}
}
fclose(fp);
fclose(tmp_fp);
if (found) {
remove(file_name);
rename("tmp.txt", file_name);
} else {
remove("tmp.txt");
}
}
```
(4)查询学生信息
```
void query_student_info(char* file_name, char* student_id) {
FILE* fp = fopen(file_name, "r");
char buf[1024];
int found = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
char id[10], name[20];
float score;
sscanf(buf, "%s\t%s\t%f", id, name, &score);
if (strcmp(id, student_id) == 0) {
printf("%s\t%s\t%.2f\n", id, name, score);
found = 1;
break;
}
}
fclose(fp);
if (!found) {
printf("Student info not found!\n");
}
}
```
(5)显示所有学生信息
```
void display_all_student_info(char* file_name) {
FILE* fp = fopen(file_name, "r");
char buf[1024];
while (fgets(buf, sizeof(buf), fp) != NULL) {
char id[10], name[20];
float score;
sscanf(buf, "%s\t%s\t%f", id, name, &score);
printf("%s\t%s\t%.2f\n", id, name, score);
}
fclose(fp);
}
```
3. 核心步骤图
(1)添加学生信息
![add_student_info](https://i.imgur.com/0xZ8JYf.png)
(2)修改学生信息
![modify_student_info](https://i.imgur.com/8fO8mY0.png)
(3)删除学生信息
![delete_student_info](https://i.imgur.com/FXiw3xq.png)
(4)查询学生信息
![query_student_info](https://i.imgur.com/1RUK2gX.png)
(5)显示所有学生信息
![display_all_student_info](https://i.imgur.com/SOJ8LhL.png)