Write c of overloading operator in complex numbers class If we-00474
This subjective question is related to the book/course vu cs302 Digital Logic Design. It can also be found in vu cs302 Mid Term Solved Past Paper No. 2.
Question 1: Write c++ of overloading ^ operator in complex numbers class.
If we have two objects of complex number class as follows,
Complex obj1,obj2;
and we write statement,
Complex obj3 = obj1 ^ obj2;
obj3 real and imaginary parts will be,
obj3.real = (obj1.real) obj2.real and obj3.img = (obj1.img) obj2.img
Hint: You can use c++ built in function power(x,y) that returns the result of x^y.
Private:
Double val;
Complex operator ^(complex c1) {
Return Power(val,c1.val);
}
};
If we have two objects of complex number class as follows,
Complex obj1,obj2;
and we write statement,
Complex obj3 = obj1 ^ obj2;
obj3 real and imaginary parts will be,
obj3.real = (obj1.real) obj2.real and obj3.img = (obj1.img) obj2.img
Hint: You can use c++ built in function power(x,y) that returns the result of x^y.
Answer:
Class complex {Private:
Double val;
Complex operator ^(complex c1) {
Return Power(val,c1.val);
}
};