C类+错误输出
Class C+ wrong output
除Setreal()
和Setimag()
命令外,所有代码工作正常,没有错误下面给出错误的输出
#include <iostream>
using namespace std;
class complex
{ public:
bool Readcomplex()
{ cout<<"Enter the real part"<<endl;
cin>>real;
cout<<"Enter the imaginary part"<<endl;
cin>>imag;
return true; };
double Getreal()
{ return real;
};
double Getimag()
{ return imag;
};
double Add(complex c)
{ real=real+c.real;
imag=imag+c.imag;
};
double Setimag(double im)
{ imag=im;
};
double Setreal(double re)
{ real=re;
};
void Multiply(complex c)
{ double x;
x=real*c.real-imag*c.imag;
imag=real*c.imag+imag*c.real;
real=x;
};
private:
double real;
double imag;
};
int main()
{ complex A,B,E,R;
double C,D;
A.Readcomplex();
B.Readcomplex();
cout<<"The complex no. A is "<<A.Getreal()<<"+i"<<A.Getimag()<<endl;
cout<<"The complex no. B is "<<B.Getreal()<<"+i"<<B.Getimag()<<endl;
A.Add(B); //Result stored in A.
cout<<"The complex no. A2 is "<<A.Getreal()<<"+i"<<A.Getimag()<<endl;
cout<<"Set the real of A"<<endl;
cin>>C;
cout<<"and set the imaginary part"<<endl;
cin>>D;
cout<<"the new A is"<<A.Setreal(C)<<"+i"<<A.Setimag(D)<<endl; //WRONG OUTPUT
A.Multiply(B);
cout<<"The complex no. A is "<<A.Getreal()<<"+i"<<A.Getimag()<<endl;
system("pause");
return 0;}
错误的结果是在cout<<"the new A is"<<A.Setreal(C)<<"+i"<<A.Setimag(D)<<endl; //WRONG OUTPUT
,因为结果是1.#QNAN+i1.#QNAN
,而不是像C+iD
那样是C和D的值
这些方法应该有一个返回语句:
double Setimag(double im)
{
return imag=im;
};
double Setreal(double re)
{
return real=re;
};
double Setreal(double re)
{
real=re;
};
这个函数应该返回double
类型的东西,但它没有…
相关文章:
- 输出错误,问题是找到总和5000位数字cpp
- 使用复制构造函数的程序输出错误
- 异或字符串加密/解密输出错误
- 在linux上使用g++输出错误,在windows上更正
- 使用递归函数 (c++) 将长字符串转换为整数时输出错误
- ECDSA 密钥对生成输出错误
- fscanf() 输出错误的值
- 输入 1024 后十进制到二进制转换的输出错误?
- 输出错误命令的条件语句
- cuSparse (cusparseDcsrgemm) 中的矩阵乘法输出错误的结果
- 为什么 du -sh 输出错误大小的内存映射文件
- VS2017 的输出错误,但 mingw 有效
- 如何使FFMPEG C 代码不输出错误消息
- 乘以时输出错误.这是我编译器中的错误吗?C
- 输出错误:两个不同编译器上的不同输出:Prime Cryptarithm USACO
- 为什么输出错误崩溃
- C++输入/输出错误
- 尝试用 c++ 制作一个简单的加法器.编译成功,但输出错误
- 当我使用此合并排序代码运行时,输出错误
- 递归功能输出错误的值