如果是每组输入一个输出的话,你自己改改吧, 毕竟你也没把输出样例给我看
#include <iostream>
using namespace std;
class Complex{
public:
Complex(double real, double imaginary);
Complex(double real);
void add(Complex &c);
void show();
private:
double Re;
double Im;
};
Complex::Complex(double real, double imaginary){
this->Re = real;
this->Im = imaginary;
}
Complex::Complex(double real){
this->Re = real;
this->Im = 0.0;
}
void Complex::add(Complex &c){
this->Re += c.Re;
this->Im += c.Im;
}
void Complex::show(){
cout << this->Re << "+" << this->Im << "i" << endl;
}
int main(){
Complex c1(3, 5);
Complex c2 = 4.5;
c1.add(c2);
c1.show();
}
是输入的问题吗?还是写的代码不能让起代码运行
class Complex
{
int a = 0;//实部
int b = 0;//虚部
public :
Complex(int s);
Complex(int s, int x);
void Add(Complex x);
void Show();
Complex(int s)
{
a = s;
b = 0;
}
Complex(int s,int x)
{
a = s;
b = x;
}
void Add(Complex obj)
{
a += obj.a;
b += obj.b;
}
void Show()
{
cout << a << "+" << b<< "i" << endl;
}
};