This is for Compplex nummber in Eng. I need the Pseudocode list of this code: MA
ID: 3822177 • Letter: T
Question
This is for Compplex nummber in Eng.
I need the Pseudocode list of this code:
MAIN.CPP
//Declaration of class Complex
//defined in Complex.cpp
#include <iostream>
#include <iomanip>
#include "Complex.h"
using namespace std;
int main()
{
Complex c1(0,0);
Complex c2(1,2);
Complex c3(8,2);
Complex c4(5,-3);
cout << "HW#8 Complex Numbers in Engineering ";
cout << "Author: Nauman Zubair ";
cout << "Initial Values ";
cout << "c1: ";
c1.print();
cout << setw(10) << "c2: ";
c2.print();
cout << " Assignment Operator c1 = c2" << setw(5);
c1 = c2;
cout << setw(17) << "c1: ";
c1.print();
cout << " Initial Values";
cout << " c3: ";
c3.print();
cout << setw(10) << "c4: ";
c4.print();
cout << " Overloaded + operator ";
Complex c5 = c3 + c4;
cout << "c4 + c3: ";
c5.print();
cout << " Overloaded - operator";
cout << " c4 - c3: ";
c5 = c4 - c3;
c5.print();
cout << " Overloaded * operator";
cout << " c3 * c4: ";
c5 = c3 * c4;
c5.print();
cout << " Overloaded / operator";
cout << " c3 / c4: ";
c5 = c3 / c4;
c5.print();
cout << " = ";
c3.print();
cout << " / ";
c4.print();
cout << " Overloaded || operator";
cout << " c1=c2||c3||c4: ";
c1 = c2||c3||c4;
c1.print();
cout << " = ";
c2.print();
cout << " || ";
c3.print();
cout << " || ";
c4.print();
cin.get();
cin.get();
}
Declaration of class Complex
Complex.h
#ifndef COMPLEX_H
#define COMPLEX_H
class Complex
{
public:
Complex(double, double);
Complex operator+(const Complex &) const;
Complex operator-(const Complex &) const;
Complex operator*(const Complex &) const;
Complex operator/(const Complex &) const;
Complex operator||(const Complex &) const;
void print() const;
private:
double real;
double imaginary;
};
#endif // COMPLEX_H
Complex.cpp Function Definition
#include "Complex.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
Complex::Complex( double realPart, double imaginaryPart )
: real ( realPart ), imaginary( imaginaryPart )
{}
Complex Complex::operator+( const Complex &operand2 ) const
{
return Complex( real + operand2.real, imaginary + operand2.imaginary );
}
Complex Complex::operator-( const Complex &operand2 ) const
{
return Complex ( real - operand2.real , imaginary - operand2.imaginary );
}
Complex Complex::operator*( const Complex &operand2 ) const
{
return Complex( real * operand2.real - imaginary * operand2.imaginary ,
imaginary * operand2.real + real * operand2.imaginary );
}
Complex Complex::operator/( const Complex &operand2 ) const
{
return Complex( (real * operand2.real + imaginary * operand2.imaginary) /
(operand2.real * operand2.real + operand2.imaginary * operand2.imaginary),
(imaginary * operand2.real - real * operand2.imaginary)/
(operand2.real * operand2.real + operand2.imaginary * operand2.imaginary) );
}
Complex Complex::operator||( const Complex &operand2 ) const
{
return (*this * operand2)/(*this + operand2);
}
void Complex::print() const
{
cout << "(" << real << setprecision(2) << fixed << ",";
imaginary >= 0? cout << " j": cout << " -j";
cout << abs(imaginary) << setprecision(2) << fixed << ")";
}
Explanation / Answer
Complex.h Class:
THis is a class created for the complex number representaion. This class has two private attribute which is real and imagenary of type double. This call also has a parametized constructor the real and imagenary part of any complex number. This class has all the arithmatic operator overloaded constant member function to perform the operations which are:
constructor:
it accepts two double type of parameter as realpart and imaginary part of a number and initialize it to private member of complex class.
1)+(plus) : takes the parameter as constant reference of complex type and return a complex type.
perform the addition separately for real part of current complex objext and passed operand 2 and for imaginary part and return the complex {real,imaginary} by forming complex type.
Exa:
Simplify (2 + 3i) + (1 – 6i).
(2 + 3i) + (1 – 6i) = (2 + 1) + (3i – 6i) = 3 + (–3i) = 3 – 3i
2)-(Minus) : takes the parameter as constant reference of complex type and return a complex type.
perform the subtraction separately for real part of current complex objext and passed operand 2 and for imaginary part and return the complex {real,imaginary} by forming complex type.
Exa:
Simplify (5 – 2i) – (–4 – i).
(5 – 2i) – (–4 – i)
= (5 – 2i) – 1(–4 – i) = 5 – 2i – 1(–4) – 1(–i)
= 5 – 2i + 4 + i= (5 + 4) + (–2i + i)
= (9) + (–1i) = 9 – i
3)*(Multiply) : takes the parameter as constant reference of complex type and return a complex type.
perform the multiplication separately for real part of current complex objext and passed operand 2 and for imaginary part and return the complex {real,imaginary} by forming complex type.
Example:
Simplify (2 – i)(3 + 4i).
(2 – i)(3 + 4i) = (2)(3) + (2)(4i) + (–i)(3) + (–i)(4i)
= 6 + 8i – 3i – 4i2 = 6 + 5i – 4(–1)
= 6 + 5i + 4 = 10 + 5i
4)/(devide):takes the parameter as constant reference of complex type and return a complex type.
perform the division separately for real part of current complex objext and passed operand 2 and for imaginary part and return the complex {real,imaginary} by forming complex type.
Multiply both the denominator and the numerator by the conjugate of the denominator
Example: divide 2 + 3i and 4 - 5i
divide complex
Logic:
((2 + 3i)/(4 - 5i)) * ((4 + 5i)/(4 + 5i))
As an example of the steps needed to complete a division problem involving complex numbers, we will simplify .
(2+3i)*(4+5i)/(4-5i)*(4+5i)
Multiply both the numerator and the denominator by the conjugate of the denominator.
Simplify the terms.
and write the answer.
5)||(OR):takes the parameter as constant reference of complex type and return a complex type.
it performs the calcultion on current complext type and the passed operand type.
(multiplying current complex object to passed operand)/(adding current complex type to passed operand).
Here it internally calling the +,* and / member funtion.
6)Print:
THis method simpy prints the real and imaginary part of complex type object.
Main.cpp:
1) It is creating the four complex type object passing the real and imaginary part.
Complex c1(0,0); // internally constructor will get called and assign the real and imaginary values.
Complex c2(1,2);
Complex c3(8,2);
Complex c4(5,-3);
2) then it is printing the values of all the 4 complext object by settign the width of the fields.
Exa: cout << setw(17) << "c1: ";
3) Then it is performing arithmatic operations on these objects.
Complex c5 = c3 + c4; // call the overloaed + operator member function and return result as complex
Print the result.
c5 = c4 - c3; // call the overloaed - operator member function and return result as complex
Print the result.
c5 = c3 * c4; // call the overloaed * operator member function and return result as complex
Print the result.
c5 = c3 / c4; // call the overloaed / operator member function and return result as complex
Print the result.
c1 = c2||c3||c4; // call the overloaed || operator member function and return result as complex
Print the result.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.