reate a multiplication operator function for the Complex class in Program 11.8 that multiplies two complex numbers. Use the relationship that (a + bi) × (c + di) = (ab − bd) + (ad + bc)i. b. Include the function constructed for Exercise 4a in a complete C++ program. #include #include using namespace std; //declaration section class Complex { private: double realpart; double imaginarypart; public: Complex(double real = 0.0, double imag = 0.0) { realpart = real; imaginarypart = imag;} void showcomplexvalues(); //accessor prototype void assignnewvalues(double real, double imag) //inline mutator { realpart = real; imaginarypart = imag;} }; //End of the class declaration //Implementation section void Complex::showcomplexvalues() //Accessor { char sign = '+'; if (imaginarypart < 0) sign = '-'; cout << realpart << ' ' << sign << ' ' << abs(imaginarypart) << 'i'; } int main() { cout << "Complex number a is "; a.showcomplexvalues(); cout << "\nComplex number b is "; b.showcomplexvalues(); cout << "\n\nThe Product of a and b: "; c.showcomplexvalues(); system("pause"); return 0;
Create a multiplication operator function for the Complex class in
(ab − bd) + (ad + bc)i.
b. Include the function constructed for Exercise 4a in a complete C++ program.
#include <iostream> #include <iomanip> using namespace std;
//declaration section class Complex { private: double realpart; double imaginarypart;
public: Complex(double real = 0.0, double imag = 0.0) { realpart = real; imaginarypart = imag;}
void showcomplexvalues(); //accessor prototype
void assignnewvalues(double real, double imag) //inline mutator { realpart = real; imaginarypart = imag;}
}; //End of the class declaration
//Implementation section void Complex::showcomplexvalues() //Accessor
{ char sign = '+'; if (imaginarypart < 0) sign = '-'; cout << realpart << ' ' << sign << ' ' << abs(imaginarypart) << 'i'; }
int main() {
cout << "Complex number a is "; a.showcomplexvalues(); cout << "\nComplex number b is "; b.showcomplexvalues();
cout << "\n\nThe Product of a and b: "; c.showcomplexvalues(); system("pause"); return 0; } |

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images









