鱼C论坛

 找回密码
 立即注册
查看: 2507|回复: 7

求助代码,小白想参考一下

[复制链接]
发表于 2021-10-17 22:12:25 | 显示全部楼层 |阅读模式
购买主题 已有 1 人购买  本主题需向作者支付 5 鱼币 才能浏览
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-10-17 22:26:22 | 显示全部楼层
来人呀
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-17 22:29:45 | 显示全部楼层
为啥你求助还要我们向你支付鱼币呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-17 22:34:53 | 显示全部楼层
你求助于人还要人给你钱的吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-17 23:21:51 | 显示全部楼层

怎么?没过半个小时就等不及了?
别人给你写代码也是需要时间的呀?
看看这个吧
提问的智慧

这题目很简单吧?你为什么不会?
没完全按照题目要求写,正好借此机会复习一下 C++ 的 用户定义字面值(User-defined literals)
代码只是给你参考,不是给你直接交差了事的

还有,你悬赏弄成付费了


  1. #include <iostream>

  2. class complex_t {
  3. public:
  4.     complex_t(int real = 0, int imag = 0): real(real), imag(imag) {}
  5.     complex_t(const complex_t &rhs): real(rhs.real), imag(rhs.imag) {}
  6.     complex_t operator+(const complex_t &rhs) const {
  7.         return complex_t(this->real + rhs.real, this->imag + rhs.imag);
  8.     }
  9.     friend std::ostream &operator<<(std::ostream &os, const complex_t &rhs);
  10. private:
  11.     int real, imag;
  12. };

  13. complex_t operator""_i(unsigned long long imag) {
  14.     return complex_t(0, imag);
  15. }

  16. complex_t operator+(unsigned long long lhs, const complex_t &rhs) {
  17.     return complex_t(lhs, 0) + rhs;
  18. }

  19. std::ostream &operator<<(std::ostream &os, const complex_t &rhs) {
  20.     os << "(" << rhs.real << "," << rhs.imag << "i)";
  21.     return os;
  22. }

  23. int main() {
  24.     complex_t c1 = 20+40_i;
  25.     complex_t c2 = 0+0_i;
  26.     complex_t c3 = c1;
  27.     std::cout << c1 << std::endl;
  28.     std::cout << c2 << std::endl;
  29.     std::cout << c3 << std::endl;
  30.     return 0;
  31. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-19 11:07:56 | 显示全部楼层
你这个付费可太秀了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-19 22:25:58 | 显示全部楼层
???
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-10-25 09:10:16 From FishC Mobile | 显示全部楼层
抱歉抱歉,设置错了真的抱歉
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-3 23:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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