关于学生对象按类排序的莫名错误,求解答

博白 2019-04-19 05:48:34
#include <iostream> #include<string> using namespace std; class student { public: student(){} 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; }
...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
博白 2019-04-19
  • 打赏
  • 举报
回复
引用 2 楼 636f6c696e的回复:
for(j=0;i<n-i;j++) --> for(j=0;j<n-i;j++)
谢谢啦,我纠结了好久
636f6c696e 2019-04-19
  • 打赏
  • 举报
回复
for(j=0;i<n-i;j++) --> for(j=0;j<n-i;j++)
博白 2019-04-19
  • 打赏
  • 举报
回复
可以运行,但运行后显示出现问题

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧