Question
I am including three classes that must be used for this project. I need two * NEW * files (class and header) for the derived
I am including three classes that must be used for this project. I need two *NEW* files (class and header) for the derived complex class. The three files to be used are below:
Application.cpp
#include
int main() { Complex a(4.0, 6.0), b(3.0, 5.0), *c = new Complex; Complex d(a); d.print(); a.add(b).print(); Complex res(7.0,9.0); cout
Complex.cpp
#include
Complex Complex::add(const Complex &c) const { Complex result; result.real = real + c.real; result.imag = imag + c.imag; return result; } Complex Complex::sub(const Complex &c) const { Complex result; result.real = real - c.real; result.imag = imag - c.imag; return result; } Complex Complex::mul(const Complex &c) const { Complex result; result.real = real * c.real - imag * c.imag; result.imag = imag * c.real + real * c.imag; return result; } Complex Complex::div(const Complex &c) const { double t = c.real * c.real + c.imag * c.imag; Complex result; result.real = (real * c.real + imag * c.imag) / t; result.imag = (imag * c.real - real * c.imag) / t; return result; }
void Complex::print() const { cout
Complex.h
#pragma once #ifndef COMPLEX_H #define COMPLEX_H class Complex { private: double real; double imag; public: Complex() : real(0.0), imag(0.0) {} Complex(double r, double i) : real(r), imag(i) {} Complex(const Complex &c) : real(c.real), imag(c.imag) {} // above statement must be pass-by-reference so that the default copy constructor is not used. // if it is pass-by-value, the above statement is not a copy constructor and function // overloading occurs the compiler cannot resolve
void setReal(double r) { real = r; } void setImag(double i) { imag = i; } void setComplex(Complex c) { real = c.real; imag = c.imag; } double getReal() { return real; } double getImag() { return imag; }
Complex add(const Complex &) const; Complex sub(const Complex &) const; Complex mul(const Complex &) const; Complex div(const Complex &) const;
void print() const; };
#endif
Please write in C++, thanks
1. Write a derived class for the Complex class to support (1) complex conjugate, (2) negative (negate both real and imaginary parts), and (3) swapping of real part and imaginary part. You must use the Complex class posted online (not your own class)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