//用结构体完成:编程求出3个学生中某个学生的平均成绩
#include <iostream>
#include <string.h>
using namespace std;
struct student
{
char *name;
double score[3];
};
struct student stu[3]={{"han",80,90,95},{"zhao",78,85,92},{"dan",75,60,59}}; //初始化
struct student *find(struct student *s)
{
char name1[20];
cout<<"请输入您要查找的学生姓名:";
cin>>name1;
for(int i(0);i<3;i++)
if(strcmp(name1,s[i].name)==0)
return s+i;
cout<<"您要查找的人不存在。"<<endl;
return 0;
}
int main()
{
struct student *p;
p=find(stu);
cout<<p->name<<": "<<(p->score[0]+p->score[1]+p->score[3])/3<<endl;
return 0;
}
【C++】用结构体完成:编程求出3个学生中某个学生的平均成绩
最新推荐文章于 2024-05-22 09:44:29 发布