S.Tarafdar
08-11-03, 03:37 AM
I have this c++ code:
#include<iostream>
using namespace std;
class Complex{
float real;
float imaginary;
public:
void getvalue(float,float);
void putvalue();
Complex sum(Complex,Complex);
};
void Complex::getvalue(float re,float im){
real=re;
imaginary=im;
}
void Complex::putvalue(){
cout<<real<<"+j"<<imaginary<<endl;
}
Complex Complex:: sum(Complex x,Complex y){
Complex p;
p.real=x.real+y.real;
p.imaginary=x.imaginary+y.imaginary;
return p;
}
int main(){
Complex x,y,z;
x.getvalue(2,8);
y.getvalue(4,9);
z=sum(x,y);
z.putvalue();
return 0;
}
I want to return p from 'sum' method.But the compiler shows error.Please suggest.
#include<iostream>
using namespace std;
class Complex{
float real;
float imaginary;
public:
void getvalue(float,float);
void putvalue();
Complex sum(Complex,Complex);
};
void Complex::getvalue(float re,float im){
real=re;
imaginary=im;
}
void Complex::putvalue(){
cout<<real<<"+j"<<imaginary<<endl;
}
Complex Complex:: sum(Complex x,Complex y){
Complex p;
p.real=x.real+y.real;
p.imaginary=x.imaginary+y.imaginary;
return p;
}
int main(){
Complex x,y,z;
x.getvalue(2,8);
y.getvalue(4,9);
z=sum(x,y);
z.putvalue();
return 0;
}
I want to return p from 'sum' method.But the compiler shows error.Please suggest.