Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
      1. add member function
        • Signature: Complex add(const Complex &addComplex) const
        • Returns a new Complex object that is this object added by the specified object.
        • Formula: (a + bi) + (c + di) = (a + c) + (b + d)i
          • New Real: (a + c)
          • New Imaginary: (b + d)
      2. subtract member function
        • Signature: Complex subtract(const Complex &subtractComplex) const
        • Returns a new Complex object that is this object subtracted by the specified object.
        • Formula: (a + bi) - (c + di) = (a - c) + (b - d)i
          • New Real: (a - c)
          • New Imaginary: (b - d)
      3. multiply member function
        • Signature: Complex multiply(const Complex &multiplyComplex) const
        • Returns a new Complex object that is this object multiplied by the specified object.
        • Formula: (a + bi) * (c + di) = (a*c - b*d) + (b*c + a*d)i
          • New Real: (a*c - b*d)
          • New Imaginary: (b*c + a*d)
      4. divide member function
        • Signature: Complex divide(const Complex &divideComplex) const
        • Returns a new Complex object that is this object divided by the specified object.
        • Formula: (a + bi) / (c + di) = ((a*c + b*d)/(c*c + d*d)) + ((b*c - a*d)/(c*c + d*d))i
          • New Real: ((a*c + b*d) / (c*c + d*d))
          • New Imaginary: ((b*c - a*d) / (c*c + d*d))
      5. Be sure to have a program description at the top and in-line comments.
        • Be clear with your comments and output to the user, so I can understand what the program is doing.

 

 

Code to edit

C++ CODE

#include<iostream>
using namespace std;
class Complex
{
    double real,imaginary;
    public:
        Complex()
        {
            real=0;
            imaginary=0;
        }
        void set(double r,double i)
        {
            real=r;
            imaginary=i;
        }
        void print()
        {
            cout<<"("<<real<<"+("<<imaginary<<"i))";
        }
        double getReal()
        {
            return real;
        }
         double getImaginary()
        {
            return imaginary;
        }
        ~Complex()
        {
            cout<<"Destrcutor\n";
        }
};
int main()
{
    Complex c1;
    Complex c2;
    Complex c3;
    c2.set(3.3,-4.4);
    c3.set(5.5,6.6);
    cout<<"Test the constructor."<<endl;
    cout<<"Complex number complex1 is: ";
    c1.print();
    cout<<"\n";
    cout<<"Test the one set() function."<<endl;
    cout<<"Complex number complex2 is: ";
    c2.print();
    cout<<"\n";
    cout<<"Complex number complex3 is: ";
    c3.print();
    cout<<endl;
    cout<<"Test the two get() functions."<<endl;
    cout<<"Complex number complex3's real part is: "<<c3.getReal()<<endl;
    cout<<"Complex number complex3's imaginary part is: "<<c3.getImaginary()<<endl;
    return 0;
}

 

 

Example Output
% make
% ./program
Test the constructor.
Complex number complex1 is: (0 + 0i)
Test the one set() function.
Complex number complex2 is: (3.3 - 4.4i)
Test the two get() functions.
Complex number complex3's real part is: 5.5
Complex number complex3's imaginary part is: 6.6
expand button
Transcribed Image Text:Example Output % make % ./program Test the constructor. Complex number complex1 is: (0 + 0i) Test the one set() function. Complex number complex2 is: (3.3 - 4.4i) Test the two get() functions. Complex number complex3's real part is: 5.5 Complex number complex3's imaginary part is: 6.6
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY