Here I am trying to implement a class for complex numbers using books and the Internet. Here is the code:
#include <iostream>
#include <ostream>
using namespace std;
class Complex{
private:
float re,im;
public:
Complex(float x,float y){
re=x;
im=y;
}
float Re() const{
re;
}
float Im() const {
return im;
}
Complex& operator*=(const Complex& rhs){
float t=Re();
re = Re()*rhs.Re()-Im()*rhs.Im();
im = t*rhs.Im()+Im()*rhs.Re();
return *this;
}
};
ostream& operator<<(ostream& t,const Complex& c){
t << c.Re() << " " << c.Im();
return t;
}
int main(){
Complex s(3.45,23.12);
return 0;
}
It compiles fine, but I can't find a way to print the real and imaginary parts of the number on the screen?