用c语言编写学生成绩管理实现功能:输入、输出、插入、删除、查找、追加、读入、显示、保存、拷贝、排序、索引、分类合计、退出。
时间: 2024-01-13 12:03:56 浏览: 72
以下是用C语言编写学生成绩管理实现各种功能的示例代码:
1. 输入学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void inputScore(struct Student *student) {
printf("请输入学生的成绩:\n");
printf("大学英语成绩:");
scanf("%f", &(student->english));
printf("毛概成绩:");
scanf("%f", &(student->politics));
printf("数据结构成绩:");
scanf("%f", &(student->dataStructure));
printf("数据库成绩:");
scanf("%f", &(student->database));
}
```
2. 输出学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void outputScore(struct Student student) {
printf("学生的成绩如下:\n");
printf("大学英语成绩:%f\n", student.english);
printf("毛概成绩:%f\n", student.politics);
printf("数据结构成绩:%f\n", student.dataStructure);
printf("数据库成绩:%f\n", student.database);
}
```
3. 插入学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void insertScore(struct Student *student, float english, float politics, float dataStructure, float database) {
student->english = english;
student->politics = politics;
student->dataStructure = dataStructure;
student->database = database;
}
```
4. 删除学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void deleteScore(struct Student *student) {
student->english = 0;
student->politics = 0;
student->dataStructure = 0; student->database = 0;
}
```
5. 查找学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void searchScore(struct Student student) {
printf("学生的成绩如下:\n");
printf("大学英语成绩:%f\n", student.english);
printf("毛概成绩:%f\n", student.politics);
printf("数据结构成绩:%f\n", student.dataStructure);
printf("数据库成绩:%f\n", student.database);
}
```
6. 追加学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void appendScore(struct Student *student, float english, float politics, float dataStructure, float database) {
student->english += english;
student->politics += politics;
student->dataStructure += dataStructure;
student->database += database;
}
```
7. 读入学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void readScore(struct Student *student) {
printf("请输入学生的成绩:\n");
printf("大学英语成绩:");
scanf("%f", &(student->english));
printf("毛概成绩:");
scanf("%f", &(student->politics));
printf("数据结构成绩:");
scanf("%f", &(student->dataStructure));
printf("数据库成绩:");
scanf("%f", &(student->database));
}
```
8. 显示学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void displayScore(struct Student student) {
printf("学生的成绩如下:\n");
printf("大学英语成绩:%f\n", student.english);
printf("毛概成绩:%f\n", student.politics);
printf("数据结构成绩:%f\n", student.dataStructure);
printf("数据库成绩:%f\n", student.database);
}
```
9. 保存学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void saveScore(struct Student student) {
FILE *file = fopen("score.txt", "w");
if (file == NULL) {
printf("保存失败!\n");
return;
}
fprintf(file, "大学英语成绩:%f\n", student.english);
fprintf(file, "毛概成绩:%f\n", student.politics);
fprintf(file, "数据结构成绩:%f\n", student.dataStructure);
fprintf(file, "数据库成绩:%f\n", student.database);
fclose(file);
printf("保存成功!\n");
}
```
10. 拷贝学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void copyScore(struct Student *dest, struct Student src) {
dest->english = src.english;
dest->politics = src.politics;
dest->dataStructure = src.dataStructure;
dest->database = src.database;
}
```
11. 排序学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void sortScore(struct Student *students, int count) {
// 使用冒泡排序按照大学英语成绩从小到大排序
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (students[j].english > students[j + 1].english) {
struct Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
}
```
12. 索引学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void indexScore(struct Student *students, int count) {
printf("学生成绩索引如下:\n");
for (int i = 0; i < count; i++) {
printf("学生%d的大学英语成绩:%f\n", i + 1, students[i].english);
}
}
```
13. 分类合计学生成绩:
```c
#include <stdio.h>
struct Student {
float english;
float politics;
float dataStructure;
float database;
};
void sumScore(struct Student *students, int count) {
float englishSum = 0;
float politicsSum = 0;
float dataStructureSum = 0;
float databaseSum = 0;
for (int i = 0; i < count; i++) {
englishSum += students[i].english;
politicsSum += students[i].politics;
dataStructureSum += students[i].dataStructure;
databaseSum += students[i].database;
}
printf("大学英语成绩总和:%f\n", englishSum);
printf("毛概成绩总和:%f\n", politicsSum);
printf("数据结构成绩总和:%f\n", dataStructureSum);
printf("数据库成绩总和:%f\n", databaseSum);
}
```
14. 退出程序:
```c
#include <stdio.h>
#include <stdlib.h>
void exitProgram() {
printf("程序已退出!\n");
exit(0);
}
```