
Concept explainers
(Complex Class) Consider class Complex shown in Figs. 10.14-10.16. The class enables operations on so-called complex numbers. These are numbers of the form real Part + imaginaryPart * i. where i has the value
- Modify the class to enable input and output of complex numbers via overloaded >> and << operators, respectively (you should remove the toString function from the class)
- Overload the multiplication operator to enable multiplication of two complex numbers as in algebra.
- Overload the == and t = operators to allow comparisons of complex numbers.
After doing this exercise, you might want to read about the Standard Library’s complex class (from) header <comp1ex>)
- // Fig. 10.14 : Complex.h
- // Complex class definition.
- #include <string>
- #ifndef COMPLEX_H
- #define COMPLEX_H
- Class Complex {
- Public :
- Explicit Complex (double = 0.0, double = 0.0) ; // constructor
- Complex operator+(const Complex&) const; // addition
- Complex operator-(const Complex&) const; // subtraction
- Std:: string toString () const:
- Private:
- Double real : // real part
- Double imaginary ; // imaginary part
- };
- #endif
Fig. 10.14 Complex class deginition.
- // Fig. 10.15 : Complex.cpp
- // Complex class member-function definitions.
- #include <string>
- #include “Complex.h” // Complex class definition
- Using namespace std;
- // Constructor
- Complex: : Complex (double realPart, double imaginaryPart)
- : reak {real Part}, imaginary {imaginaryPart} { }
- // addition operator
- Complex Complex : : operator+ (const Complex& operand2) const {
- Return Complex {real +operand2. Real, imaginary+ operand2. Imaginary};
- }
- // subtraction operator
- Complex Complex : : operator-(const Complex& opetand2) const {
- Return Complex { real − operand 2.real, imaginary − operand2. Imaginary } :
- }
- // return string representation of a complex object in the form: (a, b)
- String Complex : : to String () const {
- Return “(“s +to_string(real) + “, “s + to_string(imaginary) + “)”s;
- }
Fig.10.15 Complex class member-function definition
25 // Fig. 10.16; fig10_16.cpp
26 // Complex class test program.
27 #include <iostream>
28 #include “Complex.h”
29 using namespace std;
30
31 int main () {
32 Complex x:
33 Complex y {4.3, 8,2}:
34 Complex z {3,3, 1,1}:
35
36 count << “x: “ << x.toString () << :\ny: “<<y.to string ()
37 << “\nz: “ <<z:
38
39 x=y+z;
40 count << “\n\nx = y+z:\n” << x.toString () << “= “ << y.toString()
41 << “ + ” <<z.toString ():
42
43 x = y - z :
44 count << “\n\nx = y-z:\n” << x. to String () << “ = “ << y. to String ()
45 << “ - “ << z. toString () << end}:
X: (0, 0)
Y: (4,3, 8,2)
Z: (3,3, 1.1)
X = y+z:
(7.6, 9.3) = (4.3, 8.2) + (3.3, 1.1)
X= y-z :
(1, 7.1) = (4.3, 8.2 ) −(3.3, 1.1)
Fig. 10.16 Complex class test program (Part 2 of 2)

Want to see the full answer?
Check out a sample textbook solution
Chapter 10 Solutions
C++ How to Program (Early Objects Version)
- What IETF protocol is NetFlow associated with? Group of answer choices IPX/SPX IPIX HTTPS SSHarrow_forwardHow can I perform Laplace Transformation when using integration based on this?arrow_forwardWrite an example of a personal reflection of your course. - What you liked about the course. - What you didn’t like about the course. - Suggestions for improvement. Course: Information and Decision Sciences (IDS) The Reflection Paper should be 1 or 2 pages in length.arrow_forward
- using r languagearrow_forwardI need help in explaining how I can demonstrate how the Laplace & Inverse transformations behaves in MATLAB transformation (ex: LIke in graph or something else)arrow_forwardYou have made the Web solution with Node.js. please let me know what problems and benefits I would experience while making the Web solution here, as compared to any other Web solution you have developed in the past. what problems and benefits/things to keep in mind as someone just learningarrow_forward
- PHP is the server-side scripting language. MySQL is used with PHP to store all the data. EXPLAIN in details how to install and run the PHP/MySQL on your computer. List the issues and challenges I may encounter while making this set-up? why I asked: I currently have issues logging into http://localhost/phpmyadmin/ and I tried using the command prompt in administrator to reset the password but I got the error LOCALHOST PORT not found.arrow_forwardHTML defines content, CSS defines layout, and JavaScript adds logic to the website on the client side. EXPLAIN IN DETAIL USING an example.arrow_forwardusing r languangearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr

