Computers and Technology

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;}}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 15:00, cia196785920
Look at the circuit illustrated in the figure above. assume that the values of r1 and r2 are equal. if you connect your meter’s test probes to points a and b in the circuit, which of the following voltages would you measure
Answers: 1
image
Computers and Technology, 22.06.2019 18:00, Geo777
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
image
Computers and Technology, 23.06.2019 01:00, lusciousl
Petrică, tânăr licean în clasa a ix-a, a primit în dar de la părinţii săi un cont bancar pentru micile sale cheltuieli curente. el este pasionat de internet banking şi îşi verifică cu grijă toate tranzacţiile efectuate. pentru creşterea securităţii tranzacţiilor online, banca îi furnizează lui petrică un număr pe care el va trebui să îl modifice, obţinând un număr tan – număr de autentificare a tranzacţiei (transaction authentication number). regula de obţinere a numărului tan este următoarea: se formează cel mai mic număr par din toate cifrele numărului furnizat de bancă. cerinţă cunoscând numărul n furnizat de bancă, să se determine numărul tan obţinut de petrică. date de intrare fişierul tan. in conţine pe prima linie numărul natural n cu semnificaţia din enunţ. date de ieşire fişierul de ieşire tan. out va conţine o singură linie pe care va fi scris numărul tan cerut. restricţii • 0 < n < 18*1018 • n are cel puţin o cifră pară • numărul tan obţinut nu poate conţine zerouri nesemnificative
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, fordkenae
Which is a possible benefit of having a good credit history? having a checking account low interest rate on a car loan high interest rate on a credit card offer bankruptcy
Answers: 1
Do you know the correct answer?
Rewrite the definition of the class complexType so that the arithmetic and relational operators are...

Questions in other subjects:

Konu
Chemistry, 04.12.2020 01:50
Konu
English, 04.12.2020 01:50
Konu
Mathematics, 04.12.2020 01:50
Konu
Social Studies, 04.12.2020 01:50