1) Write the definitions of the class complexType. 2) Write a test program that implementing the operators in the class complexType. a) Create a complex number with the real and imaginary part values as 5 and 6, respectively. Let's assume the object as 'numl' in the below output example b) Create a default complex number. e) Design a code to prompt a user for the real and imaginary values from the default object. d) Use the operators +, - and display their results. e) Use the operator == to check whether the complex numbers are the same and display the appropriate statements like the sample output using operator overloading.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in c++ header file is included as second pic

Define the class complexType so that it performs the subtraction and summation operations.
Set the complex number according to the parameters such as realPart = real; imaginaryPart = imag
Design a constructor no-argument to initialize the complex number
Design a constructor to initialize the complex number according to the parameters
• Overload the operators subtraction and addition this class as member functions.
Overload the operator == to check two complex numbers are the same.
Use the friend function for the operators << and >>. For those functions, use the below function
definition.
ostreama operator<< (ostream& os, const complexType& complex)
os << "(" << complex.realPart << ","
<< complex.imaginaryPart << ")";
return os;
}
istream& operator>> (istream& is, complexType& complex)
{
char ch;
is >> ch:
I/read and discard (
Ilget the real part
I/read and discard,
Ilget the imaginary part
liread and discard)
is >> complex.realPart;
is >> ch:
is >> complex.imaginaryPart;
is >> ch;
return is;
}
For example, the calculation of addition and difference of the complex numbers are the following
If (a, b)and (c, d)are complex numbers, (a, b) – (c, d) = (a – c,b - d)
If (a, b)and (c, d)are complex numbers, (a, b) + (c, d) = (a + c,b + d)
1) Write the definitions of the class complexType.
2) Write a test program that implementing the operators in the class complexType.
a) Create a complex number with the real and imaginary part values as 5 and 6, respectively. Let's assume the
object as "numl' in the below output example
b) Create a default complex number.
c) Design a code to prompt a user for the real and imaginary values from the default object.
d) Use the operators +, - and display their results.
e) Use the operator == to check whether the complex numbers are the same and display the appropriate
statements like the sample output using operator overloading.
Transcribed Image Text:Define the class complexType so that it performs the subtraction and summation operations. Set the complex number according to the parameters such as realPart = real; imaginaryPart = imag Design a constructor no-argument to initialize the complex number Design a constructor to initialize the complex number according to the parameters • Overload the operators subtraction and addition this class as member functions. Overload the operator == to check two complex numbers are the same. Use the friend function for the operators << and >>. For those functions, use the below function definition. ostreama operator<< (ostream& os, const complexType& complex) os << "(" << complex.realPart << "," << complex.imaginaryPart << ")"; return os; } istream& operator>> (istream& is, complexType& complex) { char ch; is >> ch: I/read and discard ( Ilget the real part I/read and discard, Ilget the imaginary part liread and discard) is >> complex.realPart; is >> ch: is >> complex.imaginaryPart; is >> ch; return is; } For example, the calculation of addition and difference of the complex numbers are the following If (a, b)and (c, d)are complex numbers, (a, b) – (c, d) = (a – c,b - d) If (a, b)and (c, d)are complex numbers, (a, b) + (c, d) = (a + c,b + d) 1) Write the definitions of the class complexType. 2) Write a test program that implementing the operators in the class complexType. a) Create a complex number with the real and imaginary part values as 5 and 6, respectively. Let's assume the object as "numl' in the below output example b) Create a default complex number. c) Design a code to prompt a user for the real and imaginary values from the default object. d) Use the operators +, - and display their results. e) Use the operator == to check whether the complex numbers are the same and display the appropriate statements like the sample output using operator overloading.
class complexType
public:
void setComplex(double& real, double& imag);
//set the complex number according to the parameters
//Postcondition: realPart = real; imaginaryPart = imag
void print();
//print the complex number
complexType();
//Constructor initialize double real = 0, double imag = 0
complexType(double, double);
//Constructor
//initialize the complex number according to the parameters
/Postcondition: realPart = real; imaginaryPart = imag
complexType operator+( complexType& otherComplex);
//overload +
complexType operator-( complexType& otherComplex);
//overload -
bool operator==( complexType& otherComplex) const;
//overload ==
private:
double realPart; // variable to store the real part
double imaginaryPart; // variable to store the imaginary part
Transcribed Image Text:class complexType public: void setComplex(double& real, double& imag); //set the complex number according to the parameters //Postcondition: realPart = real; imaginaryPart = imag void print(); //print the complex number complexType(); //Constructor initialize double real = 0, double imag = 0 complexType(double, double); //Constructor //initialize the complex number according to the parameters /Postcondition: realPart = real; imaginaryPart = imag complexType operator+( complexType& otherComplex); //overload + complexType operator-( complexType& otherComplex); //overload - bool operator==( complexType& otherComplex) const; //overload == private: double realPart; // variable to store the real part double imaginaryPart; // variable to store the imaginary part
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education