A complex number has the form a + b i , where a and b arereal numbers and i ² =
ID: 3612797 • Letter: A
Question
A complex number has the form a + bi, where a and b arereal numbers and
i² = -1. The four basic arithmeticoperations for complex numbers are defined as follows:
addition: (a + bi)+(c + di) = (a + c)+(b + d)i
subtraction: (a + bi)-(c + di) = (a - c)+(b - d)i
multiplication: (a + bi)*(c + di) = (ac – bd)+(ad +bc)i
division: a + bi = (ac + bd) + (bc –ad) i
c + di (c² + d²) (c² +d²)
provided both c and d do not equal zero
(a) Write a class tostore complex numbers and provide operations for the four basicarithmetic operations along with input and output operations. (Youmust have a class that has attributes of a real and an imaginarypart. You would have 2 instances of this class for 2 complexnumbers.) Use the time type project in your text to see help youwith two class objects interacting.
(b) Write a program toread two complex numbers and a symbol for one of these operationsand to perform the indicated operations.
(c) Allow your programto continue until the user decides to Quit.
Follow all commenting conventions mentioned in class. Yourprogram must have a comment block at the top of the main methoddescribing the program purpose, input, and output. Name yourclass containing the main method Complex.cpp and your classcontaining the class specification and definition CompClass.h .
Explanation / Answer
please rate - thanks note: input must be identical to the prompt, includingparenthesis #include #include using namespace std; 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; cin>>paren>>real>>comma>>imag>>i>>paren; } void Complex::Outputc(void) {coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.