0$房天下问答|求助C++高手$https://m.fang.com/ask/ask_1456500.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.png
packc/pages/ask/detail/detail?askid=1456500
-
求助C++高手
#include<iostream>#include<cmath>#include<windows.h>#include<stdio.h>#include"Complex.h"#define pi 3.14#define Radian(pi,Angle) ((pi*Angle)\180)class Complex{ private : double real; double imag; double Radian; double Angle; public : Complex() { real=0,imag=0,Radian=0,Angle=0; } Complex(double r,double i,double j,double h) { real=r; imag=i; Radian=j; Angle=h; } Complex operator+(Complex & c2); Complex operator*(Complex & c2); friend ostream& operator << (ostream&,Complex&); friend istream& operator << (istream&,Complex&); void display(); void display2(); operator double(); operator int();};Complex Complex::operator +(Complex &c2){ Complex c; c.real=((real*cos (Radian))+(c2.real*cos (c2.Radian))); c.imag=((real*sin (Radian))+(c2.real*sin (c2.Radian))); return c;}Complex Complex::operator *(Complex &c2)
更多
共1个回答
-
-
-
richiesui
丨Lv 4
istream& operator << (istream& input,Complex& c){ cout<<"input real part and imaginary part of complex number:"; input>>c.real>>c.Angle; return input;}不是破坏了 封装性吗? real Angle 是私有成员 你的程序应该是通不过编译的 先把这个问题解决吧 Complex(double r,double i,double j,double h){ real=r; imag=i; Radian=j; Angle=h;}我的建议是写成这样Complex(double r,double i){ real=r; imag=i; 通过计算装换之后 写入数值 这样可以提高数据的通用性 Radian=?; Angle=?;}
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。

关注成功