Write a program to find the absolute value of a complex number (√(x^2+y^2)) using operator overloading of void return type.
#include <iostream>
#include <complex>
double operator=(const std::complex<double> &c) {
return sqrt(c.real()*c.real() + c.imag()*c.imag());
}
int main() {
std::complex<double> c = 1. + 2i;
double a = c;
std::cout << a << std::endl;
return 0;
}
Comments
Thanks AssignmentExpert!
Leave a comment