c++学生信息管理系统,实现录入,新增,显示查询和排序,和计算平均成绩
时间: 2023-09-14 18:00:49 浏览: 254
学生信息管理系统是一种用于录入、新增、显示查询和排序学生信息的软件系统,它也能够计算学生的平均成绩。这个系统的主要功能和特点如下:
1. 录入功能:通过该系统,可以方便地录入学生的基本信息,包括学号、姓名、性别、年龄等。同时,还可以录入学生的各科成绩,如语文、数学、英语等。
2. 新增功能:当有新的学生加入时,系统提供新增功能,可以方便地添加新的学生信息,并进行科目成绩的录入。
3. 显示查询功能:该系统拥有强大的查询功能,可以根据学生的学号、姓名等关键词进行快速的信息查找。同时,还可以按照不同的条件进行筛选和排序,如按照成绩从高到低排序,或按照年龄从小到大排序等。
4. 计算平均成绩:在系统中,可以通过简单的操作计算学生的平均成绩。系统会自动将各科成绩相加,并除以科目数,得出每个学生的平均成绩。这样,可以方便地评估和比较每个学生的学业水平。
总之,学生信息管理系统是一个功能强大且易于使用的工具,可以方便地录入、新增、显示查询和排序学生信息,并计算学生的平均成绩。它为学校、教师和学生提供了便捷的管理和评估学生学业发展的方式。
相关问题
用c语言写一个学生学籍管理系统 主要功能: 欢迎及菜单页面 通过文本文件读入学生信息 新增学生(学号不可重复) 录入成绩 删除学生 展示所有学生信息 计算最高最低平均成绩 统计ABCD每个分段的人数 按成绩从高到低排序 按学号排序 退出前将所有学生信息回写进文本文档
很好,以下是一个简单的学生学籍管理系统的C语言实现:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct student {
char id[20];
char name[20];
int score;
};
int num_students = 0;
struct student students[MAX_STUDENTS];
void load_students(char *filename) {
FILE *fp = fopen(filename, "r");
if (!fp) {
printf("Error: cannot open file %s for reading\n", filename);
return;
}
char line[100];
while (fgets(line, sizeof(line), fp)) {
char *p = strtok(line, ",");
strcpy(students[num_students].id, p);
p = strtok(NULL, ",");
strcpy(students[num_students].name, p);
p = strtok(NULL, ",");
students[num_students].score = atoi(p);
num_students++;
}
fclose(fp);
}
void save_students(char *filename) {
FILE *fp = fopen(filename, "w");
if (!fp) {
printf("Error: cannot open file %s for writing\n", filename);
return;
}
for (int i = 0; i < num_students; i++) {
fprintf(fp, "%s,%s,%d\n", students[i].id, students[i].name, students[i].score);
}
fclose(fp);
}
struct student *find_student(char *id) {
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].id, id) == 0) {
return &students[i];
}
}
return NULL;
}
void add_student() {
struct student s;
printf("Enter student ID: ");
scanf("%s", s.id);
if (find_student(s.id)) {
printf("Error: student with ID %s already exists\n", s.id);
return;
}
printf("Enter student name: ");
scanf("%s", s.name);
printf("Enter student score: ");
scanf("%d", &s.score);
students[num_students++] = s;
printf("Student added successfully\n");
}
void remove_student() {
char id[20];
printf("Enter student ID: ");
scanf("%s", id);
struct student *s = find_student(id);
if (!s) {
printf("Error: student with ID %s does not exist\n", id);
return;
}
for (int i = 0; i < num_students; i++) {
if (&students[i] == s) {
for (int j = i; j < num_students - 1; j++) {
students[j] = students[j + 1];
}
num_students--;
printf("Student removed successfully\n");
return;
}
}
}
void display_all_students() {
printf("ID\tName\tScore\n");
for (int i = 0; i < num_students; i++) {
printf("%s\t%s\t%d\n", students[i].id, students[i].name, students[i].score);
}
}
void compute_statistics() {
int min_score = students[0].score;
int max_score = students[0].score;
int sum_score = 0;
int count_a = 0, count_b = 0, count_c = 0, count_d = 0;
for (int i = 0; i < num_students; i++) {
int score = students[i].score;
if (score < min_score) {
min_score = score;
}
if (score > max_score) {
max_score = score;
}
sum_score += score;
if (score >= 90) {
count_a++;
} else if (score >= 80) {
count_b++;
} else if (score >= 70) {
count_c++;
} else {
count_d++;
}
}
double avg_score = (double) sum_score / num_students;
printf("Minimum score: %d\n", min_score);
printf("Maximum score: %d\n", max_score);
printf("Average score: %.2f\n", avg_score);
printf("A: %d\n", count_a);
printf("B: %d\n", count_b);
printf("C: %d\n", count_c);
printf("D: %d\n", count_d);
}
void sort_by_score() {
for (int i = 0; i < num_students - 1; i++) {
for (int j = i + 1; j < num_students; j++) {
if (students[i].score < students[j].score) {
struct student tmp = students[i];
students[i] = students[j];
students[j] = tmp;
}
}
}
printf("Students sorted by score\n");
}
void sort_by_id() {
for (int i = 0; i < num_students - 1; i++) {
for (int j = i + 1; j < num_students; j++) {
if (strcmp(students[i].id, students[j].id) > 0) {
struct student tmp = students[i];
students[i] = students[j];
students[j] = tmp;
}
}
}
printf("Students sorted by ID\n");
}
int main() {
char filename[] = "students.txt";
load_students(filename);
printf("Welcome to Student Management System!\n");
while (1) {
printf("\nMenu:\n");
printf("1. Add student\n");
printf("2. Remove student\n");
printf("3. Display all students\n");
printf("4. Compute statistics\n");
printf("5. Sort by score\n");
printf("6. Sort by ID\n");
printf("7. Save & quit\n");
int choice;
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
remove_student();
break;
case 3:
display_all_students();
break;
case 4:
compute_statistics();
break;
case 5:
sort_by_score();
break;
case 6:
sort_by_id();
break;
case 7:
save_students(filename);
printf("Goodbye!\n");
return 0;
default:
printf("Invalid choice, please try again\n");
}
}
}
```
注意,这只是一个简单的示例,实际应用中可能需要更多的功能和更复杂的逻辑。
阅读全文