need help, im trying to get output but doesnt come that way

I HAVE SOM ISSUES WITH MY PROGRAM, I HAVE MARK LIKE THIS /*xxxxxxxxxxxx*/ where there is a problem. see the output at the end then youll be able to figure out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//complex.cpp//
[code]// Complex class member-function definitions.  
#include "Complex.h"  
  
#include <iostream>  
using std::ostream;  
using std::istream;
using namespace std;
  
// Constructor  
Complex::Complex( double realPart, double imaginaryPart )  
   : real( realPart ),  
   imaginary( imaginaryPart )  
{  
   // empty body  
} // end Complex constructor  
  
// addition operator  
Complex Complex::operator+( const Complex &operand2 ) const  
{  
   return Complex( real + operand2.real,  
      imaginary + operand2.imaginary );  
} // end function operator+  
  
// subtraction operator  
Complex Complex::operator-( const Complex &operand2 ) const  
{  
   return Complex( real - operand2.real,  
      imaginary - operand2.imaginary );  
} // end function operator-  
  
// Overloaded multiplication operator  
Complex Complex::operator*( const Complex &operand2 ) const  
{  
   return Complex(  
      ( real * operand2.real ) + ( imaginary * operand2.imaginary ),  
      ( real * operand2.imaginary ) + ( imaginary * operand2.real ) );  
} // end function operator*  
Complex Complex::operator/( const Complex &operand2 ) const 
{
	return Complex(
	  ( operand2.real / real ) + ( imaginary / operand2.imaginary ),  
      ( real / operand2.imaginary ) + ( imaginary / operand2.real ) );  
}// end function operator/
Complex& Complex::operator=( const Complex &right )  
{  
   real = right.real;  
   imaginary = right.imaginary;  
   return *this;   // enables concatenation  
} // end function operator=  
  
bool Complex::operator==( const Complex &right ) const  
{   
   return ( right.real == real ) && ( right.imaginary == imaginary )  
      ? true : false;   
} // end function operator==   
  
bool Complex::operator!=( const Complex &right ) const  
{  
   return !( *this == right );   
} // end function operator!=  
  
ostream& operator<<( ostream &output, const Complex &complex )  
{  
   output << "(" << complex.real << ", " << complex.imaginary << ")";  
   return output;  
} // end function operator<<  
  
istream& operator>>( istream &input, Complex &complex )  
{  
   input.ignore(); // skip (  
   input >> complex.real;  
   input.ignore( 2 ); // skip ',' and space  
   input >> complex.imaginary;  
   input.ignore(); // skip )  
   return input;  
} // end function operator>> 
void Complex::print() const
{ 
   cout << '(' << real << ", " << imaginary << ')';
} // end function print 


//complex.h//
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef COMPLEX_H  
#define COMPLEX_H  
  
#include <iostream>  
using std::ostream;  
using std::istream;  
  
class Complex  
{  
   friend ostream &operator<<( ostream &, const Complex & );  
   friend istream &operator>>( istream &, Complex & );  
public:  
   Complex( double = 0.0, double = 0.0 ); // constructor  
   Complex operator+( const Complex& ) const; // addition  
   Complex operator-( const Complex& ) const; // subtraction  
   Complex operator*( const Complex& ) const; // multiplication
   Complex operator/( const Complex& ) const; // division
  
   Complex& operator=( const Complex& ); // assignment  
   bool operator==( const Complex& ) const;  
   bool operator!=( const Complex& ) const;  
   void print() const; // output
private:  
   double real; // real part  
   double imaginary; // imaginary part  
}; // end class Complex  
  

#endif

//main.cpp//
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Exercise 11.13 Solution: ex11_13.cpp  
// Complex class test program.  
#include <iostream>  
using std::cout;  
using std::cin;  
using namespace std;
#include "Complex.h"  
  
int main()  
{  
   Complex x;
   Complex y( 4.3, 8.2 );
   Complex z( 3.3, 1.1 );
   Complex k;
   Complex l( 0,   0);  
   Complex m( 0,   0.1 ); 

   cout << "Enter a complex number in the form: (a, b) for Complex object k.\n(Performing >> operator overloading.)\n?  ";  
   cin >> k; // demonstrating overloaded >> 
   cout << "The existing Complex objects are: \n(Performing << operator overloading.)\n";
 
   cout << "x: ";
   x.print();     // demonstrating overloaded << 
   cout << "\ny: ";
   y.print();     // demonstrating overloaded << 
   cout << "\nz: ";
   z.print();     // demonstrating overloaded << 
   cout << "\nk: "; 
   k.print();     // demonstrating overloaded << 
   cout << "\nl: ";
   l.print();     // demonstrating overloaded <<
   cout << "\nm: ";
   m.print();     // demonstrating overloaded <<
   
   cout << endl;
   
   x = y + z; // demonstrating overloaded + and = 
   cout << "\nPerforming +, = and << operators overloading." << endl;
   cout << "x = y + z:\n" << x << " = " << y << " + " << z << "\n";  
  
   x = y - z; // demonstrating overloaded - and =  
   cout << "\nPerforming -, = and << operators overloading." << endl;
   cout << "x = y - z:\n" << x << " = " << y << " - " << z << "\n";  
  
   x = y * z; // demonstrating overloaded * and =  
   cout << "\nPerforming *, = and << operators overloading." << endl;
   cout << "x = y * z:\n" << x << " = " << y << " * " << z << "\n\n";  
   
   x = y / z;// demonstrating overloaded / and = 
   cout << "\nPerforming /, = and << operators overloading." << endl;
   cout << "x = y / z:\n" << x << " = " << y << " / " << z << "\n\n";
   
   x = y / l;// demonstrating overloaded / and = 
   cout << "\nPerforming /, = and << operators overloading with divisor is (0, 0)." << endl;
   cout << "x = y / l:\n" << x << " = " << y << " / " << l << "\n\n";
   
   x = y / m;// demonstrating overloaded / and = 
   cout << "\nPerforming /, = and << operators overloading with divisor is (0, 0.1)." << endl;
   cout << "x = y / m:\n" << x << " = " << y << " / " << m << "\n\n";

   cout << "\nPerforming != and << operators overloading." << endl;
   cout << "check x != k\n";
   if ( x != k ) // demonstrating overloaded !=  
      cout << x << " != " << k << "\n\n";  
  
   cout << "\nPerforming =, == and << operators overloading.\n";
   cout << "assign k to x by using x=k statement.\n";
   cout << "check x == k\n";
   if ( x == k ) // demonstrating overloaded ==  
      cout << x << " == " << k;  
   
   
   system("PAUSE");
   return 0;  
} // end main  


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//OUTPUT OF THE PROBLEM//
Performing /, = and << operators overloading.
x = y / z:
(8.22199, 6.39394) = (4.3, 8.2) / (3.3, 1.1)/*DIVISION DOESNT CALCULATE CORRECTLY*/


Performing /, = and << operators overloading with divisor is (0, 0).
x = y / l:
(1.#INF, 1.#INF) = (4.3, 8.2) / (0, 0)/* instead of (1.#INF, 1.#INF) IT SHOULD BE infinite*/


Performing /, = and << operators overloading with divisor is (0, 0.1).
x = y / m:
(82, 1.#INF) = (4.3, 8.2) / (0, 0.1)/* instead of 1.#INF it should be -43*/


Performing != and << operators overloading.
check x != k
(82, 1.#INF) != (2, 0)/* instead of 1.#INF it should be -43*/


Performing =, == and << operators overloading.
assign k to x by using x=k statement.
check x == k 
/*HERE SHOULD BE ( 2,  0) == ( 2,  0) but doesnt come, the code is there in main */
Press any key to continue . . .
[/code]
As you might surmise from all the wrong division results, your formula for dividing complex numbers is incorrect. Check the formula and try again.

This isn't a test of operator << :
1
2
cout << "x: ";
   x.print();    

but this would be:
cout << "x: " << x;

The output for operator== isn't appearing because the output for operator!= did appear (and you didn't change x or k to make them equal).
what do you mean by "The output for operator== isn't appearing because the output for operator!= did appear (and you didn't change x or k to make them equal).
Either x==k is true or x!=k is true. They can't both be true.
can you correct on the code
No. That is your job. I'm sorry that the info I gave you on the errors in your code were unhelpful.
You need to think logically about your code. If you want to test what happens when x == k, then you need to do something to make x equal to k.
Topic archived. No new replies allowed.