作业帮 > 综合 > 作业

用C++ 写一个完整的Complex number(复数)用户给出2个数程序计算+-*/

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/30 16:42:22
用C++ 写一个完整的Complex number(复数)用户给出2个数程序计算+-*/
以下是已有的
#include
using namespace std;
class Complex {
private:
double a,b; // z = a + bi
public:
Complex();
Complex( const Complex & right );
Complex( double aa,double bb );
Complex( double aa );
void set( double aa,double bb );
double getreal() const;
double getim() const;
Complex & operator = ( const Complex & right );
Complex & operator += ( const Complex & right );
Complex & operator -= ( const Complex & right );
Complex & operator *= ( const Complex & right );
bool operator == ( const Complex & right ) const;
bool operator = ( const Complex & right ) const;
bool operator () const; // the unary not operator
Complex operator + ( const Complex & right ) const;
Complex operator - ( const Complex & right ) const;
Complex operator * ( const Complex & right ) const;
Complex operator / ( const Complex & right ) const;
Complex operator - () const; // the unary minus
// input output operators
friend ostream & operator > ( istream & in,Complex & right );
};
// class implementation
int main() {
string e;
while (1){
coute;
if(e[0]== 'q' or e[0]=='Q') break;
return 0;
}
用C++ 写一个完整的Complex number(复数)用户给出2个数程序计算+-*/
你是要在以上基础上修改还是推到重写?
再问: 基础上修改
再答: 还有个疑问:这个是题目自身提供的类声明?而题目实际目的只是让你写出函数的定义?这关系到是否能够修改函数声明。你至今未追问,大家时间有限,我只能按照上述类声明编写对应函数了:具体代码看附件,编译测试通过。
再问: 运行程序后 本该打完Q以外字母后程序继续运行,可是没有反应
再答: 你没看我程序怎么写的吗? 要输入两个复数看结果。 比如输入a(只要不是q)后,就是选择不退出了。 然后接下来要输入两个复数的实部和虚部: 4 4 4 4 继续回车你就看到运算结果了......