subject

Rewrite the definition of the class complexType so that the arithmetic and relational operators are overloaded as nonmember functions. Write a test program that tests various operations on the class complexType. Format your answer with two decimal places. complexType. h//Specification file complexType. h#ifndef H_complexNumber#define H_complexNumber#include using namespace std;class complexType{// overload stream insertion and extraction operatorsfriend ostream& operator<< (ostream&, const complexType&);friend istream& operator>> (istream&, complexType&);friend complexType operator+(const complexType& one, const complexType& two);//overload +friend complexType operator*(const complexType& one, const complexType& two);//overload *friend complexType operator-(const complexType& one, const complexType& two);//overload -friend complexType operator/(const complexType& one, const complexType& two);//overload /friend bool operator==(const complexType& one, const complexType& two);//overload ==public:void setComplex(const double& real, const double& imag);//Function to set the complex number according to the parameters//Postcondition: realPart = real; imaginaryPart = imagvoid getComplex(double& real, double& imag) const;//Function to retrieve the complex number.//Postcondition: real = realPart; imag = imaginaryPartcomplexType(double real = 0, double imag = 0);//constructorprivate:double realPart; // variable to store the real partdouble imaginaryPart; // variable to store the imaginary part};complexType. cpp//Implementation file complexType. cpp#include #include "complexType. h"using namespace std;ostream& operator<< (ostream& os, const complexType& complex){os << "(" << complex. realPart << ", "<< complex. imaginaryPart << ")";return os;}istream& operator>> (istream& is, complexType& complex){char ch;is >> ch; //read and discard (is >> complex. realPart; //get the real partis >> ch; //read and discard, is >> complex. imaginaryPart; //get the imaginary partis >> ch; //read and discard)return is;}bool complexType::operator==(const complexType& otherComplex) const{return(realPart == otherComplex. realPart &&imaginaryPart == otherComplex. imaginaryPart);}//constructorcomple xType::complexType(double real, double imag){realPart = real;imaginaryPart = imag;}void complexType::setComplex(const double& real, const double& imag){realPart = real;imaginaryPart = imag;}void complexType::getComplex(double& real, double& imag) const{real = realPart;imag = imaginaryPart;}//overload the operator +complexType complexType::operator+(const complexType& otherComplex) const{complexType temp;temp. realPart = realPart + otherComplex. realPart;temp. imaginaryPart = imaginaryPart + otherComplex. imaginaryPart;return temp;}//overload the operator *complexType complexType::operator*(const complexType& otherComplex) const{complexType temp;temp. realPart = (realPart * otherComplex. realPart) -(imaginaryPart*otherComplex. imaginaryPart);temp. imaginaryPart = (realPart * otherComplex. imaginaryPart) +(imaginaryPart * otherComplex. realPart);return temp;}complexType complexType::operator-(const complexType& otherComplex) const{complexType temp;temp. realPart = realPart - otherComplex. realPart;temp. imaginaryPart = imaginaryPart - otherComplex. imaginaryPart;return temp;}complexType complexType::operator/(const complexType& otherComplex) const{complexType temp;double denominator;if (otherComplex. realPart == 0 && otherComplex. imaginaryPart == 0){cout << "Cannot divide by zero" << endl;return otherComplex;}else{denominator = otherComplex. realPart * otherComplex. realPart +otherComplex. imaginaryPart * otherComplex. imaginaryPart;temp. realPart = ((realPart * otherComplex. realPart) +(imaginaryPart * otherComplex. imaginaryPart)) /denominator ;temp. imaginaryPart = ((- realPart * otherComplex. imaginaryPart) +(imaginaryPart * otherComplex. realPart)) /denominator;return temp;}}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
3. (6 pts) internally in the computer, with few exceptions, all numerical computation is done using binary numbers. output, however, often uses ascii, which is formed by appending 011 to the left of a bcd code. thus, an algorithm that directly converts a binary integer to a bcd integer is very useful. here is one such algorithm 1) draw lines to the left of the binary number to bound the expected bcd decades. (each decade is a group of 4 bits.) move the binary number one bit to the left. add 0011 to each bcd decade containing a binary value> 0100 repeat steps 2-3 until the last bit in the binary number has been moved into the least significant decade position. (note that when the last bit has been shifted into bcd decade, step 3 is not repeated.) read the bcd result. 2) 3) 4) 5) a) execute the algorithm for the binary number 1101101 b) execute the algorithm for the binary number 01110101110 4. (4 pts) represent the decimal number 3568 in bcd; excess-3 code; ascil; and hex.
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
When working with a team you should always do the following, except? question 3 options: be dependable and trustworthy be sensitive to others feelings do your fair share critique members of the group
Answers: 2
question
Computers and Technology, 23.06.2019 06:00
When is a chart legend used a. all the time b. whenever you are comparing data that is the same c. whenever you are comparing multiple sets of data d. only for hand-drawn charts
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
The option enables you to modify a slide element in most presentation applications.
Answers: 2
You know the right answer?
Rewrite the definition of the class complexType so that the arithmetic and relational operators are...
Questions
Questions on the website: 13722360