鱼C论坛

 找回密码
 立即注册
查看: 2515|回复: 3

程序b

[复制链接]
发表于 2014-7-25 20:55:56 | 显示全部楼层 |阅读模式
20鱼币
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. class Student
  5. {
  6. private:
  7. string number,name;
  8. int score;
  9. public:
  10. Student(string a,string b,int c)
  11. {
  12. number=a;
  13. name=b;
  14. score=c;
  15. }       
  16. void display()
  17. {
  18. cout<<number<<' '<<name<<' '<<score<<endl;
  19. }
  20. friend void judge(Student &t);
  21. int sco()
  22. {
  23. return score;
  24. }

  25. }stu[1000000];
  26. void judge(Student t[],int n)
  27. {
  28. for(int i=0;i<n;i++)
  29. if(t[0].sco()<t[i].sco())t[0]=t[i];
  30. t[0].display();       
  31. }
  32. int main()
  33. {
  34. int n,i;
  35. string number,name;
  36. int score;
  37. while(1)
  38. {
  39. cin>>n;       
  40. if(n==0)break;
  41. for(i=0;i<n;i++)
  42. cin>>stu[i].number>>stu[i].name>>stu[i].score;
  43. judge(stu,n);
  44. }
  45. reutrn 0;       
  46. }
复制代码
大神叔叔们,帮忙看看我这段代码哪里出问题呢,求指点迷津
代码是找出最低成绩的学生


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-7-25 22:40:03 | 显示全部楼层
你这个程序不正确吧。首先你没有默认构造函数,定义stu[1000000]会报错。其次是在number,name都是private,不能在int main中直接引用(cin>>stu[i].number>>stu[i].name>>stu[i].score;)。这个程序你自己先改一下。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-7-25 22:46:23 | 显示全部楼层
{:7_176:}
超过二十行了居然一点注释都没有
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-7-26 11:17:48 | 显示全部楼层
流行语 发表于 2014-7-25 22:40
你这个程序不正确吧。首先你没有默认构造函数,定义stu[1000000]会报错。其次是在number,name都是private, ...

学习了,受教!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-10 15:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表