struct student
{
int iNum; // 学号
char cName[20]; // 姓名
char cSex[2]; // 性别
int iAge; // 年龄
int iScore[5]; // 5门课成绩
float fAverage; // 个人平均分
};
// 求个人平均分
float ClacAverage(student *pStudent)
{
if (NULL == pStudent)
{
return 0.0f;
}
int iSum = 0;
for (int i = 0; i < 5; i++)
{
iSum += pStudent->iScore[i];
}
pStudent->fAverage = iSum / 5.0;
printf("学生 %s 的个人平均分为:%.2f\n", pStudent->cName, pStudent->fAverage);
return pStudent->fAverage;
}
// 求每门课程的平均分
void CalcAverageEachCourse(student Students[], int iCount)
{
for (int i = 0; i < 5; i++)
{
int iSum = 0;
for (int j = 0; j < iCount; j++)
{
iSum += Students[j].iScore[i];
}
float fAvg = iSum / iCount;
printf("第 %d 门课的平均分为:%.2f\n", i + 1, fAvg);
}
};
void GetInput(student *pStudent, int iNum)
{
if (NULL == pStudent)
{
return;
}
printf("请输入第 %d 位学生的学号:\n", iNum + 1);
scanf("%d", &pStudent->iNum);
printf("请输入第 %d 位学生的姓名:\n", iNum + 1);
scanf("%s", pStudent->cName);
printf("请输入第 %d 位学生的性别:\n", iNum + 1);
scanf("%s", pStudent->cSex);
for (int i = 0; i < 5; i++)
{
printf("请输入第 %d 位学生的第%d门课的成绩:\n", iNum + 1, i + 1);
scanf("%d", &pStudent->iScore[i]);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
/*test(); */
student Students[10];
for (int i = 0; i < 10; i++)
{
GetInput(&Students[i], i);
}
指针我几乎没听,可以把p->成员名的格式改成(*p)成员名吗,那样看觉得怪怪的。还有(*p)成员名表达什么意思
float ClacAverage(student *pStudent)
if (NULL == pStudent)
return 0.0f;解释这些 |
|