c语言课程设计学生成绩管理系统。 学生基本信息包括学号,姓名,性别,三门成绩,请编程序,实现如下功能:

2024-10-29 05:21:29
推荐回答(3个)
回答1:

临时写的,没有编译,应该差不离。

#include

#define MAX_CORE_NUM 3
#define MAX_STU_NUM 100
struct stu_info_t
{
int no;
char name[50];
int is_male;
int core[MAX_CORE_NUM];
int core_total;
int rank;
};
int class_min_stu[MAX_CORE_NUM];
int class_max_stu[MAX_CORE_NUM];
struct stu_info_t stu_info[MAX_STU_NUM];
int stu_num = 0;
int input_stu_info()
{
char q = 0;
int i = 0;
int j = 0;
char c = 0;

printf("请输入所有学生信息:\n");
i = 0;
while (q != 'q' && q != 'Q' && i < MAX_STU_NUM)
{
printf("学号:");
scanf("%d", &(stu_info[i].no));
printf("姓名:");
scanf("%s", stu_info[i].name);
printf("性别(M/m - 男生,F/f - 女生):");
scanf("%c", &c);
if (c == 'M' || c == 'c')
stu_info[i].is_male = 1;
else
stu_info[i].is_male = 0;
stu_info[i].core_total = 0;
for (j = 0; j < MAX_CORE_NUM; j++)
{
printf("课程%d得分:", j+1);
scanf("%d", &(stu_info[i].core[j]));
stu_info[i].core_total += stu_info[i].core[j];
}
i++;
if (i >= MAX_STU_NUM)
{
printf("最多输入%d个学生信息\n", MAX_STU_NUM);
break;
}
printf("退出(Q/q):");
scanf("%c", &q);
}
stu_num = i;
return 0;
}
int save_stu_info()
{
int i = 0;
int j = 0;
FILE * fp = NULL;
fp = fopen("students.txt", "rw");
if (fp == NULL)
return -1;
fprintf(fp, "\t学号\t姓名\t性别");
for (j = 0; j < MAX_CORE_NUM; j++)
{
fprintf(fp, "\t课程%d", j+1);
}
fprintf(fp, "\r\n");
for (i = 0; i < stu_num; i++)
{
fprintf(fp, "\t%d\t%s\t%s", stu_info[i].no, stu_info[i].name, (stu_info[i].is_male ? "男" : "女"));
for (j = 0; j < MAX_CORE_NUM; j++)
{
fprintf(fp, "\t%d", stu_info[i].core[j]);
}
fprintf(fp, "\r\n");
}
fclose(fp);
return 0;
}
int cal_rank()
{
int i = 0;
int j = 0;
int class_min;
int class_max;
struct stu_info_t t;
for (i = 0; i < stu_num - 1; i++)
{
for (j = i + 1; j < stu_num; j++)
{
if (stu_info[i].core_total < stu_info[j].core_total)
{
memcpy(&t, &stu_info[j], sizeof(struct stu_info_t));
memcpy(&stu_info[j], &stu_info[i], sizeof(struct stu_info_t));
memcpy(&stu_info[i], &t, sizeof(struct stu_info_t));
}
}
}
for (i = 0; i < stu_num; i++)
{
stu_info[i].rank = i + 1;
}
for (j = 0; j < MAX_CORE_NUM; j++)
{
class_min = 0;
class_max = 10000;
for (i = 0; i < stu_num; i++)
{
if (stu_info[i].core[j] < class_min)
{
class_min = stu_info[i].core[j];
class_min_stu[j] = i;
}
if (stu_info[i].core[j] > class_max)
{
class_max = stu_info[i].core[j];
class_max_stu[j] = i;
}
}
}
return 0;
}

int output_total()
{
int i = 0;
printf("\t学号\t姓名\t总分\t排名\n");
for (i = 0; i < stu_num; i++)
{
printf("\t%d\t%s\t%d\t%d\n", stu_info[i].no, stu_info[i].name, stu_info[i].core_total, stu_info[i].rank);
}
return 0;
}
int output_class()
{
int i = 0;
int j = 0;
int core = 0;
for (j = 0; j < MAX_CORE_NUM; j++)
{
core = stu_info[class_max_stu[j]].core[j];
printf("课程%d最高分:%d\n", j+1, core);
printf("\t学号\t姓名\n");
for (i = 0; i < stu_num; i++)
{
if (stu_info[i].core[j] == core)
{
printf("\t%d\t%s\n", stu_info[i].no, stu_info[i].name);
}
}
}
for (j = 0; j < MAX_CORE_NUM; j++)
{
core = stu_info[class_min_stu[j]].core[j];
printf("课程%d最低分:%d\n", j+1, core);
printf("\t学号\t姓名\n");
for (i = 0; i < stu_num; i++)
{
if (stu_info[i].core[j] == core)
{
printf("\t%d\t%s\n", stu_info[i].no, stu_info[i].name);
}
}
}
return 0;
}
void main()
{
input_stu_info();
save_stu_info();
cal_rank();
output_total();
output_class();
return;
}

回答2:

用数组,和链表,排序。

回答3:

我有源码。。明天开电脑给你