#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;
}
#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);
}
Comments
Leave a comment