//用结构体完成:编程求出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; }
<img src="http://img.blog.csdn.net/20150509102131411?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG91ZG91d2ExMjM0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
时间: 2024-10-06 07:25:33