Answer to Question #171243 in C++ for aditya

Question #171243

#include<iostream>

using namespace std;

class ComplexNum {

  int r, i;

  public:

    ComplexNum(int _r, int _i) : r(_r), i(_i) { }

    ComplexNum& _____________{ //LINE-1


      __________ //LINE-2

      __________ //LINE-3

    }

    ComplexNum ______________{    //LINE-4


      _________ //LINE-5


      _________ //LINE-6

      return t;

    }


1
Expert's answer
2021-03-13T12:03:53-0500
#include <iostream>
using namespace std;

typedef struct complex {
    float real;
    float imaginary;
} complexNumber;

complexNumber addComplexNumbers(complex, complex);

int main() {
    complexNumber num1, num2, complexSum;
    char signOfImag;

    cout << "For the first complex number:" << endl;
    cout << "Enter the real and imaginary parts of the complex number:" << endl;
    cin >> num1.real >> num1.imaginary;

    cout << endl
         << "For the second complex number:" << endl;
    cout << "Enter the real and imaginary parts of the complex number:" << endl;
    cin >> num2.real >> num2.imaginary;

    complexSum = addComplexNumbers(num1, num2);
    signOfImag = (complexSum.imaginary > 0) ? '+' : '-';
    complexSum.imaginary = (complexSum.imaginary > 0) ? complexSum.imaginary : -complexSum.imaginary;
    cout << "Sum = " << complexSum.real << signOfImag << complexSum.imaginary << "i";

    return 0;
}

complexNumber addComplexNumbers(complex num1, complex num2) {
    complex temp;
    temp.real = num1.real + num2.real;
    temp.imaginary = num1.imaginary + num2.imaginary;
    return (temp);
}

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS