C++   How to Program (Early Objects Version)
C++ How to Program (Early Objects Version)
10th Edition
ISBN: 9780134448824
Author: Paul Deitel; Harvey M. Deitel
Publisher: Pearson Education (US)
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
Specifications: Part-1Part-1: DescriptionIn this part of the lab you will build a single operation ALU. This ALU will implement a bitwise left rotation. Forthis lab assignment you are not allowed to use Digital's Arithmetic components.IF YOU ARE FOUND USING THEM, YOU WILL RECEIVE A ZERO FOR LAB2!The ALU you will be implementing consists of two 4-bit inputs (named inA and inB) and one 4-bit output (named out). Your ALU must rotate the bits in inA by the amount given by inB (i.e. 0-15).Part-1: User InterfaceYou are provided an interface file lab2_part1.dig; start Part-1 from this file.NOTE: You are not permitted to edit the content inside the dotted lines rectangle.Part-1: ExampleIn the figure above, the input values that we have selected to test are inA = {inA_3, inA_2, inA_1, inA_0} = {0, 1, 0,0} and inB = {inB_3, inB_2, inB_1, inB_0} = {0, 0, 1, 0}. Therefore, we must rotate the bus 0100 bitwise left by00102, or 2 in base 10, to get {0, 0, 0, 1}. Please note that a rotation left is…
How can I perform Laplace Transformation when using integration based on this? Where we convert time-based domain to frequency domain
what would be the best way I can explain the bevhoirs of Laplace and Inverse Transofrmation In MATLAB.
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