Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Detailed Description of functions for all of the code examples below, assume all

ID: 3698612 • Letter: D

Question

Detailed Description of functions for all of the code examples below, assume all variables are of type The complexPO function should output the value of the givae. with an "r ater the imaginary term. There should be no spaces or in before or after the output Note: a specification like +.21ts is very handy for the imaginary part print 5.20-7 30 prints ?»2 . ,99; y.-5.0, compleXP ( ?.y); // 3.00-5.001 The complex3 function takes an integer operator and three complex numbers (six doubles); it provides the result of the operation (1-add, 2 sub, 3-mult) Some examples -1.2: b-3.4: -5.6:d-7.8 prints.80+ i1.20i prints prints -3.00-4.0s prints -32-00-2900 co plex) (1,6e,6f.a,b, e, d)?eemplex, le. t) a.1.2; b.3.4; // : d-9 corpiex3 12,se,&E;,a,b, e,d) :complexple.t) The complex3 () function takes seven (7) arguments as follows - operator designation- 1 add, 2-sub; 3 mult: other-print error - address of real part of result - address of imaginary part of result - real part of operand1 - imaginary part of operand 1 - real part of operand 2 - imaginary part of operand 2 The complex2( function takes an integer operator and two complex numbers (four doubles). The first set of values are both one of the operands and where the result will be placed. The operator has the same meaning as in complex30. Some examples: a 1.2; b-3.4: c 5.6: d7.8 complex2 (a. a,ab, c,d) :complexPla,b) // prints 6.80-11.201 a»1.2; b-3.4; c.-5.6; ds-9.0; complexz (1, sa, b,e,d) :complexPla,b) / prints -4.40-5.60 a 2.0: b 3.0: c 5.0: d-7.0 complexz (2, sa, &b;, c, d) complexP(a,b) / prints -3.00-4.00i a 2.0: b-3.0: c 5.0: d 7.0 complexz (3, &a;, sb,c,d):complexP(a,b) /prints -11.00+29.001 The complex2 () function takes five (5) arguments as follows: -operator designation - 1-add, 2-sub; 3-mult, other-print error - address of real part of result and first operand - address of imaginary part of result and first operand -real part of operand 2 - imaginary part of operand2

Explanation / Answer

Code


/*
* Mandar Shinde.
*/

#include <iostream>
#include <iomanip>
#include <stdio.h>

using namespace std;

// Prints the complex number
void complexP(double real,double imag) {
   cout<<fixed; // used for printing trailing zero if decimal is less than 2 digits.

   if(imag > 0.0)// if imaginary is positive print '+' else '-'
       cout<<setprecision(2)<<real<<" + "<<imag<<"i ";// precision set to 2
   else
       cout<<setprecision(2)<<real<<" - "<<imag*-1.0<<"i ";
}

void complex3(int operation, //IN: operation
               double &resR, //OUT: result
               double &resI, //OUT: result
               double operand1R, //IN: real part of first complex number
               double operand1I, //IN: imaginary part of first complex number
               double operand2R, //IN: real part of second complex number
               double operand2I //IN: imaginary part of second complex number

               ){

   if(operation == 1){
       resR = operand1R + operand2R; //Adding real part
       resI = operand1I + operand2I; //Adding imaginary part
   }
   else if(operation == 2){
       resR = operand1R - operand2R; //Subtracting real part
       resI = operand1I - operand2I; //Subtracting imaginary part
   }
   else
   {
       //Logic for multiplication:
       // (X+Yi) * (P+Qi) = X * P + Yi*Qi + (X*Q + Y*P)i
       // i*i = -1 hence we get X*P - Y*Q + (X*Q + Y*P)i
       // HEre X is operand1R Y is operand1I
       // P is operand2R Q is operand2I
       resR = operand1R * operand2R - operand1I * operand2I;
       resI = operand1R * operand2I + operand2R * operand1I;
   }
}

void complex2(int operation, //IN: operation
               double &resR, //INOUT: real part of first complex number
               double &resI, //INOUT: imaginary part of first complex number
               double operand2R, //IN: real part of second complex number
               double operand2I //IN: imaginary part of second complex number
               ){

   // Comments same as above in complex3 function.
   if(operation == 1){
       resR += operand2R;
       resI += operand2I;
   }
   else if(operation == 2){
       resR -= operand2R;
       resI -= operand2I;
   }
   else
   {
       resR = resR * operand2R - resI * operand2I;
       resI = resR * operand2I + operand2R * resI;
   }
}
int main()
{
   double a,b,c,d,e,f,g,h,x,y;

   g= 5.2; h =7.3; complexP(g,h);
   x = 2.999; y = -5.0; complexP(x,y);

   a = 1.2; b = 3.4; c = 5.6; d = 7.8;
   complex3(1,e,f,a,b,c,d); complexP(e,f);
   a = 1.2; b = 3.4; c = -5.6; d = -9.0;
   complex3(1,e,f,a,b,c,d); complexP(e,f);
   a = 2.0; b = 3.0; c = 5.0; d = 7.0;
   complex3(2,e,f,a,b,c,d); complexP(e,f);
   a = 2.0; b = 3.0; c = 5.0; d = 7.0;
   complex3(3,e,f,a,b,c,d); complexP(e,f);

   a = 1.2; b = 3.4; c = 5.6; d = 7.8;
   complex2(1,a,b,c,d); complexP(a,b);
   a = 1.2; b = 3.4; c = -5.6; d = -9.0;
   complex2(1,a,b,c,d); complexP(a,b);
   a = 2.0; b = 3.0; c = 5.0; d = 7.0;
   complex2(2,a,b,c,d); complexP(a,b);
   a = 2.0; b = 3.0; c = 5.0; d = 7.0;
   complex2(3,a,b,c,d); complexP(a,b);

  
    return 0;
}


Sample output:

5.20 + 7.30i
3.00 - 5.00i
6.80 + 11.20i
-4.40 - 5.60i
-3.00 - 4.00i
-11.00 + 29.00i
6.80 + 11.20i
-4.40 - 5.60i
-3.00 - 4.00i
-11.00 - 62.00i

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote