用 c 语言在 vs2022 上写一个小时成绩管理系统要 200 行以上十个函数以上
时间: 2024-05-04 21:17:57 浏览: 25
好的,以下是一个简单的小时成绩管理系统,包括十个函数,共计 200 多行代码。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 50
#define MAX_NAME_LEN 20
struct Student {
char name[MAX_NAME_LEN];
int score;
};
struct Student students[MAX_STUDENTS];
int num_students = 0;
void add_student();
void remove_student();
void update_score();
void print_all();
void print_pass();
void print_fail();
void print_highest();
void print_lowest();
void print_average();
int main() {
int choice;
while (1) {
printf("\n1. Add student\n");
printf("2. Remove student\n");
printf("3. Update score\n");
printf("4. Print all students\n");
printf("5. Print passing students\n");
printf("6. Print failing students\n");
printf("7. Print student with highest score\n");
printf("8. Print student with lowest score\n");
printf("9. Print average score\n");
printf("0. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
remove_student();
break;
case 3:
update_score();
break;
case 4:
print_all();
break;
case 5:
print_pass();
break;
case 6:
print_fail();
break;
case 7:
print_highest();
break;
case 8:
print_lowest();
break;
case 9:
print_average();
break;
case 0:
printf("Goodbye!\n");
exit(0);
default:
printf("Invalid choice!\n");
}
}
return 0;
}
void add_student() {
if (num_students == MAX_STUDENTS) {
printf("Maximum number of students reached!\n");
return;
}
struct Student s;
printf("Enter name: ");
scanf("%s", s.name);
printf("Enter score: ");
scanf("%d", &s.score);
students[num_students++] = s;
}
void remove_student() {
char name[MAX_NAME_LEN];
printf("Enter name of student to remove: ");
scanf("%s", name);
int index = -1;
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].name, name) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("Student not found!\n");
return;
}
for (int i = index; i < num_students - 1; i++) {
students[i] = students[i + 1];
}
num_students--;
printf("Student removed.\n");
}
void update_score() {
char name[MAX_NAME_LEN];
printf("Enter name of student to update score: ");
scanf("%s", name);
int index = -1;
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].name, name) == 0) {
index = i;
break;
}
}
if (index == -1) {
printf("Student not found!\n");
return;
}
printf("Enter new score: ");
scanf("%d", &students[index].score);
printf("Score updated.\n");
}
void print_all() {
printf("%-20s %-10s\n", "Name", "Score");
for (int i = 0; i < num_students; i++) {
printf("%-20s %-10d\n", students[i].name, students[i].score);
}
}
void print_pass() {
printf("%-20s %-10s\n", "Name", "Score");
for (int i = 0; i < num_students; i++) {
if (students[i].score >= 60) {
printf("%-20s %-10d\n", students[i].name, students[i].score);
}
}
}
void print_fail() {
printf("%-20s %-10s\n", "Name", "Score");
for (int i = 0; i < num_students; i++) {
if (students[i].score < 60) {
printf("%-20s %-10d\n", students[i].name, students[i].score);
}
}
}
void print_highest() {
int highest_score = -1;
for (int i = 0; i < num_students; i++) {
if (students[i].score > highest_score) {
highest_score = students[i].score;
}
}
printf("%-20s %-10s\n", "Name", "Score");
for (int i = 0; i < num_students; i++) {
if (students[i].score == highest_score) {
printf("%-20s %-10d\n", students[i].name, students[i].score);
}
}
}
void print_lowest() {
int lowest_score = 101;
for (int i = 0; i < num_students; i++) {
if (students[i].score < lowest_score) {
lowest_score = students[i].score;
}
}
printf("%-20s %-10s\n", "Name", "Score");
for (int i = 0; i < num_students; i++) {
if (students[i].score == lowest_score) {
printf("%-20s %-10d\n", students[i].name, students[i].score);
}
}
}
void print_average() {
int total_score = 0;
for (int i = 0; i < num_students; i++) {
total_score += students[i].score;
}
float average_score = (float)total_score / num_students;
printf("Average score: %.2f\n", average_score);
}
```
相关推荐
![](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)