I have no clue where to even begin on this HW Assignment.

The code is attached below for class for complex number. Provide operator overloading functions to facilitate the following operations on any complex numbers A, B and C:
A == B; overload Boolean operator == to test if A and B are equal
C = A*B; overload multiplication operator *
A = B; overload assignment operator =
cin >> A >> B; overload stream operator >> to take user input for real and imaginary part of the number (You might want to create a friend function to facilitate this)
Also, write a static function for the complexNumber class which initializes numCount variable. Your function takes an integer argument provided by user. Assign this argument to numCount variable.

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
  #include <iostream>
 
using namespace std;
 
 
class complexNumber {
private:
static int numCount; int Re, Imag;
public:
complexNumber(){numCount++;} // constructor with no argument
 
complexNumber(int Real, int Imaginary){numCount++; cout << "constructor with argument is called" << endl;
Re = Real; Imag = Imaginary;}// constructor with arguments
 
~complexNumber(){cout << "destructor is called" <<endl; numCount--;}
 
complexNumber (complexNumber &anycomplex) {numCount++; cout <<endl; cout <<"Copy constructor called" << endl; Re = anycomplex.Re; Imag = anycomplex.Imag;} // copy constructor
 
void printComplex(){ cout <<"number of active complex numbers= " << numCount << " and present number.....= " << Re <<" + j" << Imag << endl;}
 
complexNumber operator+(complexNumber &b){complexNumber temp; cout << "overloaded + iscalled" << endl; temp.Re = Re + b.Re; temp.Imag = Imag + b.Imag; return temp;}
 
complexNumber operator++(){complexNumber temp; cout << "overloaded ++(pre) called" << endl; temp.Re = ++Re; temp.Imag = ++Imag; return temp;}
 
complexNumber operator++(int){complexNumber temp; cout << "overloaded ++(post) called" << endl; temp.Re = Re++; temp.Imag = Imag++; return temp;}
 
friend ostream & operator<< (ostream &out, complexNumber &somecomplex){cout << "overloaded << called" <<endl; out << somecomplex.Re<<"+ j" << somecomplex.Imag; return out;}
 
};
 
int complexNumber::numCount = 0 ;
 
void printC(complexNumber a) {a.printComplex();}
 
int main (){
complexNumber A, B(1,2), C(2,3);
B.printComplex();
++ B;
printC(C);
A = B + C;
A = B++;
A.printComplex();
B.printComplex();
cout << A << B;
cin.get();
 
 
return 0;
}
Topic archived. No new replies allowed.