Answer to Question #256471 in C++ for Buzz

Question #256471

Write a program to find the absolute value of a complex number (√(x^2+y^2)) using operator overloading of void return type.


1
Expert's answer
2021-10-25T17:55:52-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Buzz
26.10.21, 17:28

Thanks AssignmentExpert!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS