I'm writing a class(.h) file involving complex numbers and need to overload the %26lt;%26lt; and %26gt;%26gt; so I can use cin and cout .
The class allows users to use complex numbers in the form a+bi.
So, the private parts of the class are real(a part), imag(b part) and expoi (the exponent of i. so 3 = expoi in i^3)
I succefully overloaded all the other things, so here's what the class can do.
class Complex // keeps track of a Number in the form a +bi
{
private:
double real; // this is the "a" part
double imag; // this is the "b" part
int expoi; // this is the exponent of i
public:
double Real();// Returns Real part of number
double Imaginary(); // Returns imaginary part of number
void Show(); // prints out complex number on screen
Complex operator +(Complex Num);
Complex operator -(Complex Num);
Complex operator *(Complex Num);
Complex operator=(Complex Num);
Complex operator==(Complex Num);
Complex operator%26lt;%26lt;(Complex Num);
Complex operator%26gt;%26gt;(Complex Num);
};
Overloading %26lt;%26lt; and %26gt;%26gt; operators in C++?
Check this out:
http://www.fredosaurus.com/notes-cpp/oop...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment