Question: #include #include using namespace std; struct Complex { double a, b; void printComplex(void); Complex addComplex(Complex); Complex subtractComplex(Complex); Complex multiplyComplex(Complex); Complex divideComplex(Complex); }; int main(void) {
#include
#include
using namespace std;
struct Complex {
double a, b;
void printComplex(void);
Complex addComplex(Complex);
Complex subtractComplex(Complex);
Complex multiplyComplex(Complex);
Complex divideComplex(Complex);
};
int main(void) {
int size = 3;
Complex z1 = { 3,4 };
Complex z2 = { 5,0 };
Complex z3;
z3.a = 6;
z3.b = -8;
cout << "Adding, Subrtacting, Multiplying and Devidiing Complex Numbers" << endl;
Complex z4 = z3.addComplex(z1);
z4.printComplex();
Complex z5 = z3.subtractComplex(z2);
z5.printComplex();
Complex z6 = z3.multiplyComplex(z1);
z6.printComplex();
Complex z7 = z3.divideComplex(z1);
z7.printComplex();
system("pause");
return(0);
}
void Complex::printComplex(void) {
if (b >= 0)
cout << a << " + " << b << "i" << endl;
else
cout << a << " - " << -1 * b << "i" << endl;
}
Complex Complex::addComplex(Complex arg) {
Complex x;
x.a = a + arg.a;
x.b = b + arg.b;
return(x);
}
Complex Complex::subtractComplex(Complex arg) {
Complex x;
x.a = a - arg.a;
x.b = a - arg.b;
return(x);
}
Complex Complex::multiplyComplex(Complex arg) {
Complex x;
x.a = a * arg.a - b * arg.b;
x.b = b * arg.b - a * arg.a;
return (x);
}
Complex Complex::divideComplex(Complex arg) {
Complex x;
x.a = a / arg.a - b / arg.b;
x.b = b / arg.b - a / arg.a;
return (x);
}
I need help adding magnitude i had a complete brain fart the function must me :
double magnitude(void);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
