#include #include #include "complex.h"using namespace std;int main(){// Construct 2 complex numbersComplex test1 = Complex(1,2);Complex test2 = Complex(3,4);cout < "test1:="">test1.print();cout <>cout < "test2:="">test2.print();cout <>Complex addition = test1.add(test2);cout <"add:>"add:>addition.print();cout <>Complex multiplication = test1.multiply(test2);cout <"multiply:>"multiply:>multiplication.print();cout <>Complex division = test1.divide(test2);cout <"divide:>"divide:>division.print();cout <>Complex conjugate_value = test1.conjugate();cout <"complex conjugate:="">"complex>conjugate_value.print(); cout <>return 0;}Extracted text: Requirements • Data members // a+bi double real;// a o double imag; // b • Member functions: Complex(double, double); Complex add(Complex); Complex multiply(Complex); Complex divide(Complex); Complex conjugate(); o void print(); // a+bi Introduction to Computers II 3Extracted text: Complex Number » Please upload complex.h and complex.cpp to realize the Complex class. » A complex number contains the real part and the imaginary part, a+bi, where a and b are real numbers and i=(-1)0.5 represents the imaginary unit. · Ex) • (1+2i) + (3+4i) = (1+2i) * (3+4i) = (-3+10i) (4+6i) Introduction to Computers II 2
#include #include "complex.h"using namespace std;int main(){// Construct 2 complex numbersComplex test1 = Complex(1,2);Complex test2 = Complex(3,4);cout < "test1:="">test1.print();cout <>cout < "test2:="">test2.print();cout <>Complex addition = test1.add(test2);cout <"add:>"add:>addition.print();cout <>Complex multiplication = test1.multiply(test2);cout <"multiply:>"multiply:>multiplication.print();cout <>Complex division = test1.divide(test2);cout <"divide:>"divide:>division.print();cout <>Complex conjugate_value = test1.conjugate();cout <"complex conjugate:="">"complex>conjugate_value.print(); cout <>return 0;}Extracted text: Requirements • Data members // a+bi double real;// a o double imag; // b • Member functions: Complex(double, double); Complex add(Complex); Complex multiply(Complex); Complex divide(Complex); Complex conjugate(); o void print(); // a+bi Introduction to Computers II 3Extracted text: Complex Number » Please upload complex.h and complex.cpp to realize the Complex class. » A complex number contains the real part and the imaginary part, a+bi, where a and b are real numbers and i=(-1)0.5 represents the imaginary unit. · Ex) • (1+2i) + (3+4i) = (1+2i) * (3+4i) = (-3+10i) (4+6i) Introduction to Computers II 2
#include "complex.h"
using namespace std;
int main(){
// Construct 2 complex numbers
Complex test1 = Complex(1,2);
Complex test2 = Complex(3,4);
cout < "test1:="">
test1.print();
cout <>
cout < "test2:="">
test2.print();
Complex addition = test1.add(test2);
cout <"add:>"add:>
addition.print();
Complex multiplication = test1.multiply(test2);
cout <"multiply:>"multiply:>
multiplication.print();
Complex division = test1.divide(test2);
cout <"divide:>"divide:>
division.print();
Complex conjugate_value = test1.conjugate();
cout <"complex conjugate:="">"complex>
conjugate_value.print(); cout <>
return 0;
}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here