Question
A complex number is of the form a+ib. Let x = a +ib and y =c + id. The operation of adding two complex numbers
A complex number is of the form a+ib. Let x = a +ib and y =c + id.
The operation of adding two complex numbers is: x +y = (a +c) + i(b+ d).
The operation of subtracting two complex number is: x-y = (a -c) - i(b-d).
The operation of multiplying two complex number is:x *y = (ac - bd) + i(bc +ad) .
The operation of dividing two complex number is: x/y = [(ac+bd)/ (c^2 + d^2)] + [i(bc-ad)/(c^2 + d^2)].
Write a class called Complex for adding, subtracting, multiplying, and dividing two complex numbers. These member functions shall accept one (NOT two) complex number and return the result via the return type. The class shall have a single complex number as its data member.
Include one or more constructors as appropriate. Also include the set, get, and display member functions.
Use a header file called Complex.h, an implementation file called Complex.cpp, and an application file called Application.cpp. Test the Complex class in the main function.
Use pass-by-reference to eliminate the overhead of copying the argument to the parameter. If a member function will not modify the data member, make the function constant so that data members will not be accidentally modified in the function body. If a parameter is pass-by-reference and the function will not modify the parameter, use constant data to ensure that the parameter will not be accidentally modified in the function body.
I have the header file and need help with the implementation and application
//HEADER FILE
#pragma once
#ifndef COMPLEX_H
#define COMPLEX_H
class ComplexH
{
private:
double real;
double imag;
public:
// initialize the complex number to 0.0
ComplexH() : real(0.0), imag(0.0) {}
// initialize the complex number at declaration or new
ComplexH(double r, double i) : real(r), imag(i) {}
ComplexH(const ComplexH &c) : real(c.real), imag(c.imag) {}
void setReal(double r) { real = r; }
void setImag(double i) { imag = i; }
void setComplex(const ComplexH &c) { real = c.real; imag = c.imag; }
double getReal() const { return real; }
double getImag() const { return imag; }
ComplexH getComplex() const { return *this; }
ComplexH add(const ComplexH &) const;
ComplexH sub(const ComplexH &) const;
ComplexH mul(const ComplexH &) const;
ComplexH div(const ComplexH &) const;
void print() const;
void print(const ComplexH &) const;
};
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started