//Help me
//I got 3 errors left
//whats wrong with program
#include<iostream.h>
class Complex {
friend ostream &operator<<( ostream &, Complex & );
friend istream &operator>>(istream &, Complex & );
public:
Complex ( double = 0.0, double = 0.0 );
Complex operator+(const Complex & ) const;
Complex operator-(const Complex & ) const;
Complex operator*(const Complex & ) const;
const Complex &operator=(const Complex & );
int operator==(const Complex&) const;
int operator!=(const Complex&) const;
//void print() const;
private:
double real;
double imaginary;
};
Complex::Complex( double r, double i )
: real(r), imaginary(i) { }
Complex Complex:perator+(const Complex &operand2 ) const
{
Complex added;
added.real = real + operand2.real;
added.imaginary = imaginary + operand2.imaginary;
return added;
}
Complex Complex:perator-( const Complex &operand2 ) const
{
Complex subtrac;
subtrac.real = real - operand2.real;
subtrac.imaginary = imaginary - operand2.imaginary;
return subtrac;
}
const Complex& Complex:perator=(const Complex &right )
{
real = right.real;
imaginary = right.imaginary;
return *this;
}
int Complex:perator==(const Complex &right) const
{ return right.real == real && right.imaginary == imaginary ? 1 : 0; }
int Complex:perator!=(const Complex &right) const
{ return !(*this == right); }
const Complex& Complex:perator*(const Complex &operand2)
{
Complex mult;
mult.real = real * operand2.real + imaginary * operand2.imaginary;
mult.imaginary = real * operand2.imaginary + imaginary * operand2.real;
return mult;
}
//void Complex:rint() const
//{ cout<< '(' <<real <<"," <<imaginary<<')'; }
ostream& operator<<( ostream &output, const Complex &number)
{
output<<number.real;
//output<<ignore(2);
output<<number.imaginary;
}
istream& operator>>( istream &input, Complex &number)
{
input>>number.real;//ERROR HERE CANNOT ACCESS PRIVATE MEMBER REAL
input.ignore(2);
input >> number.imaginary;
input.ignore(2);
return input;
}
int main()
{
Complex x,y(4.3, 8.2), z(3.3, 1.1 ),cmp;
cout << "Enter a complex number in the form: a + bi\n? ";
cin >> cmp;
cout << "x: " << x << "\ny: " << y << "\nz: " << z << "\ncmp: "
<< cmp << endl;
cout<< "x: ";
//x.print();
cout<< "\ny: ";
//y.print();
cout<<"\nz: ";
//z.print();
x+y=z;
cout<<"\n\nx = y + z:\n";
//x.print();
cout<<" = ";
//y.print();
cout<<" +";
//z.print();
x = y - z;
cout<< "\n\nx = y - z:\n";
//x.print();
cout <<" = ";
//y.print();
cout<<" - ";
//z.print();
cout <<endl;
if (x != cmp)
cout << x << " != " << cmp << endl;
cout << endl;
x = cmp;
if (x == cmp)
cout << x << " == " << cmp << endl;
return 0;
}