#include<iostream>
#include "string.h"
using namespace std;
struct student
{
char name[20];
int score1;
int score2;
int score3;
};
struct student* find(struct student *s)
{
char name1[20];
cin >> name1;
for (int i(0); i < 3; i++)
if (strcmp(name1, s[i].name) == 0)
return s + i;
return 0;
}
int main()
{
static struct student stu[3] = { {"xiaoe",100,80,90}, {"dae",50,60,70}, {"ee",30,40,50} };
struct student* p, * find(struct student* s);
p = find(stu);
cout << p->name << ":" << (p->score1 + p->score2 + p->score3) / 3 << endl;
return 0;
}
输入”xiaoe“,得到90.