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, 22.06.2019 11:30
Awell-diversified portfolio needs about 20-25 stocks from different categories is this true or false?
Answers: 2
question
Computers and Technology, 23.06.2019 06:00
What makes myhexadecimalnumber a child of mynumber? which methods does myhexadecimalnumber inherit directly from the mynumber class? what can an instance of the mynumber class do? what can an instance of the myhexadecimalnumber class do? which methods are overridden? why are they overridden? how many examples of overloading are there? why was this done? where is the super keyword used? what is it doing? why isn’t the incoming value set immediately in the second myhexadecimalnumber constructor? how many examples can you find of an inherited method being called?
Answers: 1
question
Computers and Technology, 23.06.2019 11:30
Me dangers of social media and the internetexplain what each means: 1) social media and phones have become an addiction.2) outside people have access to you all the time.3) cyberstalking4) cyberbullying5) catphishing6) viruses7) identity theft8) credit card fraud9) hacking10) money schemes
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words.size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words.size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
You know the right answer?
Rewrite the definition of the class complexType so that the arithmetic and relational operators are...
Questions
question
Mathematics, 24.09.2019 12:10
question
English, 24.09.2019 12:10
question
Mathematics, 24.09.2019 12:10