c++定义对象数组的问题

2024年11月16日 06:55
有3个网友回答
网友(1):

#include
#include

class student
{
private:
int num ;
float score;
string name;
public:
void set()
{ cout<<"\n学号:" ;
cin>>num;
cout<<"\n成绩:";
cin>>score;
cout<<"\n姓名:" ;
cin>>name;
}
void print()
{cout<<"\n学号:"< cout<<"\n成绩:"< cout<<"\n姓名:"< }
float getScore(){return score;}

};

int main()
{
student a[3];
int i,j,k=0;

for(i=0;i<3;++i)
a[i].set();

for(j=0;j<2;++j)
{ if(a[j].getScore() k=j+1;
}
a[k].print();

return 0;
}

网友(2):

#include

#include

class
student
{
private:
int
num
;
float
score;
string
name;
public:
void
set()
{
cout<<"\n学号:"
;
cin>>num;
cout<<"\n成绩:";
cin>>score;
cout<<"\n姓名:"
;
cin>>name;
}
void
print()
{cout<<"\n学号:"<cout<<"\n成绩:"<cout<<"\n姓名:"<}
float
getScore(){return
score;}
};
int
main()
{
student
a[3];
int
i,j,k=0;
for(i=0;i<3;++i)
a[i].set();
for(j=0;j<2;++j)
{
if(a[j].getScore()k=j+1;
}
a[k].print();
return
0;
}

网友(3):

建个类 写个冒泡排序 不就o了