7.7.cpp
来自「这是C++的一部分练习程序!对初学者有一定的帮助作用。」· C++ 代码 · 共 30 行
CPP
30 行
#include <iostream.h>
#include <string.h>
struct student
{
char *name;
double score[3];
}stu[3]={{"Li",{89,85.5,90}},{"Ma",{89.5,90.5,79}},{"Hu",{88.5,92,81}}};
struct student *find(struct student []);
void main()
{
struct student *ps;
ps=find(stu);
if(ps==0)
cout<<"error!\n";
else
cout<<ps->name<<':'<<(ps->score[0]+ps->score[1]+ps->score[2])/3<<endl;
}
struct student *find(struct student s[])
{
char name[20];
cout<<"Enter student's name: ";
cin>>name;
for(int i=0;i<3;i++)
if(strcmp(name,s[i].name)==0)
return s+i;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?