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

2024-11-16 06:55:26
推荐回答(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了