I can seem to print the real part of a complex number using printRe
in my class.
As a test I get complex number p(1.0, 5.0)
where the real number is 1.0
and imaginarynumber
5.0
I would like to return real number, so
1.0`.
The function should return
real number(Real number is: 1.0)
But when I run my code, I get only
"Real number is: "
Where is the problem Here is my code:
#include <iostream>
#include <stdio.h>
using namespace std;
class Complex{
public:
double a;
double b;
Complex(double re=0.0, double im=0.0){
a = re;
b = im;
}
Complex(const Complex &other){
a = other.a;
b = other.b;
}
void printRe(){
printf("Real number is:", a);
}
};
//some operators +, -, *, /
int main(){
Complex p(1.0, 5.0);
p.printRe();
return 0;
}
Would appreciate some help