#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;
小辰代写
- 粉丝: 4537
- 资源: 100
最新资源
- 职工上、下班交通费补贴规定.docx
- 房地产公司圣诞活动策划方案.docx
- 全球旅游与经济指标数据集,旅游影响因素数据集,旅游与收入数据(六千六百多条数据)
- 公司下午茶费用预算.xlsx
- 下午茶.docx
- 毕设和企业适用springboot计算机视觉平台类及在线平台源码+论文+视频.zip
- 2014年度体检项目.xls
- 年度员工体检项目.xls
- 年度体检.xlsx
- 毕设和企业适用springboot跨境电商平台类及虚拟现实体验平台源码+论文+视频.zip
- 毕设和企业适用springboot平台对接类及全球电商管理平台源码+论文+视频.zip
- 数据库-sqlite客户端-sqlite-访问sqlite数据库
- 住宅小区汽车超速检测及报警系统设计(单片机源码+图+报告)
- 毕设和企业适用springboot区块链技术类及客户关系管理平台源码+论文+视频.zip
- 毕设和企业适用springboot区块链技术类及音频处理平台源码+论文+视频.zip
- 毕设和企业适用springboot区块链交易平台类及交通信息平台源码+论文+视频.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈