Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help complete this code! The goal of this function is to write the interface and implementation for the complex number class. The public interface

Please help complete this code! The goal of this function is to write the interface and implementation for the complex number class. The public interface for the complex number class should provide the following member functions: constructors: There will be three versions of the constructor function:

a. Complex() : the default constructor sets both real and imag, private member variables, to 0. The default constructor is implemented for you.

b. Complex(double r) : the second constructor sets real to r, the double, and imag to 0.

c. Complex(double r, double i) : the third constructor sets real to r and imag to i.

operators: +, -, / and * will be overloaded as non-member friend functions. For the / operator, when both the real and imaginary parts of the divisor are 0, an exception occurs. The operator must throw an integer, -1. The << operator has already been implemented for you. Make sure you understand how it works. Also, the + non-member operator has been implemented for you.

accessors: implement two accessor member functions: a. getReal(): this function returns the real part of the complex number. This member function has been implemented for you.

b. getImag() : this function returns the imaginary part of the complex number.

Other member functions :

a. conjugate() : this member function returns a complex number that is the conjugate of the object used to invoke it. This function has been implemented for you.

b. modulus() : this member function returns the magnitude of the complex number. The square root function, sqrt, is defined in the math library.

c. argument() : this member function returns the polar angle of a complex number. Given a complex number z = x + iy, it returns arctan(y/x). Note the arctan function, atan2(y,x), is already de- fined in the math library. However, the function must throw an integer, -2, when an exception occurs. An exception occurs when both y and x are 0.

Define the function pow(const Complex& z, int n) as a friend function of the Complex class. The function returns a new complex number equivalent to Zn.

complex.h:

/** * public interface for the complex number class. * */

#ifndef COMPLEX_H #define COMPLEX_H

#include

using namespace std;

/* The TASK HERE IS TO GIVE THE COMPLETE DEFINITION OF THE class Complex AS DESCRIBED above. 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions