学生信息管理系统下设管理员、教师、学生三个部分。管理员可以对教师和学生的身份进行管理。教师的权限在成绩维护与查询,其中成绩维护包括录入 、修改、删除、添加,查询功能包括各种方式的成绩查询、统计。学生端则可以查询单科成绩或总成绩
时间: 2023-12-20 21:07:10 浏览: 59
好的,以下是使用 C 语言实现的学生信息管理系统的部分代码,包括管理员、教师和学生三个部分的功能。为了简化代码,这里使用了结构体和数组来存储学生和教师的信息。
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT 100
#define MAX_TEACHER 100
// 学生和教师信息结构体
struct student {
char name[20];
int id;
int grade;
int class;
char phone[20];
int math;
int english;
int physics;
int chemistry;
int total;
};
struct teacher {
char name[20];
char password[20];
};
// 全局变量
struct student students[MAX_STUDENT];
int student_cnt = 0;
struct teacher teachers[MAX_TEACHER];
int teacher_cnt = 0;
// 函数声明
void admin_login();
void admin_menu();
void add_teacher();
void add_student();
void modify_student();
void delete_student();
void query_student();
void teacher_login();
void teacher_menu();
void add_score();
void modify_score();
void delete_score();
void query_score();
int main() {
while (1) {
printf("请选择用户类型:\n");
printf("1. 管理员\n");
printf("2. 教师\n");
printf("3. 学生\n");
printf("4. 退出\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1: admin_login(); break;
case 2: teacher_login(); break;
case 3: // 学生功能暂未实现
case 4: return 0;
default: printf("无效选择,请重新输入。\n");
}
}
}
// 管理员登录
void admin_login() {
printf("请输入管理员账号和密码:\n");
char username[20], password[20];
scanf("%s %s", username, password);
if (strcmp(username, "admin") == 0 && strcmp(password, "admin") == 0) {
admin_menu();
} else {
printf("账号或密码错误,请重新登录。\n");
}
}
// 管理员菜单
void admin_menu() {
while (1) {
printf("请选择操作:\n");
printf("1. 添加教师\n");
printf("2. 添加学生\n");
printf("3. 修改学生信息\n");
printf("4. 删除学生信息\n");
printf("5. 查询学生信息\n");
printf("6. 退出\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1: add_teacher(); break;
case 2: add_student(); break;
case 3: modify_student(); break;
case 4: delete_student(); break;
case 5: query_student(); break;
case 6: return;
default: printf("无效选择,请重新输入。\n");
}
}
}
// 添加教师
void add_teacher() {
if (teacher_cnt >= MAX_TEACHER) {
printf("教师信息已满,无法添加。\n");
return;
}
printf("请输入教师姓名和密码:\n");
char name[20], password[20];
scanf("%s %s", name, password);
strcpy(teachers[teacher_cnt].name, name);
strcpy(teachers[teacher_cnt].password, password);
teacher_cnt++;
printf("教师信息添加成功。\n");
}
// 添加学生
void add_student() {
if (student_cnt >= MAX_STUDENT) {
printf("学生信息已满,无法添加。\n");
return;
}
printf("请输入学生姓名、学号、年级、班级和联系方式:\n");
char name[20], phone[20];
int id, grade, class;
scanf("%s %d %d %d %s", name, &id, &grade, &class, phone);
strcpy(students[student_cnt].name, name);
students[student_cnt].id = id;
students[student_cnt].grade = grade;
students[student_cnt].class = class;
strcpy(students[student_cnt].phone, phone);
students[student_cnt].math = -1;
students[student_cnt].english = -1;
students[student_cnt].physics = -1;
students[student_cnt].chemistry = -1;
students[student_cnt].total = -4;
student_cnt++;
printf("学生信息添加成功。\n");
}
// 修改学生信息
void modify_student() {
printf("请输入学生学号:\n");
int id;
scanf("%d", &id);
int index = -1;
for (int i = 0; i < student_cnt; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index < 0) {
printf("找不到学生信息,请重新输入。\n");
return;
}
printf("请输入修改后的学生姓名、年级、班级和联系方式:\n");
char name[20], phone[20];
int grade, class;
scanf("%s %d %d %s", name, &grade, &class, phone);
strcpy(students[index].name, name);
students[index].grade = grade;
students[index].class = class;
strcpy(students[index].phone, phone);
printf("学生信息修改成功。\n");
}
// 删除学生信息
void delete_student() {
printf("请输入学生学号:\n");
int id;
scanf("%d", &id);
int index = -1;
for (int i = 0; i < student_cnt; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index < 0) {
printf("找不到学生信息,请重新输入。\n");
return;
}
for (int i = index; i < student_cnt - 1; i++) {
students[i] = students[i + 1];
}
student_cnt--;
printf("学生信息删除成功。\n");
}
// 查询学生信息
void query_student() {
printf("请输入学生学号:\n");
int id;
scanf("%d", &id);
int index = -1;
for (int i = 0; i < student_cnt; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index < 0) {
printf("找不到学生信息,请重新输入。\n");
return;
}
printf("学生姓名:%s\n", students[index].name);
printf("学生学号:%d\n", students[index].id);
printf("学生年级:%d\n", students[index].grade);
printf("学生班级:%d\n", students[index].class);
printf("联系方式:%s\n", students[index].phone);
}
// 教师登录
void teacher_login() {
printf("请输入教师姓名和密码:\n");
char name[20], password[20];
scanf("%s %s", name, password);
int index = -1;
for (int i = 0; i < teacher_cnt; i++) {
if (strcmp(teachers[i].name, name) == 0 && strcmp(teachers[i].password, password) == 0) {
index = i;
break;
}
}
if (index < 0) {
printf("教师姓名或密码错误,请重新登录。\n");
return;
}
teacher_menu();
}
// 教师菜单
void teacher_menu() {
while (1) {
printf("请选择操作:\n");
printf("1. 添加成绩\n");
printf("2. 修改成绩\n");
printf("3. 删除成绩\n");
printf("4. 查询成绩\n");
printf("5. 退出\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1: add_score(); break;
case 2: modify_score(); break;
case 3: delete_score(); break;
case 4: query_score(); break;
case 5: return;
default: printf("无效选择,请重新输入。\n");
}
}
}
// 添加成绩
void add_score() {
printf("请输入学生学号和四门课程的成绩:\n");
int id, math, english, physics, chemistry;
scanf("%d %d %d %d %d", &id, &math, &english, &physics, &chemistry);
int index = -1;
for (int i = 0; i < student_cnt; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index < 0) {
printf("找不到学生信息,请重新输入。\n");
return;
}
students[index].math = math;
students[index].english = english;
students[index].physics = physics;
students[index].chemistry = chemistry;
students[index].total = math + english + physics + chemistry;
printf("成绩添加成功。\n");
}
// 修改成绩
void modify_score() {
printf("请输入学生学号和需要修改的课程:\n");
int id;
char course[20];
scanf("%d %s", &id, course);
int index = -1;
for (int i = 0; i < student_cnt; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index < 0) {
printf("找不到学生信息,请重新输入。\n");
return;
}
int score;
if (strcmp(course, "math") == 0) {
printf("请输入修改后的数学成绩:\n");
scanf("%d", &score);
students[index].math = score;
} else if (strcmp(course, "english") == 0) {
printf("请输入修改后的英语成绩:\n");
scanf("%d", &score);
students[index].english = score;
} else if (strcmp(course, "physics") == 0) {
printf("请输入修改后的物理成绩:\n");
scanf("%d", &score);
students[index].physics = score;
} else if (strcmp(course, "chemistry") == 0) {
printf("请输入修改后的化学成绩:\n");
scanf("%d", &score);
students[index].chemistry = score;
} else {
printf("无效课程,请重新输入。\n");
return;
}
students[index].total = students[index].math + students[index].english + students[index].physics + students[index].chemistry;
printf("成绩修改成功。\n");
}
// 删除成绩
void delete_score() {
printf("请输入学生学号和需要删除的课程:\n");
int id;
char course[20];
scanf("%d %s", &id, course);
int index = -1;
for (int i = 0; i < student_cnt; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index < 0) {
printf("找不到学生信息,请重新输入。\n");
return;
}
if (strcmp(course, "math") == 0) {
students[index].math = -1;
} else if (strcmp(course, "english") == 0) {
students[index].english = -1;
} else if (strcmp(course, "physics") == 0) {
students
阅读全文