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

Using C programming.. define a structured type with real and imaginary parts to

ID: 3609789 • Letter: U

Question

Using C programming..
define a structured type with real and imaginary parts to representa complex number. implement a menu-driven program that will firstallow us to enter two complex number by entering their components,separated by whitespace, in the order real1imag1 real2 imag2. thenpresent a menu with options to add, subtract, multiply or divide.display the input and the result after each operation. write fourfunctions to perform the complex operations defined next, andinstall them in an array of functions that can be called using themenu selection. these functions should accept two structuredarguments, do the computations, store the answer in a local complexvariable, and return the value of the variable. in these formulas,C1, C2 are two complex numbers: C1= a+bi and C2=c+di.
C1 + C2 = (a+c) + (b+d)i
    C1 - C2 = (a-c) +(b-d)i
    C1 x C2 = (ac-bd) +(ad+bc)i
    C1 / C2 = [(ac+bd) +(bc-ad)i]/(c2+d2) Using C programming..
define a structured type with real and imaginary parts to representa complex number. implement a menu-driven program that will firstallow us to enter two complex number by entering their components,separated by whitespace, in the order real1imag1 real2 imag2. thenpresent a menu with options to add, subtract, multiply or divide.display the input and the result after each operation. write fourfunctions to perform the complex operations defined next, andinstall them in an array of functions that can be called using themenu selection. these functions should accept two structuredarguments, do the computations, store the answer in a local complexvariable, and return the value of the variable. in these formulas,C1, C2 are two complex numbers: C1= a+bi and C2=c+di.
C1 + C2 = (a+c) + (b+d)i
    C1 - C2 = (a-c) +(b-d)i
    C1 x C2 = (ac-bd) +(ad+bc)i
    C1 / C2 = [(ac+bd) +(bc-ad)i]/(c2+d2)

Explanation / Answer

please rate - thanks you may want to check the arithmetic sample run enter a complex number pair such as(5.1,2.3i):(5.1,2.3i) enter a complex number pair such as (5.1,2.3i):(5.1,2.3i) enter choice: (a)dd, (s)ub,(m)ult, (d)ivide:m (20.72,23.46i) #include #include #include #include class Complex {public: void Inputc(); void Outputc(); Complex operator+(Complex x); Complex operator-(Complex x); Complex operator*(Complex x); Complex operator/(Complex x); private: float real,imag; }; Complex Complex::operator + (Complex x) {Complex temp; temp.real=real+x.real; temp.imag=imag+x.imag; return(temp);} Complex Complex::operator - (Complex x) {Complex temp; temp.real=real-x.real; temp.imag=imag-x.imag; return(temp);} Complex Complex::operator *(Complex x) {Complex temp; temp.real=(real*x.real)-(imag*x.imag); temp.imag=(imag*x.real)+(real*x.imag); return(temp);} Complex Complex::operator / (Complex x) {Complex temp; temp.real=((real*x.real)+(imag*x.imag))/(x.real*x.real+x.imag*x.imag); temp.imag=((imag*x.real)-(real*x.imag))/(x.real*x.real+x.imag*x.imag); return(temp);} void Complex::Inputc(void) {char i,paren,comma,trash; scanf("%c%f%c%f%c%c",&paren,&real,&comma,&imag,&i,&paren); trash=getchar();} void Complex::Outputc(void) {printf("(%.2f,%.2fi) ",real,imag);} int main() {char choice,trash; Complex a,b,c; printf("enter a complex number pair such as (5.1,2.3i):"); a.Inputc(); printf("enter a complex number pair such as (5.1,2.3i):"); b.Inputc(); printf("enter choice: (a)dd, (s)ub,(m)ult, (d)ivide:"); choice=getchar(); trash=getchar(); switch (choice) {case'a':c=a+b;            break; case's': c=a-b;          break; case'm':c=a*b;          break; case'd':c=a/b;         break;        default: printf("error");} //cout
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