I need assistance with this project. I have it started, but I\'m unsure where to
ID: 3563959 • Letter: I
Question
I need assistance with this project. I have it started, but I'm unsure where to continue. The following is the rubric, then what I have so far. I would greatly appreciate some assistance.
THIS IS WHAT I HAVE SO FAR:
http://pastebin.com/kunSX0Mx
Program Features: Looping structure: switch structure, variables, data input and output, mathematical operators, user-defined functions. Write a C++ Win32 Console application that will perform a number of operations on complex numbers. The application shall use a main function that presents the user with a display that resembles the following. Complex Number A: Real: Imaginary: Magnitude: Angle: Complex Number B: Real: Imaginary: Magnitude: Angle: Complex Number C: Real: Imaginary: Magnitude: Angle: Enter Complex Number A in Rectangular Form. Enter Complex Number A in Polar Form. Enter Complex Number B in Rectangular Form. Enter Complex Number B in Polar Form. Add the two Complex Numbers: C = A + B. Find the Complex Conjugate: C = A*. Multiply the two Complex Numbers: C = AB Divide the two Complex Numbers: C = A / B. End the program. Select Option: Write the main function in such a way that an improper response will cause the menu items to be repeated. Write a user-defined function to perform each of the operations shown in the Main Menu. Pass the arguments to the user-defined functions by reference. The results shall immediately be updated after each menu selection. All angles shall be stored and presented as integers in degrees. Take care to determine the Phase Angle such that the complex number is located in the appropriate quadrant of the Complex Plane. Use double-precision floating-point numbers in performing the calculations. After each of the Complex Number Arithmetic Operations, present the result in Rectangular and in Polar form.Explanation / Answer
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
double const PI = 4 * atan(1);
void input_rectangular(double& real, double& imag)
{
cout << "Enter the real part: ";
cin >> real;
cout << "Enter the imaginary part: ";
cin >> imag;
}
void input_polar(double& mag, int& angle)
{
cout << "Enter the Magnitude : ";
cin >> mag;
cout << "Enter the Angle : ";
cin >> angle;
}
void rect_to_polar(double& real, double& imag, double& mag, int& ang)
{
mag = sqrt(real*real + imag*imag);
ang = atan2(imag, real) * 180 / PI;
}
void polar_to_rect(double& mag, int& ang, double& real, double& imag)
{
real = mag*cos((float)ang*PI/180);
imag = mag*sin((float)ang* PI / 180);
}
void conju_real(double& real, double& imag,double& real1, double& imag1)
{
real1 = real;
imag1 = -imag;
}
void sum_rect(double& realA, double& imagA,double& realB, double& imagB,double& realC, double& imagC)
{
realC=realA+realB;
imagC=imagA+imagB;
}
void div_rect(double& realA, double& imagA,double& realB, double& imagB,double& realC, double& imagC)
{
float temp;
temp=((realB*realB)+(imagB*imagB));
realC=((realA*realB)+(imagA*imagB))/temp;
imagC=((imagA*realB)-(imagB*realA))/temp;
realC=realA+realB;
imagC=imagA+imagB;
}
void mult_rect(double& realA, double& imagA,double& realB, double& imagB,double& realC, double& imagC)
{
realC=realA*realB-imagA*imagB;
imagC=realA*imagB+realB*imagA;
}
int main()
{
double ReA = 0.0, ImA = 0.0, MagA = 0.0;
int AngA = 0;
double ReB = 0.0, ImB = 0.0, MagB = 0.0;
int AngB = 0;
double ReC = 0.0, ImC = 0.0, MagC = 0.0;
int AngC = 0;
int selection;
do
{
system("cls");
cout<<"-------------------------------------------------------------------"<<endl<<endl;
cout << "Complex Number A: Real " << ReA << " Imaginary " << ImA << " Mag " << MagA << " Ang " << AngA << endl;
cout << "Complex Number B: Real " << ReB << " Imaginary " << ImB << " Mag " << MagB << " Ang " << AngB << endl;
cout << "Complex Number C: Real " << ReC << " Imaginary " << ImC << " Mag " << MagC << " Ang " << AngC << endl;
cout << "Main Menu" << endl;
cout << endl;
cout << "1. Enter Complex Number A in rectangular form." << endl;
cout << "2. Enter Complex Number A in Polar form." << endl;
cout << "3. Enter Complex Number B in rectangular form." << endl;
cout << "4. Enter Complex Number A in Polar form." << endl;
cout << "5. Add the two Complex Number: C=A+B." << endl;
cout << "6. Find the Complex Conjugate: C=A*" << endl;
cout << "7. Multiply two Complex Number C=A*B" << endl;
cout << "8. Divide two Complex Number C=A/B" << endl;
cout << "9. End " << endl;
cout << endl;
cout<<"-------------------------------------------------------------------"<<endl<<endl;
cout << "Please make selection : ";
cin >> selection;
switch (selection)
{
case 1:
cout << "You have selected 1." << endl;
cout<<"*******Enter Rectangular Complex A ( x + i y) *********"<<endl;
input_rectangular(ReA, ImA);
rect_to_polar(ReA, ImA, MagA, AngA);
break;
case 2:
cout << "You have selected 2." << endl;
cout<<"*******Enter Polor Complex ( Mag A , Angle A) *********"<<endl;
input_polar(MagA, AngA);
polar_to_rect(MagA, AngA, ReA, ImA);
break;
case 3:
cout << "You have selected 3." << endl;
cout<<"*******Enter Rectangular Complex B (x + i y)*********"<<endl;
input_rectangular(ReB, ImB);
rect_to_polar(ReB, ImB, MagB, AngB);
break;
case 4:
cout << "You have selected 4." << endl;
cout<<"*******Enter Polor Complex ( Mag B , Angle B) *********"<<endl;
input_polar(MagB, AngB);
polar_to_rect(MagB, AngB, ReB, ImB);
break;
case 5:
cout << "You have selected 5." << endl;
sum_rect(ReA,ImA,ReB,ImB,ReC,ImC);
rect_to_polar(ReC, ImC, MagC, AngC);
break;
case 6:
cout << "You have selected 6." << endl;
conju_real(ReA,ImA,ReC,ImC);
rect_to_polar(ReC, ImC, MagC, AngC);
break;
case 7:
cout << "You have selected 7." << endl;
mult_rect(ReA,ImA,ReB,ImB,ReC,ImC);
rect_to_polar(ReC, ImC, MagC, AngC);
break;
case 8:
cout << "You have selected 8." << endl;
div_rect(ReA,ImA,ReB,ImB,ReC,ImC);
rect_to_polar(ReC, ImC, MagC, AngC);
break;
default: cout << "Please make a proper choice." << endl;
}
} while (selection != 9);
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.