用C语言代码以及数据结构相关知识写出一个学生成绩查询统计系统 要求: (1)一起打印并根据成绩进行由高到低排序和根据学生姓名进行字典排序功能两个表格; (2)根据学号或姓名查找学生成绩; (3)输出统计及格、中、良、优秀和不及格学生人数及其所占比例; (4)可以录入学生成绩要求能写入学生学号姓名三科课程名称和成绩 (5)各个功能通过目录选择要进行的功能 (6)删除学生信息功能
时间: 2024-01-15 16:02:51 浏览: 70
今天给大家分享一个C语言环境下开发的学生成绩管理系统 这个系统原理很简单:成绩的录入,输出,修改,排序,删除等等
好的,我明白了。以下是一个简单的学生成绩查询统计系统的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 1000
#define MAX_NAME_LEN 20
#define MAX_COURSE_NUM 3
typedef struct {
char name[MAX_NAME_LEN];
int id;
int score[MAX_COURSE_NUM];
float avg_score;
} student;
int student_num = 0;
student students[MAX_STUDENT_NUM];
void add_student();
void delete_student();
void sort_by_score();
void sort_by_name();
void search_student();
void print_statistics();
int main() {
int choice = 0;
while (1) {
printf("\nMenu:\n");
printf("1. Add student\n");
printf("2. Delete student\n");
printf("3. Sort by score\n");
printf("4. Sort by name\n");
printf("5. Search student\n");
printf("6. Print statistics\n");
printf("7. Exit\n");
printf("Enter your choice:\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
delete_student();
break;
case 3:
sort_by_score();
break;
case 4:
sort_by_name();
break;
case 5:
search_student();
break;
case 6:
print_statistics();
break;
case 7:
printf("Exit.\n");
exit(0);
default:
printf("Invalid choice.\n");
break;
}
}
return 0;
}
void add_student() {
if (student_num >= MAX_STUDENT_NUM) {
printf("No more space.\n");
return;
}
student new_student;
printf("Enter student name:\n");
scanf("%s", new_student.name);
printf("Enter student id:\n");
scanf("%d", &new_student.id);
printf("Enter student score for course 1:\n");
scanf("%d", &new_student.score[0]);
printf("Enter student score for course 2:\n");
scanf("%d", &new_student.score[1]);
printf("Enter student score for course 3:\n");
scanf("%d", &new_student.score[2]);
new_student.avg_score = (new_student.score[0] + new_student.score[1] + new_student.score[2]) / 3.0;
students[student_num++] = new_student;
printf("Student added.\n");
}
void delete_student() {
int id;
printf("Enter student id:\n");
scanf("%d", &id);
int i;
for (i = 0; i < student_num; i++) {
if (students[i].id == id) {
int j;
for (j = i; j < student_num - 1; j++) {
students[j] = students[j + 1];
}
student_num--;
printf("Student deleted.\n");
return;
}
}
printf("Student not found.\n");
}
void sort_by_score() {
int i, j;
for (i = 0; i < student_num; i++) {
for (j = i + 1; j < student_num; j++) {
if (students[i].avg_score < students[j].avg_score) {
student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
printf("Sorted by score (from high to low):\n");
printf("Name\tID\tScore 1\tScore 2\tScore 3\tAverage score\n");
for (i = 0; i < student_num; i++) {
printf("%s\t%d\t%d\t%d\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score[0],
students[i].score[1], students[i].score[2], students[i].avg_score);
}
}
void sort_by_name() {
int i, j;
for (i = 0; i < student_num; i++) {
for (j = i + 1; j < student_num; j++) {
if (strcmp(students[i].name, students[j].name) > 0) {
student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
printf("Sorted by name (in dictionary order):\n");
printf("Name\tID\tScore 1\tScore 2\tScore 3\tAverage score\n");
for (i = 0; i < student_num; i++) {
printf("%s\t%d\t%d\t%d\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score[0],
students[i].score[1], students[i].score[2], students[i].avg_score);
}
}
void search_student() {
int choice = 0;
while (1) {
printf("Search by:\n");
printf("1. Student id\n");
printf("2. Student name\n");
printf("3. Back to menu\n");
printf("Enter your choice:\n");
scanf("%d", &choice);
switch (choice) {
case 1: {
int id;
printf("Enter student id:\n");
scanf("%d", &id);
int i;
for (i = 0; i < student_num; i++) {
if (students[i].id == id) {
printf("Name\tID\tScore 1\tScore 2\tScore 3\tAverage score\n");
printf("%s\t%d\t%d\t%d\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score[0],
students[i].score[1], students[i].score[2], students[i].avg_score);
return;
}
}
printf("Student not found.\n");
break;
}
case 2: {
char name[MAX_NAME_LEN];
printf("Enter student name:\n");
scanf("%s", name);
int i;
for (i = 0; i < student_num; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("Name\tID\tScore 1\tScore 2\tScore 3\tAverage score\n");
printf("%s\t%d\t%d\t%d\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score[0],
students[i].score[1], students[i].score[2], students[i].avg_score);
return;
}
}
printf("Student not found.\n");
break;
}
case 3:
return;
default:
printf("Invalid choice.\n");
break;
}
}
}
void print_statistics() {
int pass_num = 0, fail_num = 0, middle_num = 0, good_num = 0, excellent_num = 0;
int i;
for (i = 0; i < student_num; i++) {
if (students[i].avg_score >= 90) {
excellent_num++;
} else if (students[i].avg_score >= 80) {
good_num++;
} else if (students[i].avg_score >= 70) {
middle_num++;
} else if (students[i].avg_score >= 60) {
pass_num++;
} else {
fail_num++;
}
}
printf("Pass: %d (%.2f%%)\n", pass_num, pass_num * 100.0 / student_num);
printf("Middle: %d (%.2f%%)\n", middle_num, middle_num * 100.0 / student_num);
printf("Good: %d (%.2f%%)\n", good_num, good_num * 100.0 / student_num);
printf("Excellent: %d (%.2f%%)\n", excellent_num, excellent_num * 100.0 / student_num);
printf("Fail: %d (%.2f%%)\n", fail_num, fail_num * 100.0 / student_num);
}
```
这个程序使用了一个结构体 `student` 来保存学生信息,包括姓名、学号、三科成绩和平均成绩。主函数中提供了菜单,可以选择增加、删除、排序、搜索和输出统计信息等功能。其中排序功能可以按照成绩和姓名两种方式排序,搜索功能可以按照学号和姓名两种方式查找学生。同时,程序使用了数据结构相关知识来存储学生信息,包括数组、结构体和指针等。
阅读全文