C语言编写密码验证进入管理员界面。 2. 菜单显示浏览、增删改及退出系统等功能,用户通过键入数字或者字母实现 功能选择,进而进入相应功能 3. 浏览某专业全体学生的所有信息及总排名,根据学生的总分进行排序输出。 4. 单科课程排序输出。 5. 对学生信息的增、删、改。 6. 对某课程的成绩数据编辑。 7. 其他功能
时间: 2024-02-03 10:13:10 浏览: 22
这是一个比较复杂的程序,需要有一定的编程基础才能完成。以下是一个简单的示例程序,供参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
#define MAX_NAME_LEN 20
#define MAX_COURSE_NUM 3
typedef struct student {
int id; // 学号
char name[MAX_NAME_LEN]; // 姓名
int scores[MAX_COURSE_NUM]; // 成绩数组
int total_score; // 总成绩
} Student;
int student_count = 0; // 学生总数
Student students[MAX_STUDENT_NUM]; // 学生数组
// 显示菜单
void show_menu() {
printf("\n\n");
printf("1. 浏览学生信息及总排名\n");
printf("2. 单科课程排序输出\n");
printf("3. 增加学生信息\n");
printf("4. 删除学生信息\n");
printf("5. 修改学生信息\n");
printf("6. 编辑某课程成绩数据\n");
printf("7. 退出系统\n");
}
// 获取学生总分
int get_total_score(Student *student) {
int total = 0;
for (int i = 0; i < MAX_COURSE_NUM; i++) {
total += student->scores[i];
}
return total;
}
// 显示学生信息
void show_student_info(Student *student) {
printf("学号:%d\t姓名:%s\t成绩:%d %d %d\t总分:%d\n",
student->id, student->name,
student->scores[0], student->scores[1], student->scores[2],
student->total_score);
}
// 显示所有学生信息及总排名
void show_all_students() {
// 计算总分
for (int i = 0; i < student_count; i++) {
students[i].total_score = get_total_score(&students[i]);
}
// 排序
for (int i = 0; i < student_count - 1; i++) {
for (int j = i + 1; j < student_count; j++) {
if (students[i].total_score < students[j].total_score) {
Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
// 显示信息
printf("\n所有学生信息及总排名:\n");
for (int i = 0; i < student_count; i++) {
show_student_info(&students[i]);
}
}
// 单科课程排序输出
void sort_by_course() {
int course;
printf("请输入课程编号(1-%d):", MAX_COURSE_NUM);
scanf("%d", &course);
while (course < 1 || course > MAX_COURSE_NUM) {
printf("输入有误,请重新输入(1-%d):", MAX_COURSE_NUM);
scanf("%d", &course);
}
// 排序
for (int i = 0; i < student_count - 1; i++) {
for (int j = i + 1; j < student_count; j++) {
if (students[i].scores[course - 1] < students[j].scores[course - 1]) {
Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
// 显示信息
printf("\n按照课程%d成绩排序:\n", course);
for (int i = 0; i < student_count; i++) {
show_student_info(&students[i]);
}
}
// 增加学生信息
void add_student() {
if (student_count >= MAX_STUDENT_NUM) {
printf("学生数量已达到上限,无法添加!\n");
return;
}
Student new_student;
printf("请输入学号:");
scanf("%d", &new_student.id);
printf("请输入姓名:");
scanf("%s", new_student.name);
for (int i = 0; i < MAX_COURSE_NUM; i++) {
printf("请输入课程%d成绩:", i + 1);
scanf("%d", &new_student.scores[i]);
}
students[student_count++] = new_student;
printf("添加成功!\n");
}
// 删除学生信息
void delete_student() {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < student_count; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生!\n");
return;
}
for (int i = index; i < student_count - 1; i++) {
students[i] = students[i + 1];
}
student_count--;
printf("删除成功!\n");
}
// 修改学生信息
void modify_student() {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < student_count; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生!\n");
return;
}
printf("请输入新的姓名(原姓名:%s):", students[index].name);
scanf("%s", students[index].name);
for (int i = 0; i < MAX_COURSE_NUM; i++) {
printf("请输入新的课程%d成绩(原成绩:%d):", i + 1, students[index].scores[i]);
scanf("%d", &students[index].scores[i]);
}
printf("修改成功!\n");
}
// 编辑某课程成绩数据
void edit_course_scores() {
int course;
printf("请输入要编辑的课程编号(1-%d):", MAX_COURSE_NUM);
scanf("%d", &course);
while (course < 1 || course > MAX_COURSE_NUM) {
printf("输入有误,请重新输入(1-%d):", MAX_COURSE_NUM);
scanf("%d", &course);
}
printf("请输入要编辑成绩的学生学号:");
int id;
scanf("%d", &id);
int index = -1;
for (int i = 0; i < student_count; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生!\n");
return;
}
printf("请输入新的课程%d成绩(原成绩:%d):", course, students[index].scores[course - 1]);
scanf("%d", &students[index].scores[course - 1]);
printf("修改成功!\n");
}
int main() {
// 验证密码
char password[20];
printf("请输入密码:");
scanf("%s", password);
if (strcmp(password, "123456") != 0) {
printf("密码错误,无法进入系统!\n");
return 0;
}
// 显示菜单
show_menu();
// 处理用户输入
char choice;
printf("请输入菜单编号:");
scanf("%s", &choice);
while (choice != '7') {
switch (choice) {
case '1':
show_all_students();
break;
case '2':
sort_by_course();
break;
case '3':
add_student();
break;
case '4':
delete_student();
break;
case '5':
modify_student();
break;
case '6':
edit_course_scores();
break;
default:
printf("输入有误,请重新输入!\n");
break;
}
// 显示菜单
show_menu();
// 处理用户输入
printf("请输入菜单编号:");
scanf("%s", &choice);
}
printf("感谢使用本系统!\n");
return 0;
}
```
以上程序实现了一个简单的学生成绩管理系统,具有浏览、增删改、排序等功能。你可以在此基础上进行改进,例如增加文件存储功能、优化用户界面等。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)
![](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)