复数相加。。。求答案。。c++
复数相加#include"iostream.h"classComplex{public:Complex(){real=0;imag=0;}Complex(doubler)...
复数相加
#include "iostream.h"
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r) {real=r;imag=0;}
Complex(double r,double i) {real=r;imag=i;}
Complex operator+(Complex &c2)
{
Complex c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
_______________;
}
void print(Complex &c)
{
if(c.imag<0)
cout<<c.real<<c.imag<<"i"<<endl;
else
cout<<c.real<<"+"<<c.imag<<"i"<<endl;
}
private:
double real,imag;
};
void main()
{
Complex c1(2.5,6),c2(3.5,-8),c3;
_______________;
cout<<"\nc1+c2=";
c3.print(c3);
}
谢谢 展开
#include "iostream.h"
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r) {real=r;imag=0;}
Complex(double r,double i) {real=r;imag=i;}
Complex operator+(Complex &c2)
{
Complex c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
_______________;
}
void print(Complex &c)
{
if(c.imag<0)
cout<<c.real<<c.imag<<"i"<<endl;
else
cout<<c.real<<"+"<<c.imag<<"i"<<endl;
}
private:
double real,imag;
};
void main()
{
Complex c1(2.5,6),c2(3.5,-8),c3;
_______________;
cout<<"\nc1+c2=";
c3.print(c3);
}
谢谢 展开
3个回答
展开全部
Complex operator+(Complex &c2)
{
Complex c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
return c;//_________________;
}
void main()
{
Complex c1(2.5,6),c2(3.5,-8),c3;
c3=c1+c2;//_______________;
cout<<"\nc1+c2=";
c3.print(c3);
}
{
Complex c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
return c;//_________________;
}
void main()
{
Complex c1(2.5,6),c2(3.5,-8),c3;
c3=c1+c2;//_______________;
cout<<"\nc1+c2=";
c3.print(c3);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-05-30
展开全部
1. return c;
2. c3 = c1+c2;
2. c3 = c1+c2;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
return c;
c3=c1+c2;
c3=c1+c2;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询