• 10.10c++作业


    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 bool 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 bool operator!=(const 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. const Stu operator-(const Stu &R)const
    26. {
    27. Stu temp;
    28. temp.a=this->a-R.a;
    29. temp.b=this->b-R.b;
    30. return temp;
    31. }
    32. const Stu operator+(const Stu &R)const
    33. {
    34. Stu temp;
    35. temp.a=this->a+R.a;
    36. temp.b=this->b+R.b;
    37. return temp;
    38. }
    39. const Stu operator*(const Stu &R)const
    40. {
    41. Stu temp;
    42. temp.a=this->a*R.a;
    43. temp.b=this->b*R.b;
    44. return temp;
    45. }
    46. const Stu operator/(const Stu &R)const
    47. {
    48. Stu temp;
    49. temp.a=this->a/R.a;
    50. temp.b=this->b/R.b;
    51. return temp;
    52. }
    53. bool operator>(const Stu &R)const
    54. {
    55. if(a>R.b && b>R.b)
    56. {
    57. return true;
    58. }
    59. else
    60. {
    61. return false;
    62. }
    63. }
    64. bool operator<(const Stu &R)const
    65. {
    66. if(a
    67. {
    68. return true;
    69. }
    70. else
    71. {
    72. return false;
    73. }
    74. }
    75. bool operator==(const Stu &R)const
    76. {
    77. if(a==R.b && b==R.b)
    78. {
    79. return true;
    80. }
    81. else
    82. {
    83. return false;
    84. }
    85. }
    86. bool operator<=(const Stu &R)const
    87. {
    88. if(a<=R.b && b<=R.b)
    89. {
    90. return true;
    91. }
    92. else
    93. {
    94. return false;
    95. }
    96. }
    97. bool operator>=(const Stu &R)const
    98. {
    99. if(a>=R.b && b>=R.b)
    100. {
    101. return true;
    102. }
    103. else
    104. {
    105. return false;
    106. }
    107. }
    108. bool operator!=(const Stu &R)const
    109. {
    110. if(a!=R.b && b!=R.b)
    111. {
    112. return true;
    113. }
    114. else
    115. {
    116. return false;
    117. }
    118. }
    119. Stu &operator+=(const Stu &R)
    120. {
    121. a+=R.a;
    122. b+=R.b;
    123. return *this;
    124. }
    125. Stu &operator-=(const Stu &R)
    126. {
    127. a-=R.a;
    128. b-=R.b;
    129. return *this;
    130. }
    131. Stu &operator*=(const Stu &R)
    132. {
    133. a*=R.a;
    134. b*=R.b;
    135. return *this;
    136. }
    137. Stu &operator/=(const Stu &R)
    138. {
    139. a/=R.a;
    140. b/=R.b;
    141. return *this;
    142. }
    143. void show()
    144. {
    145. cout << "a= " << a << "b= " << b << endl;
    146. }
    147. };
    148. const Stu operator*(const Stu &L,const Stu &R)
    149. {
    150. Stu temp;
    151. temp.a = L.a * R.a;
    152. temp.b = L.b * R.b;
    153. return temp;
    154. }
    155. const Stu operator+(const Stu &L,const Stu &R)
    156. {
    157. Stu temp;
    158. temp.a = L.a + R.a;
    159. temp.b = L.b + R.b;
    160. return temp;
    161. }
    162. const Stu operator-(const Stu &L,const Stu &R)
    163. {
    164. Stu temp;
    165. temp.a = L.a - R.a;
    166. temp.b = L.b - R.b;
    167. return temp;
    168. }
    169. const Stu operator/(const Stu &L,const Stu &R)
    170. {
    171. Stu temp;
    172. temp.a = L.a / R.a;
    173. temp.b = L.b / R.b;
    174. return temp;
    175. }
    176. bool operator>(const Stu &L,const Stu &R)
    177. {
    178. if(L.a > R.a && L.b > R.b)
    179. {
    180. return true;
    181. }
    182. else
    183. {
    184. return false;
    185. }
    186. }
    187. bool operator<(const Stu &L,const Stu &R)
    188. {
    189. if(L.a < R.a && L.b < R.b)
    190. {
    191. return true;
    192. }
    193. else
    194. {
    195. return false;
    196. }
    197. }
    198. bool operator>=(const Stu &L,const Stu &R)
    199. {
    200. if(L.a >= R.a && L.b >= R.b)
    201. {
    202. return true;
    203. }
    204. else
    205. {
    206. return false;
    207. }
    208. }
    209. bool operator<=(const Stu &L,const Stu &R)
    210. {
    211. if(L.a <= R.a && L.b <= R.b)
    212. {
    213. return true;
    214. }
    215. else
    216. {
    217. return false;
    218. }
    219. }
    220. bool operator!=(const Stu &L,const Stu &R)
    221. {
    222. if(L.a != R.a && L.b != R.b)
    223. {
    224. return true;
    225. }
    226. else
    227. {
    228. return false;
    229. }
    230. }
    231. Stu &operator+=(Stu &L,const Stu &R)
    232. {
    233. L.a+=R.a;
    234. L.b+=R.b;
    235. return L;
    236. }
    237. Stu &operator-=(Stu &L,const Stu &R)
    238. {
    239. L.a-=R.a;
    240. L.b-=R.b;
    241. return L;
    242. }
    243. Stu &operator*=(Stu &L,const Stu &R)
    244. {
    245. L.a*=R.a;
    246. L.b*=R.b;
    247. return L;
    248. }
    249. Stu &operator/=(Stu &L,const Stu &R)
    250. {
    251. L.a/=R.a;
    252. L.b/=R.b;
    253. return L;
    254. }
    255. int main()
    256. {
    257. Stu s1(500,500);
    258. Stu s2(250,250);
    259. //Stu s3=s1-s2;
    260. // Stu s3=s1*s2;
    261. // s3.show();
    262. // if(s1>s2)
    263. // {
    264. // cout << "s1 > s2" << endl;
    265. // }
    266. // s2+=s1;
    267. s2.show();
    268. return 0;
    269. }

  • 相关阅读:
    【继承之extends关键字和super关键字】
    Linux(Kali\Ubuntu\CentOS\arm-Linux)安装Powershell
    Transformer模型
    Sublime Text 下载和安装教程
    C++ 练气期之一文看懂字符串
    Ubuntu16.04编译测试LVI_SAM过程
    面向对象基础案例(2)
    Vue3使用Vite创建项目
    [Model.py 03]Modification for creating terrain matrix3.
    Kubernetes API 基础
  • 原文地址:https://blog.csdn.net/z18756576757/article/details/133754477