网问答>>请求C++程序题复数操作答案?
问题
未解决

请求C++程序题复数操作答案?

时间:2024-03-14 13:53:17
下题是按照试卷写的,我自己的答案和实际运行的答案一致都是2+9i,1+1i,1+8i,但是试卷的参考答案是8+7i,6+5i,2+2i,到底谁算错了,请指导?#include iostreamusing namespace std;class testComplx{ private: double realpart, imagepart; public: testComplx(double real=0,double image=0):realpart(real),imagepart(image){ } testComplx operator-(const testComplx &p) const{ return testComplx(realpart-p.realpart,imagepart-p.imagepart); } void show() const{ coutrealpart"+"imagepart"i"endl; }}; int main(){ testComplx a(2,9),b(1,1),c; c=a-b; a.show(); b.show(); c.show();return 0;}
本类最有帮助
Copyright © 2008-2013 www.wangwenda.com All rights reserved.冀ICP备12000710号-1
投诉邮箱: