• 07-25-2002
Unregistered
//Help me
//I AM SUPPOSSED TO HAVE THE USER INPUT AN IMAGINARY
//NUMBER
// I NEED THE SUM
// THE DIFFERENCE
// MULTIPLIED VALUE
// == IF ANY
// AND THE !=
// I AM GETTING SOME ERRORS

#include<iostream.h>

class Complex {

friend ostream &operator<<( ostream &, const 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 & );
//void print() const;

private:
double real;
double imaginary;

};

ostream& operator<<( ostream &output, const Complex &number)
{
output<<number.real;
//output<<ignore(2);
output<<number.imaginary;
}

istream& operator>>(istream &input, const Complex &number)
{
input>>number.real;//ERROR HERE CANNOT ACCESS PRIVATE MEMBER REAL
input.ignore(2);
input >> number.imaginary;

return input;
}
Complex::Complex( double r, double i )

: real(r), imaginary(i) { }

Complex Complex::operator+(const Complex &operand2 ) const

{
return Complex( real + operand2.real,
imaginary - operand2.imaginary );
}

Complex Complex::operator-( const Complex &operand2 ) const
{
return Complex( real - operand2.real,
imaginary - operand2.imaginary );

}

const Complex& Complex::operator=(const Complex &right )
{
real = right.real;
imaginary = right.imaginary;
return *this;
}

//const Complex& Complex::operator*(const Complex &operand2)
//{

// return Complex( real * operand2.real,
// imaginary * operand2.imaginary );
//}

//void Complex::print() const
//{ cout<< '(' <<real <<"," <<imaginary<<')'; }

int main()

{
Complex x,y(4.3, 8.2), z(3.3, 1.1 );

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;

return 0;

}