#define AVERAGE_SCORE (90)
#define PER_SCORE (85)
typedef struct student
{
int iNum;
float fScore[5];
}STUDENT_ST;
int g_aSatisfy[100] = {0};
int InputPerStuInfo(int iNum, STUDENT_ST *pstStu)
{
printf("Input the %dst student num, math, Eng,c++,linearity and PE:\r\n", iNum+1);
scanf("%d%f%f%f%f%f", &pstStu->iNum,&pstStu->fScore[0], &pstStu->fScore[1], &pstStu->fScore[2],&pstStu->fScore[3],&pstStu->fScore[4]);
return 0;
}
float Average(STUDENT_ST stStu)
{
float fAver = 0;
int i = 0;
while (i<5)
{
fAver += (stStu.fScore[i]/5);
i++;
}
return fAver;
}
int Query(STUDENT_ST *pstStu)
{
int i = 0;
float fAver = 0.0;
while (pstStu[i].iNum != 0)
{
fAver = Average(pstStu[i]);
if (fAver >= AVERAGE_SCORE ||
(pstStu[i].fScore[0] >= PER_SCORE && pstStu[i].fScore[1] >= PER_SCORE
&& pstStu[i].fScore[2] >= PER_SCORE && pstStu[i].fScore[3] >= PER_SCORE && pstStu[i].fScore[4] >= PER_SCORE))
{
g_aSatisfy[i] = 1;
}
else
{
g_aSatisfy[i] = 0;
}
i++;
}
return 0;
}
int main()
{
int iStuSumNum = 0;
int i = 0;
STUDENT_ST astStu[100];
memset(astStu, 0x00, 100*sizeof(STUDENT_ST));
memset(g_aSatisfy, 0x00, 100*sizeof(int));
printf("Please input the total num of students:");
scanf("%d", &iStuSumNum);
for (i=0; i< iStuSumNum; i++)
{
InputPerStuInfo(i, &astStu[i]);
}
Query(astStu);
for (i=0; i< 100;i++)
{
if (1 == g_aSatisfy[i])
{
printf("Satisfy num=%d averg score=%f\r\n", astStu[i].iNum, Average(astStu[i]));
}
}
return 0;
}
下面是程序的執行結果:
Please input the total num of students:3
Input the 1st student num, math, Eng,c++,linearity and PE:
1001 90 90 90 90 89
Input the 2st student num, math, Eng,c++,linearity and PE:
1002 70 100 100 100 95
Input the 3st student num, math, Eng,c++,linearity and PE:
1003 85 85 84 85 85
Satisfy num=1001 averg score=89.800003
Satisfy num=1002 averg score=93.000000