I have been working on a lab project for my C++ class, and am struggling. I'm new to programming, and we just got into Object-Oriented Programming.
My question concerns adding two objects. According to the lab paper, the function
Complex Add(Complex& pRHSOp);
MUST:
{Add THIS Complex number and pRHSOp to form a new Complex number named sum and returns sum. Note: pRHSOp is passed-by-reference because it is generally faster to pass objects by reference.}
where THIS function is the secondary constructor
(Complex::Complex(pInitReal, pInitImag)
Here is the beginning of the class declaration:
#ifndef COMPLEX_HPP
#define COMPLEX_HPP
#include <fstream>
using namespace std;
class Complex {
public:
Complex();
Complex(double pInitReal, double pInitImag);
Complex Add(Complex& pRHSOp);
______________________________________…
And here is a fraction of my C++ source code, so far:
To add the two, you simply add the two imaginary parts and the real parts.
1 2 3 4 5
Complex Complex::Add(Complex& pRHSOp)
{
this->pInitReal+=pRHSOp.pInitReal // pInitReal is the real part
this->PInitImag+=pRHSOp.pInitImag // pInitImag is the imaginary part
}
Note that you don't actually need the this pointer.