编写学生管理系统,其中学生的信息有姓名(汉语拼音,最多20个字符,长度21的字符数组),
性别(男 / 女,用1表示男,2表示女,整数)、生日(19850101(年月日),整数)、身高(以m为单位,实数),
还需要处理C语言、微积分两门课的成绩(整数),请编写程序实现功能:
输入学生的人数和每个学生的信息;输出每门课程的总平均成绩、最高分和最低分,以及获得最高分的学生的信息。
需要注意的是某门课程最高分的学生可能不只一人。
输入输出格式要求:
身高输出时保留两位小数,请按照例子中进行输出,请勿输出其他字符
例如:
输入:3 zhangsan 1 19910101 1.85 85 90 lisi 1 19920202 1.56 89 88 wangwu 2 19910303 1.6 89 90回车
#include<stdio.h>
typedef struct stu {
char name[21];
int sex;
long int birth;
float hight;
int C;
int calculus;
};
int main()
{
stu student[10];
int N;
scanf("%d", &N);
getchar();
long long int C_average = 0, C_max = 0, C_min = 100, Calculus_average = 0, Calculus_max = 0, Calculus_min = 100;
int pC_max[100] = {};
int pCalculus_max[100] = {};
int count_C_max=0;
int count_Calculus_max = 0;
//用来记录谁拿了最高分
//输入:3 zhangsan 1 19910101 1.85 85 90 lisi 1 19920202 1.56 89 88 wangwu 2 19910303 1.6 89 90回车
for (int i = 0; i < N; i++)
{
char c;
int j = 0;
while (1)
{
c = getchar();
if (j == 0 && c == ' ') continue;
else if (c == ' ') break;
student[i].name[j++] = c;
}
student[i].name[j] = '\0';
scanf("%d%d%f%d%d"
, &student[i].sex, &student[i].birth, &student[i].hight, &student[i].C, &student[i].calculus);
//计算分数之和
C_average += student[i].C;
Calculus_average += student[i].calculus;
//记录最高分
if (C_max == student[i].C) pC_max[count_C_max++] = i;//若同为最高分,记录
if (C_max < student[i].C)
{
C_max = student[i].C;
pC_max[0] = i;
count_C_max = 1;
}
if (Calculus_max == student[i].calculus) pCalculus_max[count_Calculus_max++] = i;//若同为最高分,记录
if (Calculus_max < student[i].calculus)
{
Calculus_max = student[i].calculus;
pCalculus_max[0] = i;
count_Calculus_max = 1;
}
//记录最低分
if(C_min>student[i].C) C_min = student[i].C;
if(Calculus_min>student[i].calculus) Calculus_min = student[i].calculus;
}
//计算平均分
C_average /= N;
Calculus_average /= N;
printf("C_average:%d\n", C_average);
printf("C_max:%d\n", C_max);
for (int i = 0; i < count_C_max; i++)
{
printf("%s %d %d %.2f %d %d\n",
student[pC_max[i]].name, student[pC_max[i]].sex, student[pC_max[i]].birth, student[pC_max[i]].hight,
student[pC_max[i]].C, student[pC_max[i]].calculus);
}
printf("C_min:%d\n", C_min);
printf("Calculus_average:%d\n", Calculus_average);
printf("Calculus_max:%d\n", Calculus_max);
for (int i = 0; i < count_Calculus_max; i++)
{
printf("%s %d %d %.2f %d %d\n", student[pCalculus_max[i]].name, student[pCalculus_max[i]].sex, student[pCalculus_max[i]].birth, student[pCalculus_max[i]].hight, student[pCalculus_max[i]].C, student[pCalculus_max[i]].calculus);
}
printf("Calculus_min:%d\n", Calculus_min);
//输出:
//C_average : 87回车
//C_max : 89回车
//lisi 1 19920202 1.56 89 88回车
//wangwu 2 19910303 1.60 89 90回车
//C_min : 85回车
//Calculus_average : 89回车
//Calculus_max : 90回车
//zhangsan 1 19910101 1.85 85 90回车
//wangwu 2 19910303 1.60 89 90回车
//Calculus_min : 88回车
}