Please help! The goal of this project is to write the interface and implementation for the complex number class. THE INSTRUCTIONS ARE BELOW (IN BOLD): Please complete the below STARTER functions (some variables need to be defined) ALL BOLDED SECTIONS CORRESPOND WITH ONE ANOTHER: complex.h: /**  * public interface for the complex number class.  *  */ #ifndef COMPLEX_H #define COMPLEX_H #include using namespace std; /* YOUR TASK HERE IS TO GIVE THE COMPLETE DEFINITION OF    THE class Complex. BE SURE TO INCLUDE A DESCRIPTION OF EACH OF THE FUNCTIONS.    YOU WILL PROVIDE ONLY THE PUBLIC INTERFACE OF THE MEMBER    AND FRIEND FUNCTIONS, NOT THEIR DEFINITIONS.     THE MEMBER AND FRIEND FUNCTIONS WILL BE DEFINED IN THE     IMPLEMENTATION FILE.    DEFINE THE CLASS BELOW.    */ #endif complex.cpp: /**  * Implementation for the complex class   *  */ #include #include #include "complex.h" /* SOME FUNCTION HAVE BEEN IMPLEMENTED. IMPLEMENT    ALL OTHER FUNCTIONS.  */ Complex::Complex() {    real = 0.0;    imag = 0.0; } double Complex::getReal() const {    return real; } Complex Complex::conjugate() const {    return Complex(real,-imag); } Complex operator +(const Complex& z1, const Complex& z2) {    return Complex(z1.real+z2.real,z1.imag+z2.imag); } ostream& operator<<(ostream& out, const Complex& z) {    if (z.real == 0 && z.imag == 0)    {       out<<"0";       return out;    }    if (z.real == 0)    {       if (z.imag < 0)       {          if (z.imag != -1)             out< #include "complex.h" #include using namespace std; int main(int argc, char **argv) {    Complex z0(3.6,4.8);    Complex z1(4,-2);    Complex z2(-4,2);    Complex z3(-4,-3);    Complex z4(3,-4);    Complex z5;    Complex z6;    Complex z7;    double ang;    cout<<"z0 = "<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Please help! The goal of this project is to write the interface and implementation for the complex number class. THE INSTRUCTIONS ARE BELOW (IN BOLD):

Please complete the below STARTER functions (some variables need to be defined) ALL BOLDED SECTIONS CORRESPOND WITH ONE ANOTHER:

complex.h:

/**
 * public interface for the complex number class.
 * </pre>
 */

#ifndef COMPLEX_H
#define COMPLEX_H

#include <iostream>

using namespace std;

/* YOUR TASK HERE IS TO GIVE THE COMPLETE DEFINITION OF
   THE class Complex. BE SURE TO INCLUDE A DESCRIPTION OF EACH OF THE FUNCTIONS.
   YOU WILL PROVIDE ONLY THE PUBLIC INTERFACE OF THE MEMBER
   AND FRIEND FUNCTIONS, NOT THEIR DEFINITIONS. 
   THE MEMBER AND FRIEND FUNCTIONS WILL BE DEFINED IN THE 
   IMPLEMENTATION FILE.
   DEFINE THE CLASS BELOW.   
*/
#endif

complex.cpp:

/**
 * Implementation for the complex class 
 * </pre>
 */

#include <cmath>
#include <cstdlib>
#include "complex.h"
/* SOME FUNCTION HAVE BEEN IMPLEMENTED. IMPLEMENT
   ALL OTHER FUNCTIONS. 
*/

Complex::Complex()
{
   real = 0.0;
   imag = 0.0;
}

double Complex::getReal() const
{
   return real;
}

Complex Complex::conjugate() const
{
   return Complex(real,-imag);
}
Complex operator +(const Complex& z1, const Complex& z2)
{
   return Complex(z1.real+z2.real,z1.imag+z2.imag);
}
ostream& operator<<(ostream& out, const Complex& z)
{
   if (z.real == 0 && z.imag == 0)
   {
      out<<"0";
      return out;
   }
   if (z.real == 0)
   {
      if (z.imag < 0)
      {
         if (z.imag != -1)
            out<<z.imag<<"i";
         else
            out<<"-i";
      }
      else
      {
         if (z.imag != 1)
            out<<z.imag<<"i";
         else
            out<<"i";
      }
      return out;
   }
   if (z.imag == 0)
   {
      out<<z.real;
      return out;
   }
   out <<z.real;
   if (z.imag < 0)
   {
      if (z.imag != -1)
         out<<z.imag<<"i";
      else
         out<<"-i";
   }   
   else
   {
      if (z.imag != 1)
         out<<"+"<<z.imag<<"i";
      else
         out<<"+i";  
   }
   return out;
}

completest.cpp

/**
 * A program to test the complex class implementation
 */

#include <iostream>
#include "complex.h"
#include <cstdlib>
using namespace std;

int main(int argc, char **argv)
{
   Complex z0(3.6,4.8);
   Complex z1(4,-2);
   Complex z2(-4,2);
   Complex z3(-4,-3);
   Complex z4(3,-4);
   Complex z5;
   Complex z6;
   Complex z7;
   double ang;
   cout<<"z0 = "<<z0<<" and re(z0) = "<<z0.getReal()<<" and "
       <<"im(z0) = "<<z0.getImag()<<"."<<endl;
   cout<<"z1 = "<<z1<<endl;
   cout<<"z2 = "<<z2<<endl;
   cout<<"z3 = "<<z3<<endl;
   cout<<"z4 = "<<z4<<endl;

   cout<<"z2 x z3 = "<<z2*z3<<endl;
   cout<<"z1 + z2 = "<<z1+z2<<endl;

   cout<<"z3 = "<<z3<<endl;
   cout<<"z4 = "<<z4<<endl;
   cout<<"z3-z4 = "<<z3-z4<<endl;

   cout<<"((z2+z3)x(z3-z4)) = ";
   cout<<(z2+z3)*(z3-z4)<<endl;
   cout<<"z1^3 = "<<pow(z1,3)<<endl;
   cout<<"1/z2^2 = "<<pow(z2,-2)<<endl;
   cout<<"z3^0 = "<<pow(z3,0)<<endl;
   try
   {   
      cout<<"((z2+z3)x(z3-z4))/z3 = ";
      z6 = ((z2+z3)*(z3-z4))/z3;
      cout<<z6<<endl;
      cout<<"z3 / z4 = "<<(z3/z4)<<endl;

      cout<<"Conj(z4) = "<<z4.conjugate()<<endl;
      cout<<"The real part of the conjugate of z4 is "<<(z4.conjugate()).getReal()<<endl;
      cout<<"The imaginary part of the conjugate of z4 is "<<(z4.conjugate()).getImag()<<endl;
      cout<<"The argument of the conjugate of z4 is "<<(z4.conjugate()).argument()<<"."<<endl;
      cout<<"The modulus of the conjugate of z4 is "<<(z4.conjugate()).modulus()<<"."<<endl;
      cout<<"(z3*conj(z4))/(z4*conj(z4))= ";
      cout<<(z3*z4.conjugate())/(z4*z4.conjugate())<<endl;
      /* Add statement here to compute ((z1-z2).(z3/z4))/(z4/z3)
         and print the result:*/
      
      ang = (z1+z2).argument();
      cout<<"angle = "<<ang<<endl;
      /* Put a comment here explaining what happened and why?
      */
   }
   catch(int e)
   {
      if (e == -1)
         cerr<<"DivideByZero Exception in / operator"<<endl;
      else if (e == -2)
         cerr<<"DivideByZero Exception in argument function"<<endl;
   }
   return 0;
}

Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Types of Loop
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education