Question: I need help to 1. Add an overloaded operator!=() and operator==() functions. 2. Add the overloaded stream extraction and stream insertion operators To this class.

I need help to

1. Add an overloaded operator!=() and operator==() functions. 2. Add the overloaded stream extraction and stream insertion operators To this class.

So I just need help adding these operator overloads to this class I started on

myArray.h

#pragma once #ifndef H_myArray #define H_myArray #include using namespace std; class myArray { public: myArray(int); myArray(int, int); ~myArray(); int& operator[](int); int operator[](int) const; int StartIndex; int size; int* PtrAry;

}; #endif H_myArray

myArray.cpp

#include "myArray.h" #include using namespace std;

myArray::myArray(int newSize)//Single parameter constructor { StartIndex = 0; size = newSize; //create pointer based array PtrAry = new int[size]; for (int i = 0; i < (size + StartIndex); i++) PtrAry[i] = 0; }

myArray::myArray(int newStartIndex, int newSize) //constructor two parameters { StartIndex = -newStartIndex; size = newSize; for (int i = 0; i < (size + StartIndex); i++) PtrAry[i] = 0;

}

myArray::~myArray() { delete[] PtrAry; }

int &myArray::operator[](int index)//implement overiding non constant array { if (index < -StartIndex || index >= size) { cerr << " Error:Index " << index << "is out of range" << endl; system("pause"); exit(1);//terminates }

return PtrAry[index + StartIndex]; }

int myArray::operator[](int index) const //const array overloader { if (index < -StartIndex || index >= size) { cerr << " Error:Index " << index << "is out of range" << endl; system("pause"); exit(1);//terminates } return PtrAry[index + StartIndex]; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!