C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)
bartleby

Concept explainers

bartleby

Videos

Textbook Question
100%
Book Icon
Chapter 10, Problem 10.8E

(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

  Chapter 10, Problem 10.8E, (Complex Class) Consider class Complex shown in Figs. 10.14-10.16. The class enables operations on

  1. Modify the class to enable input and output of complex numbers via overloaded >> and
  2. << operators, respectively (you should remove the toString function from the class)
  3. Overload the multiplication operator to enable multiplication of two complex numbers as in algebra.
  4. 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>)

  1. // Fig. 10.14 : Complex.h
  2. // Complex class definition.
  3. #include <string>
  4. #ifndef COMPLEX_H
  5. #define COMPLEX_H
  6. Class Complex {
  7. Public :
  8. Explicit Complex (double = 0.0, double = 0.0) ; // constructor
  9. Complex operator+(const Complex&) const; // addition
  10. Complex operator-(const Complex&) const; // subtraction
  11. Std:: string toString () const:
  12. Private:
  13. Double real : // real part
  14. Double imaginary ; // imaginary part
  15. };
  16. #endif

Fig. 10.14 Complex class deginition.

  1. // Fig. 10.15 : Complex.cpp
  2. // Complex class member-function definitions.
  3. #include <string>
  4. #include “Complex.h” // Complex class definition
  5. Using namespace std;
  6. // Constructor
  7. Complex: : Complex (double realPart, double imaginaryPart)
  8. : reak {real Part}, imaginary {imaginaryPart} { }
  9. // addition operator
  10. Complex Complex : : operator+ (const Complex& operand2) const {
  11. Return Complex {real +operand2. Real, imaginary+ operand2. Imaginary};
  12. }
  13. // subtraction operator
  14. Complex Complex : : operator-(const Complex& opetand2) const {
  15. Return Complex { real − operand 2.real, imaginary − operand2. Imaginary } :
  16. }
  17. // return string representation of a complex object in the form: (a, b)
  18. String Complex : : to String () const {
  19. Return “(“s +to_string(real) + “, “s + to_string(imaginary) + “)”s;
  20. }

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)

Blurred answer
Students have asked these similar questions
Information Security Risk and Vulnerability Assessment 1- Which TCP/IP protocol is used to convert the IP address to the Mac address? Explain 2-What popular switch feature allows you to create communication boundaries between systems connected to the switch3- what types of vulnerability directly related to the programmer of the software?4- Who ensures the entity implements appropriate security controls to protect an asset?         Please do not use AI and add refrence
Find the voltage V0 across the 4K resistor using the mesh method or nodal analysis. Note: I have already simulated it and the value it should give is -1.714V
Resolver por superposicion
Knowledge Booster
Background pattern image
Computer Science
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
functions in c programming | categories of function |; Author: Education 4U;https://www.youtube.com/watch?v=puIK6kHcuqA;License: Standard YouTube License, CC-BY