Question: For this assignment, you will make changes to the previous coding to now include the following upgrades: a) Modify the class to enable input and

For this assignment, you will make changes to the previous coding to now include the

following upgrades:

a)

Modify the class to enable input and output of complex numbers via overloaded +

and - operators, respectively (addition and subtraction).

b)

Modify the class to enable input and output of complex numbers via overloaded =

and * operators, respectively (assignment and multiplication).

c)

Modify the class to enable input and output of complex numbers via overloaded >>

and

class). Use friend functions to accomplish this.

d)

Overload the == and != operators to allow comparisons of complex numbers.

e)

Add friend member functions to enable input and output of complex numbers via

overloaded >> and

from the class).

Change the Complex class definition, the Complex class member-function definitions, and

modify the driver program as appropriate. Please use the following code and replace your

main function, or driver function, with the test code included below. Use these test cases

now, and execute the test cases successfully to ensure full credit.

int main()

{

for (double i = 1; i

{

Complex y{i * 2.7, i + 3.2};

Complex z{i * 6, i + 8.3};

Complex x;

Complex k;

std::cout

std::cin >> k; // demonstrating overloaded >>

std::cout

x = y + z; // demonstrating overloaded + and =

std::cout

x = y - z; // demonstrating overloaded - and =

std::cout

x = y * z; // demonstrating overloaded * and =

std::cout

if (x != k) { // demonstrating overloaded !=

std::cout

}

std::cout

x = k;

=================================================================================================

Below is what I have so far but I'm stuck. Please do not rewrite the code, simply fix it! (Code for copy below)

For this assignment, you will make changes to the previous coding to

now include the following upgrades: a) Modify the class to enable input

and output of complex numbers via overloaded + and - operators, respectively

#include #include #include

using std::cout; using std::cin; using std::string; using std::endl;

// build your class and member functions here class Complex {

public:

double realPart; double imaginaryPart;

Complex() // default constructor { realPart = 0.0; imaginaryPart = 0.0; }

Complex (double r, double q) { realPart = r; imaginaryPart = q; }

// member function "add" adds two complex numbers // Pre: pass an object from Complex // Post: returns the sum of two complex numbers Complex add(Complex next) { double r = realPart + next.realPart; double q = imaginaryPart + next.imaginaryPart; return Complex(r,q); }

Complex operator+(Complex next) { return add(next); }

// member function "subtract" subtracts two complex numbers // Pre: pass an object from Complex // Post: returns the difference of two complex numbers Complex subtract (Complex next) { double r = realPart - next.realPart; double q = imaginaryPart - next.imaginaryPart; return Complex(r,q); }

Complex operator-(Complex next) { return subtract(next); }

// member function "multiply" multiplies two complex numbers // Pre: pass an object from Complex // Post: returns the product of two complex numbers Complex multiply (Complex next) { double real1 = realPart * next.realPart; // 1st real element * 2nd real element produces a real element double real2 = (imaginaryPart * next.imaginaryPart) * -1; // 1st imag. element * 2nd imag. element produces a real element * i^2 where i^2 = -1 double imaginary1 = realPart * next.imaginaryPart; // 1st real element * 2nd imag. element produces an imag. element double imaginary2 = imaginaryPart * next.realPart; // 1st imag. element * 2nd real element produces an imag. element

double r = real1 + real2; double q = imaginary1 + imaginary2; return Complex(r,q); }

Complex operator*(Complex next) { return multiply(next); }

void setComplexNumber (int a, int b) { realPart = a; imaginaryPart = b; }

};

int main() { for (double i = 1; i > k; // demonstrating overloaded >> std::cout include #include #include iostream 10 12 13 14 15 16 asing std::cout: using std: :in using std: :string: using std: :endl: 18 19 20 21 11d your class and member runctions her class Complex public: 23 double realPart: double imaginaryPart: 25 26 27 28 29 30 31 32 Complex ) rea1Part-0.0; maginaryPart -0.0: 34 35 36 37 38 39 40 41 92 Complex (double r, double q imaginaryPart / member function"add adds two complex nunber :pasa an object rrom complex Post: returns th mof tWO COmplex numbera Complex add (Complex next) 45 46 47 98 double ealPart next realPart double qimaginaryPart next.inaginaryPar return Complex (,q 50 51 52 53 54 Complex operator+ (Complex next) return add (next) // member function "subtzacE" subtEaCtS O complex numbers R: pass an object fxom Complex 7Postc: recurna the ditterence of tHo conplex number Complex subcract (Complex next) 56 57 58 59 60 61 62 63 64 65 double rrealPartnext.realPart: doubleimaginaryPartnext.imaginaryBart return Complex (,q) Complex operator-(Complex next) 67 69 69 70 71 72 73 74 75 76 return aubtract (next) / member function "multiply" multiplies two complex number Rs: pass an object fzom Complex Post: returns the prod of two complex numbers Complex maltiply Complex next) double reall- realPart next.realPart; double rea12- (Imagina ryPart next. ImaginaryPart) * -1; // 1st anaa -element double imaginary! = realpart next. imaginarypart; double imaginary2imaginaryPartnext.realPart: 1st Ist real lement 2 real element producesa rea 2wes www- ment produces T 1at real element 2nd anaag element pz naselement 2adeal element pa an imag elemen es an emen 79 79 80 31 82 83 94 35 86 87 89 89 90 91 92 93 94 95 96 double r = reali + real2 ; double qimaginarylimaginary2: return Complex (, Complex operator(Complex next) return multiply (next) void setComplexNumber int a, int b) realParta: imaginaryPartb 01 102 103 int main () for (double i-l; 10; ++ i) Complex y{i * 2.7, i 3.2); Complex z/1 * 6, i + 8.3); Complex Complex std: :cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!