65,209
社区成员
发帖
与我相关
我的任务
分享
student(string r,int s):name(r),score(s){}
void display();
friend void turn(student* ,int);
private:
string name;
int score;
};
void student::display()
{
cout<<name<<" "<<score<<endl;
}
void turn(student *stu,int n)
{
student temp;
int i,j;
for(i=1;i<n;i++)
for(j=0;i<n-i;j++)
{
if(stu[j].score>stu[j+1].score)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
int main()
{
int i;
student stud[3]={
student("zhanh san",70),
student("li si",100),
student("xiao ming",59)
};
turn(stud,3);
for(i=0;i<3;i++)
{
stud[i].display();
}
return 0;
}