• C++DAY42


    1. #include
    2. using namespace std;
    3. class Stu
    4. {
    5. friend const Stu operator+(const Stu &L,const Stu &R);
    6. friend const Stu operator-(const Stu &L,const Stu &R);
    7. friend const Stu operator*(const Stu &L,const Stu &R);
    8. friend const Stu operator/(const Stu &L,const Stu &R);
    9. friend const Stu operator%(const Stu &L,const Stu &R);
    10. friend bool operator<(const Stu &L, const Stu &R);
    11. friend bool operator==(const Stu &L, const Stu &R);
    12. friend bool operator>(const Stu &L, const Stu &R);
    13. friend Stu operator+=(Stu &L,const Stu &R);
    14. friend Stu operator-=(Stu &L,const Stu &R);
    15. friend Stu operator*=(Stu &L,const Stu &R);
    16. friend Stu operator/=(Stu &L,const Stu &R);
    17. friend Stu operator%=(Stu &L,const Stu &R);
    18. private:
    19. int a;
    20. int b;
    21. public:
    22. Stu(){}
    23. Stu(int a,int b):a(a),b(b)
    24. {}
    25. void show()
    26. {
    27. cout << "a = " << a << " b = " << b << endl;
    28. }
    29. };
    30. const Stu operator+(const Stu &L,const Stu &R)
    31. {
    32. Stu temp;
    33. temp.a = L.a + R.a;
    34. temp.b = L.b + R.b;
    35. return temp;
    36. }
    37. const Stu operator-(const Stu &L,const Stu &R)
    38. {
    39. Stu temp;
    40. temp.a = L.a - R.a;
    41. temp.b = L.b - R.b;
    42. return temp;
    43. }
    44. const Stu operator*(const Stu &L,const Stu &R)
    45. {
    46. Stu temp;
    47. temp.a = L.a * R.a;
    48. temp.b = L.b * R.b;
    49. return temp;
    50. }
    51. const Stu operator/(const Stu &L,const Stu &R)
    52. {
    53. Stu temp;
    54. temp.a = L.a / R.a;
    55. temp.b = L.b / R.b;
    56. return temp;
    57. }
    58. const Stu operator%(const Stu &L,const Stu &R)
    59. {
    60. Stu temp;
    61. temp.a = L.a % R.a;
    62. temp.b = L.b % R.b;
    63. return temp;
    64. }
    65. bool operator<(const Stu &L, const Stu &R)
    66. {
    67. if(L.ab
    68. {
    69. return true;
    70. }
    71. else
    72. {
    73. return false;
    74. }
    75. }
    76. bool operator==(const Stu &L, const Stu &R)
    77. {
    78. if(L.a==R.a && L.b==R.b)
    79. {
    80. return true;
    81. }
    82. else
    83. {
    84. return false;
    85. }
    86. }
    87. bool operator>(const Stu &L, const Stu &R)
    88. {
    89. if(L.a>R.a && L.b>R.b)
    90. {
    91. return true;
    92. }
    93. else
    94. {
    95. return false;
    96. }
    97. }
    98. Stu operator+=(Stu &L,const Stu &R)
    99. {
    100. L.a += R.a;
    101. L.b += R.b;
    102. return L;
    103. }
    104. Stu operator-=(Stu &L,const Stu &R)
    105. {
    106. L.a -= R.a;
    107. L.b -= R.b;
    108. return L;
    109. }
    110. Stu operator*=(Stu &L,const Stu &R)
    111. {
    112. L.a *= R.a;
    113. L.b *= R.b;
    114. return L;
    115. }
    116. Stu operator/=(Stu &L,const Stu &R)
    117. {
    118. L.a /= R.a;
    119. L.b /= R.b;
    120. return L;
    121. }
    122. Stu operator%=(Stu &L,const Stu &R)
    123. {
    124. L.a %= R.a;
    125. L.b %= R.b;
    126. return L;
    127. }
    128. int main()
    129. {
    130. Stu s1(1,1);
    131. Stu s2(13,52);
    132. Stu s3 = s1 + s2;
    133. Stu s4 = s2 - s1;
    134. Stu s5 = s1 * s2;
    135. Stu s6 = s1 / s2;
    136. Stu s7 = s1 % s2;
    137. s3.show();
    138. s4.show();
    139. s5.show();
    140. s6.show();
    141. s7.show();
    142. s3 += s1;
    143. s3.show();
    144. s4 -= s1;
    145. s4.show();
    146. s5 *= s1;
    147. s5.show();
    148. s6 /= s1;
    149. s6.show();
    150. s7 %= s1;
    151. s7.show();
    152. if(s2 < s3)
    153. {
    154. cout << "s2 < s3" << endl;
    155. }
    156. if(s2 == s5)
    157. {
    158. cout << "s2 == s5" << endl;
    159. }
    160. if(s2 > s4)
    161. {
    162. cout << "s2 > s4" << endl;
    163. }
    164. return 0;
    165. }

     

  • 相关阅读:
    正则表达式
    基于Python的电子病历实体识别系统
    简单几个步骤,轻松完成短视频配音工作|别惊讶,让我手把手教你
    Presto 之 explain and explain analyze的实现
    linux安装opencv
    Ubuntu上安装部署k8s集群
    CentOS部署Samba服务
    打造千万级流量秒杀第二十五课 过滤器:如何实现用户认证和反黄牛过滤无效请求?
    HummerRisk V0.6.0发布:升级列表高级搜索功能,扩充对象存储和操作审计支持范围等
    初识上位机(下):C#读写PLC数据块数据
  • 原文地址:https://blog.csdn.net/weixin_69186714/article/details/133754777