用dev C写一个学生管理系统
时间: 2023-12-14 17:04:42 浏览: 23
好的,学生管理系统可以分为以下几个模块:
1. 学生信息录入模块
2. 学生信息查询模块
3. 学生信息修改模块
4. 学生信息删除模块
5. 学生信息统计模块
下面是一个简单的学生管理系统的代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
typedef struct {
int id;
char name[20];
int age;
char gender;
float score;
} Student;
Student studentList[MAX_STUDENT_NUM];
int studentNum = 0;
void addStudent() {
if (studentNum >= MAX_STUDENT_NUM) {
printf("Student list is full.\n");
return;
}
printf("Please enter student information:\n");
printf("ID: ");
scanf("%d", &studentList[studentNum].id);
printf("Name: ");
scanf("%s", studentList[studentNum].name);
printf("Age: ");
scanf("%d", &studentList[studentNum].age);
printf("Gender (M/F): ");
scanf(" %c", &studentList[studentNum].gender);
printf("Score: ");
scanf("%f", &studentList[studentNum].score);
studentNum++;
printf("Add student successfully.\n");
}
void queryStudent() {
int id;
printf("Please enter the student ID: ");
scanf("%d", &id);
for (int i = 0; i < studentNum; i++) {
if (studentList[i].id == id) {
printf("ID: %d\n", studentList[i].id);
printf("Name: %s\n", studentList[i].name);
printf("Age: %d\n", studentList[i].age);
printf("Gender: %c\n", studentList[i].gender);
printf("Score: %.2f\n", studentList[i].score);
return;
}
}
printf("Student not found.\n");
}
void modifyStudent() {
int id;
printf("Please enter the student ID: ");
scanf("%d", &id);
for (int i = 0; i < studentNum; i++) {
if (studentList[i].id == id) {
printf("Please enter new student information:\n");
printf("ID: ");
scanf("%d", &studentList[i].id);
printf("Name: ");
scanf("%s", studentList[i].name);
printf("Age: ");
scanf("%d", &studentList[i].age);
printf("Gender (M/F): ");
scanf(" %c", &studentList[i].gender);
printf("Score: ");
scanf("%f", &studentList[i].score);
printf("Modify student information successfully.\n");
return;
}
}
printf("Student not found.\n");
}
void deleteStudent() {
int id;
printf("Please enter the student ID: ");
scanf("%d", &id);
for (int i = 0; i < studentNum; i++) {
if (studentList[i].id == id) {
for (int j = i; j < studentNum - 1; j++) {
studentList[j] = studentList[j + 1];
}
studentNum--;
printf("Delete student successfully.\n");
return;
}
}
printf("Student not found.\n");
}
void statStudent() {
float totalScore = 0;
float avgScore = 0;
float maxScore = 0;
float minScore = 100;
for (int i = 0; i < studentNum; i++) {
totalScore += studentList[i].score;
if (studentList[i].score > maxScore) {
maxScore = studentList[i].score;
}
if (studentList[i].score < minScore) {
minScore = studentList[i].score;
}
}
if (studentNum > 0) {
avgScore = totalScore / studentNum;
}
printf("Total number of students: %d\n", studentNum);
printf("Average score: %.2f\n", avgScore);
printf("Max score: %.2f\n", maxScore);
printf("Min score: %.2f\n", minScore);
}
int main() {
int choice;
while (1) {
printf("\n");
printf("1. Add student\n");
printf("2. Query student\n");
printf("3. Modify student\n");
printf("4. Delete student\n");
printf("5. Stat student\n");
printf("0. Exit\n");
printf("Please enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
queryStudent();
break;
case 3:
modifyStudent();
break;
case 4:
deleteStudent();
break;
case 5:
statStudent();
break;
case 0:
printf("Goodbye!\n");
exit(0);
default:
printf("Invalid choice.\n");
break;
}
}
return 0;
}
```
这个学生管理系统可以实现基本的添加、查询、修改、删除和统计操作。你可以根据需求进行修改和扩展。