谁帮我看一下我的代码啊

来源:百度知道 编辑:UC知道 时间:2024/05/25 05:36:05
这个代码应该怎么修改啊?
#include <iostream>
#include <cmath>
using std::cout;
using std::endl;
using std::cin;
class complex
{
public:
complex() //构造函数,将实部虚部置为0
{
real=image=0;
}
complex(double r, double i) //构造函数,创建复数对象的同时完成复数的实部虚部的初始化
{
real = r, image = i;
}
complex operator +(const complex &c); //构造函数 加法
complex operator -(const complex &c); //构造函数 减法
complex operator *(const complex &c); //构造函数 乘法
complex operator /(const complex &c); //构造函数 除法
double abs(void); //构造函数 取模
complex getcomplex();
double getrealpart() ; //获得实部
double getimaginarypart(); //获得虚部
friend void print(const complex &c);
private:
double real, image;
};

inline complex compl

我调试中,你的 cout<<"您输入的复数是:"<<c1.getrealpart<<"+"<<c1.getimaginarypart<<"i"<<endl; 中c1.getrealpart是函数不是变量,不能做为输入的变量
方案1
你可以在写两个函数
分别是输入实部和虚部
在定义变量接受输入的值
执行函数传值进去进去
方案2
把函数作引用//好像不行,因为那两个值是私有的