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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 24.06.2019 00:00, Kaylaonfleek0956
Consider the series where in this problem you must attempt to use the ratio test to decide whether the series converges. compute enter the numerical value of the limit l if it converges, inf if it diverges to infinity, minf if it diverges to negative infinity, or div if it diverges but not to infinity or negative infinity.
Answers: 1
image
Computers and Technology, 24.06.2019 15:50, coralaguilar1702
Andy would like to create a bulleted list. how should he do this? andy should click on the bullet icon or select the bullet option from the menu and then type the list. andy should press the shift key and the 8 key at the beginning of each line of text. andy should type the text and then click on the bullet command. andy should press return and the bullets will automatically
Answers: 2
image
Computers and Technology, 24.06.2019 17:40, HealTheWorld
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately
Answers: 2
image
Computers and Technology, 24.06.2019 22:00, dixks
According to your study unit, what is the main reason that improved human relations skills may improve your grades?
Answers: 1
You know the right answer?
Rewrite the definition of the class complexType so that the arithmetic and relational operators are...

Questions in other subjects:

Konu
Mathematics, 26.06.2019 21:30
Konu
Mathematics, 26.06.2019 21:30
Konu
History, 26.06.2019 21:30