在评定奖学金时,学校通常会综合考虑学生的专业课成绩和德育成绩,并将两者之间设置一定的比例以便合成学生的综合成绩,然后按照综合成绩的排名顺序确定不同等级的奖学金获得者的名单。 编程实现上述奖学金评定过程,具体要求: (1)从文件rawscore.txt中读入学生人数、考核科目数及每位学生各科目分数等基本信息。 (2)根据读入的信息,计算出每位学生的专业课平均分。 (3)设置专业课成绩与德育成绩之间的比例、奖学金等级数、各等级获奖人数等基本信息。 (4)输出满足上述设置要求的奖学金获得者名单及基本信息等。
时间: 2024-03-14 10:46:37 浏览: 94
编程实现:(1) 键入某组学生(共 10 人)的学号、姓名、组成原理考试 成绩、数据结构考试成绩、汇编语言考试成绩
好的,那么我就为你提供一份实现上述要求的代码。请注意,以下代码可能需要根据具体的文件名、文件格式、比例、奖学金等级数和获奖人数等信息进行修改。同时,代码中可能存在一些细节问题,需要你自己进行测试和调试。希望对你有所帮助。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char name[20];
double averageScore;
double moralityScore;
double finalScore;
} Student;
int cmp(const void* a, const void* b) {
Student* studentA = (Student*)a;
Student* studentB = (Student*)b;
return studentB->finalScore - studentA->finalScore;
}
int main() {
FILE* inFile = fopen("rawscore.txt", "r");
if (!inFile) {
fprintf(stderr, "无法打开文件\n");
return 1;
}
int studentCount, subjectCount;
fscanf(inFile, "%d %d", &studentCount, &subjectCount);
Student* students = (Student*)malloc(studentCount * sizeof(Student));
for (int i = 0; i < studentCount; i++) {
fscanf(inFile, "%s", students[i].name);
double sum = 0;
for (int j = 0; j < subjectCount; j++) {
double score;
fscanf(inFile, "%lf", &score);
sum += score;
}
students[i].averageScore = sum / subjectCount;
fscanf(inFile, "%lf", &students[i].moralityScore);
}
double academicWeight, moralityWeight;
printf("请输入专业课成绩与德育成绩之间的比例(如0.7):");
scanf("%lf", &academicWeight);
moralityWeight = 1 - academicWeight;
for (int i = 0; i < studentCount; i++) {
students[i].finalScore = students[i].averageScore * academicWeight + students[i].moralityScore * moralityWeight;
}
qsort(students, studentCount, sizeof(Student), cmp);
int scholarshipLevelCount;
printf("请输入奖学金等级数:");
scanf("%d", &scholarshipLevelCount);
int* scholarshipLevelCounts = (int*)malloc(scholarshipLevelCount * sizeof(int));
for (int i = 0; i < scholarshipLevelCount; i++) {
printf("请输入%d等奖的获奖人数:", i + 1);
scanf("%d", &scholarshipLevelCounts[i]);
}
printf("\n奖学金获得者名单:\n");
for (int i = 0; i < scholarshipLevelCount; i++) {
printf("\n%d等奖:\n", i + 1);
for (int j = 0; j < scholarshipLevelCounts[i]; j++) {
printf("%s %.2lf\n", students[j].name, students[j].finalScore);
}
}
free(scholarshipLevelCounts);
free(students);
return 0;
}
```
阅读全文