鱼C论坛

 找回密码
 立即注册
查看: 1171|回复: 1

C++的问题,求助

[复制链接]
发表于 2024-6-9 16:45:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<iostream>
  2. using namespace std;

  3. class Singer
  4. {
  5.         protected:
  6.                 string name;
  7.                 char sex;
  8.                 int age;
  9.                 double score;
  10.         public:
  11.                 string getName() const{ return name; };
  12.                 Singer(string name="", char s='?' ,int a=0,double n=0 );//构造函数要写的
  13.                 friend istream& operator >> (istream &, Singer &);
  14.                 bool operator >(Singer & a) ;
  15.                 bool operator ==(Singer &b) ;
  16.                 friend ostream& operator << (ostream &, const Singer &);
  17. };
  18. Singer::Singer(string name, char s, int a,double n )
  19. {
  20.     this->name= name;
  21.     score = n;
  22.     sex = s;
  23.     age = a;
  24. }
  25. istream& operator >> (istream & myin, Singer & sin)
  26. {
  27.         myin >> sin.name >> sin.sex >> sin.age >> sin.score;
  28.         return myin;
  29. }
  30. ostream& operator << (ostream & myout, const Singer & sing)
  31. {
  32.         myout << sing.name << sing.sex << sing.age << sing.score;
  33.         return myout;
  34. }
  35. bool operator >(Singer & a)
  36. {
  37.         if(this->score > a.score)
  38.         return true;
  39.         else
  40.         return false;
  41. }
  42. bool operator ==(Singer &b)
  43. {
  44.         if(this->score == b.score)
  45.         return true;
  46.         else
  47.         return false;       
  48. }

  49. int main()
  50. {
  51. Singer s1,s2;
  52. cin>>s1>>s2;
  53. cout<<s1<<"\n"<<s2<<endl;
  54. if(s1>s2)
  55. cout<<s1.getName()<<"'s score is higher than "<<s2.getName()<<"'s.\n";

  56. else if(s1==s2)
  57. cout<<s1.getName()<<"'s score is equal to "<<s2.getName()<<"'s.\n";

  58. else
  59. cout<<s1.getName()<<"'s score is lower than "<<s2.getName()<<"'s.\n";

  60. return 0;

  61. }
复制代码

//bool的地方出了问题,但我不知道哪里有问题,感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-26 03:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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