#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SUBJECTS 6
#define MAX_STUDENTS 30
#define MAX_NAME_LENGTH 50
struct Student {
char id[20];
char name[MAX_NAME_LENGTH];
int scores[MAX_SUBJECTS];
float totalScore;
float averageScore;
};
//测试用例
void ceshi(struct Student* students, char subjects[][50], int* numStudents, int* numSubjects){
// 假设有三名学生
*numStudents=3;
// 假设每位学生有三门课程成绩
*numSubjects=3;
// 填充学生信息和成绩
strcpy(students[0].id, "001");
strcpy(students[0].name, "张三");
students[0].scores[0] = 80;
students[0].scores[1] = 90;
students[0].scores[2] = 85;
students[0].totalScore = 80+90+85;
students[0].averageScore = students[0].totalScore/3;
strcpy(students[1].id, "002");
strcpy(students[1].name, "李四");
students[1].scores[0] = 75;
students[1].scores[1] = 85;
students[1].scores[2] = 90;
students[1].totalScore = 75+85+90;
students[1].averageScore = students[1].totalScore/3;
strcpy(students[2].id, "003");
strcpy(students[2].name, "王五");
students[2].scores[0] = 77;
students[2].scores[1] = 81;
students[2].scores[2] = 93;
students[2].totalScore = 77+81+93;
students[2].averageScore = students[1].totalScore/3;
strcpy(subjects[0], "语文");
strcpy(subjects[1], "数学");
strcpy(subjects[2], "英语");
printf("\n导入成功!");
printf("输入任意内容返回主菜单:");
scanf("%s");
}
//显示菜单
void displayMenu() {
system("cls");
printf("1. Input record(录入学生信息)\n");
printf("2. Calculate total and average score of every course(打印每门课程的总分和平均分)\n");
printf("3. Calculate total and average score of every student(打印每个学生的总分和平均分)\n");
printf("4. Sort in descending order by total score of every student(按每个学生的总分降序排列)\n");
printf("5. Sort in ascending order by number(按学号由小到大排序)\n");
printf("6. Sort in dictionary order by name(按姓名的字典顺序排序)\n");
printf("7. Search by number(按学号查询学生信息)\n");
printf("8. Search by name(按姓名查询学生信息)\n");
printf("9. Statistic analysis for every course(每门课程统计分析)\n");
printf("10. List record (输出学生信息)\n");
printf("11. 一键导入测试数据\n");
printf("0. Exit(退出)\n");
printf("Please input your choice(请输入您的选择): ");
}
//录入学生信息
void storeStudentInfo(int* numStudents,struct Student* students,int* numSubjects,char (*subjects)[50]) {
int i,j;
// 输入学生人数
printf("请输入学生人数(不超过30): ");
scanf("%d", &*numStudents);
// 输入科目数
printf("请输入科目数(不超过6): ");
scanf("%d", &*numSubjects);
// 输入科目名称
for (i = 0; i < *numSubjects; i++) {
printf("请输入第 %d 门科目的名称: ", i+1);
scanf("%s", &subjects[i]);
};
// 输入学生信息
for (i = 0; i < *numStudents; i++) {
printf("hello!");
//初始化数据
students[i].totalScore=0;
students[i].averageScore=0;
// 输入学号和姓名
printf("\n请输入第 %d 位学生的学号: ", i + 1);
scanf("%s", students[i].id);
printf("请输入第 %d 位学生的姓名: ", i + 1);
scanf("%s", students[i].name);
// 输入每门科目的成绩
for (j = 0; j < *numSubjects; j++) {
printf("请输入第 %d 位学生的 %s 成绩: ", i + 1, subjects[j]);
scanf("%d", &students[i].scores[j]);
students[i].totalScore += students[i].scores[j];
};
// 计算平均成绩
students[i].averageScore = (float)students[i].totalScore / *numSubjects;
};
// 打印学生信息
printf("\n学生信息:\n");
printf("%-10s %-10s %-10s %-10s\n", "学号", "姓名", "总成绩", "平均成绩");
for (i = 0; i < *numStudents; i++) {
struct Student *student = &students[i];
printf("|%-10s|%-10s|%-10.2f|%-10.2f|\n", student->id, student->name, student->totalScore, student->averageScore);
}
printf("输入任意内容返回主菜单:");
scanf("%s");
};
//打印每科总分和平均分
void calculateCourseScores(int numStudents, struct Student* students, int numSubjects, char subjects[][50]) {
int i, j;
// 打印科目名称
printf("科目名称\t总分\t平均分\n");
// 计算每门科目的总分和平均分
for (j = 0; j < numSubjects; j++) {
int totalScore = 0;
float averageScore = 0.0;
// 计算总分
for (i = 0; i < numStudents; i++) {
totalScore += students[i].scores[j];
}
// 计算平均分
averageScore = (float)totalScore / numStudents;
// 打印科目总分和平均分
printf("%s\t\t%d\t%.2f\n", subjects[j], totalScore, averageScore);
}
printf("输入任意内容返回主菜单:");
scanf("%s");
}
//打印每个学生的总分和平均分
void calculateStudentScores(int numStudents, struct Student* students, int numSubjects) {
int i;
// 打印学生总分和平均分
printf("|学生姓名\t|总分\t|平均分\n");
for (i = 0; i < numStudents; i++) {
printf("|%s\t\t|%.2f\t|%.2f|\n", students[i].name, students[i].totalScore, students[i].averageScore);
}
printf("输入任意内容返回主菜单:");
scanf("%s");
}
//学生总分由高到低排序
void sortStudentsByTotalScore(int numStudents, struct Student* students) {
int i, j;
struct Student temp;
// 使用冒泡排序按总分由高到低排序学生
for (i = 0; i < numStudents - 1; i++) {
for (j = 0; j < numStudents - i - 1; j++) {
if (students[j].totalScore < students[j + 1].totalScore) {
temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
};
};
};
// 打印排序后的学生信息
printf("学生ID\t\t姓名\t\t总分\t\t平均分\n");
for (i = 0; i < numStudents; i++) {
printf("%s\t\t%s\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].totalScore, students[i].averageScore);
}
printf("输入任意内容返回主菜单:");
scanf("%s");
}
//学生学号由小到大
void sortStudentsById(int numStudents, struct Student* students) {
int i, j;
struct Student temp;
// 使用冒泡排序按学生id由小到大排序
for (i = 0; i < numStudents - 1; i++) {
for (j = 0; j < numStudents - i - 1; j++) {
if (strcmp(students[j].id, students[j + 1].id) > 0) {
temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
// 打印排序后的学生信息
printf("学生ID\t\t姓名\t\t总分\t\t平均分\n");
for (i = 0; i < numStudents; i++) {
printf("%s\t\t%s\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].totalScore, students[i].averageScore);
}
printf("输入任意内容返回主菜单:");
scanf("%s");
}
//按学生姓名的字典顺序排序并打印
void printStudentInfoByName(int numStudents, struct Student* students) {
int i, j;
struct Student temp;
// 使用冒泡排序按学生id由小到大排序
for (i = 0; i < numStudents - 1; i++) {
for (j = 0; j < numStudents - i - 1; j++) {
if (strcmp(students[j].name, students[j + 1].name) > 0) {
temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
小辰代写
- 粉丝: 4191
- 资源: 100
最新资源
- HtmlMate标签使用详解中文最新版本
- ATM机旁危险物品检测数据集VOC+YOLO格式1251张5类别.zip
- 网页优化meta标签使用方法及规则中文最新版本
- 网页万能复制 浏览器插件
- IMG_20241123_093226.jpg
- JavaScript的表白代码项目源码.zip
- springboot vue3前后端分离开发入门介绍,分享给有需要的人,仅供参考
- 全国297个地级市城市辖区数据1990-2022年末实有公共汽车出租车数人均城市道路建成区绿地面积供水供气总量医院卫生机构数医生人数GDP第一二三产业增加值分行业从业人员水资源农产品产量利用外资
- Python客流量时间序列预测模型.zip
- 故障预测-灰色预测模型C++源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈