#include <stdio.h>
typedef struct Student
{
char name[10];
float math;//高数
float english;//英语
float physics;//大学物理
float clanguage;//C语言
float maogai;//毛概
}STU;
void averagescore(STU *ps)//每个课程的平均成绩
{
float average=0;
int i;
printf("高数平均成绩:");
for(i=0;i<4;i++)
{
average=average+(ps[i].math)/4;
}
printf("%.1f",average);
putchar(' ');
printf("英语平均成绩:");
for(i=0,average=0;i<4;i++)
{
average=average+(ps[i].english)/4;
}
printf("%.1f",average);
putchar(' ');
printf("大学物理平均成绩:");
for(i=0,average=0;i<4;i++)
{
average=average+(ps[i].physics)/4;
}
printf("%.1f",average);
putchar(' ');
printf("c语言平均成绩:");
for(i=0,average=0;i<4;i++)
{
average=average+(ps[i].clanguage)/4;
}
printf("%.1f",average);
putchar(' ');
printf("毛概平均成绩:");
for(i=0,average=0;i<4;i++)
{
average=average+(ps[i].maogai)/4;
}
printf("%.1f",average);
putchar(' ');
}
void Studentscore(STU *ps)//每个学生的平均成绩
{
float score;
int i;
for(i=0;i<4;i++)
{
score=(ps[i].math+ps[i].english+ps[i].physics+ps[i].clanguage+ps[i].maogai)/5;
printf("%s的平均成绩为%.1f ",ps[i].name,score);
}
}
void Sscore(STU *ps)//全部课程成绩高于85分的学生
{
int i;
for(i=0;i<4;i++)
{
if(ps[i].math>=85&&ps[i].english>=85&&ps[i].physics>=85&&ps[i].clanguage>=85&&ps[i].maogai>=85)
printf("%s ",ps[i].name);
}
putchar(' ');
}
void main()
{
STU s[4]={
{"张三",88,86,85,89,84},
{"李四",86,89,94,95,89},
{"李华",89,88,99,98,88},
{"小明",85,84,87,99,100}
};
int i;
printf("------------------------------------------- ");
printf("| 功能选定 | ");
printf("------------------------------------------- ");
printf("|指令| | 功能 | ");
printf("------------------------------------------- ");
printf("| 0 | | 退出 | ");
printf("------------------------------------------- ");
printf("| 1 | | 每个学生的平均成绩 | ");
printf("------------------------------------------- ");
printf("| 2 | | 每门课的平均成绩 | ");
printf("------------------------------------------- ");
printf("| 3 | |全部课程成绩高于85分学生| ");
printf("------------------------------------------- ");
printf("请输入您的指令:");
while(1)
{
scanf("%d",&i);
if(i==1)
{
printf("每个学生的平均成绩: ");
Studentscore(s);
putchar(' ');
printf("请输入您的指令:");
continue;
}
else if(i==2)
{
printf("每门课的平均成绩: ");
averagescore(s);
putchar(' ');
printf("请输入您的指令:");
continue;
}
else if(i==3)
{
printf("全部课程成绩高于85分学生: ");
Sscore(s);
putchar(' ');
printf("请输入您的指令:");
continue;
}
else if(i==0)
{
printf("感谢您的使用。");
break;
}
else
{
printf("您输入的指令有误请重新输入:");
continue;
}
}
}