Can you please help me with this ? its for C++ 1. Write a class ComplexNumber(de
ID: 3907349 • Letter: C
Question
Can you please help me with this ? its for C++
1. Write a class ComplexNumber(declaration and implementation) that has the following private data members: a) an int m real b) an int m_imaginary c) a static int s_count (used to track how many objects of type Complex Number exist). and the following public member functions: a) a Default ctor that leaves m_real and m_imaginary uninitialized. b) A Copy ctor that copies from one ComplexNumber object to the newly instantiated one. c) An assignment operator that assigns from one ComplexNumber object to the calling object d) An operator+ function that sums 2 complex numbers (resulting ComplexNumber is the sum of real parts and the sum of imaginary parts). e) A static method to get the s_count data that are private (should be named GetCount). and also uses an insertion operatorExplanation / Answer
Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
ComplexNumber.h
======
#ifndef ComplexNumber_h
#define ComplexNumber_h
#include <iostream>
using namespace std;
class ComplexNumber{
private:
int m_real;
int m_imaginary;
static int s_count;
public:
ComplexNumber();
ComplexNumber(const ComplexNumber& other);
ComplexNumber(int real, int imag);
ComplexNumber& operator = (const ComplexNumber& other);
ComplexNumber operator +(const ComplexNumber& other);
static int GetCount();
int GetReal();
int GetImaginary();
void SetReal(int real);
void SetImaginary(int imag);
friend ostream& operator <<(ostream& out, const ComplexNumber& c);
}
#endif /* ComplexNumber_h */
ComplexNumber.cpp
-------
#include "ComplexNumber.h"
int ComplexNumber::s_count = 0;
ComplexNumber::ComplexNumber(){
m_real = 0;
m_imaginary = 0;
s_count++;
}
ComplexNumber::ComplexNumber(const ComplexNumber& other){
m_real = other.m_real;
m_imaginary = other.m_imaginary;
s_count++;
}
ComplexNumber::ComplexNumber(int real, int imag){
m_real = real;
m_imaginary = imag;
s_count++;
}
ComplexNumber& ComplexNumber::operator = (const ComplexNumber& other){
m_real = other.m_real;
m_imaginary = other.m_imaginary;
return *this;
}
ComplexNumber ComplexNumber::operator +(const ComplexNumber& other){
return ComplexNumber(m_real+ other.m_real, m_imaginary + other.m_imaginary);
}
int ComplexNumber::GetCount(){
return s_count;
}
int ComplexNumber::GetReal(){
return m_real;
}
int ComplexNumber::GetImaginary(){
return m_imaginary;
}
void ComplexNumber::SetReal(int real){
m_real = real;
}
void ComplexNumber::SetImaginary(int imag){
m_imaginary = imag;
}
ostream& operator <<(ostream& out, const ComplexNumber& c){
out << c.m_real << " + i" << c.m_imaginary ;
return out;
}