
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 Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)
- Describe three (3) Multiplexing techniques common for fiber optic linksarrow_forwardCould you help me to know features of the following concepts: - commercial CA - memory integrity - WMI filterarrow_forwardBriefly describe the issues involved in using ATM technology in Local Area Networksarrow_forward
- For this question you will perform two levels of quicksort on an array containing these numbers: 59 41 61 73 43 57 50 13 96 88 42 77 27 95 32 89 In the first blank, enter the array contents after the top level partition. In the second blank, enter the array contents after one more partition of the left-hand subarray resulting from the first partition. In the third blank, enter the array contents after one more partition of the right-hand subarray resulting from the first partition. Print the numbers with a single space between them. Use the algorithm we covered in class, in which the first element of the subarray is the partition value. Question 1 options: Blank # 1 Blank # 2 Blank # 3arrow_forward1. Transform the E-R diagram into a set of relations. Country_of Agent ID Agent H Holds Is_Reponsible_for Consignment Number $ Value May Contain Consignment Transports Container Destination Ф R Goes Off Container Number Size Vessel Voyage Registry Vessel ID Voyage_ID Tonnagearrow_forwardI want to solve 13.2 using matlab please helparrow_forward
- a) Show a possible trace of the OSPF algorithm for computing the routing table in Router 2 forthis network.b) Show the messages used by RIP to compute routing tables.arrow_forwardusing r language to answer question 4 Question 4: Obtain a 95% standard normal bootstrap confidence interval, a 95% basic bootstrap confidence interval, and a percentile confidence interval for the ρb12 in Question 3.arrow_forwardusing r language to answer question 4. Question 4: Obtain a 95% standard normal bootstrap confidence interval, a 95% basic bootstrap confidence interval, and a percentile confidence interval for the ρb12 in Question 3.arrow_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

