First of, this is an assignment and only dynamic allocated array could be used(can't use vector or map). The hint that I received was to create another array(with all elements assigned or not,I'm not sure) and compare with the original array.
So, an original array was dynamically allocated with the capacity of 50. I can't assign values or give default values to myArray.
int *myArray = new int[50];
Not all elements are present at every index. myArray may have 0,10, or 50 elements present.I don't know how many or where the elements are presents.by "not present" I meant that an element at a given index has not been initialized.
Let's assume 2 elements are present:
myArray [0] = 10;
myArray [1] = 20;
the goal is to write a bool isPresent(int index) function with 3 requirements:
if index is too big(bigger than 49 in this case),return false;
return true, if the element is present at isPresent(int index);
return false, if the element at given index is not present.
bool isPresent(int 0){}//this should return true
bool isPresent(int 1){}//this should return true
bool isPresent(int 3){}//this should return false
bool isPresent(int 49){}//this should return false
bool isPresent(int 50){}//this should return false
please help me finish the bool isPresent() function. For the second array that I can create to maybe help me, there's no requirement of how to do it. I can maybe do something like the following, but I'm not sure how that can help:
int *myArray2 = new int[50];
for (int i = 0; i < 50; i++)
{
myArray2[i] = 100;//so I'm assigning 100 to every element for myArray2
//to compare?
}
The bool isPresent() function is under a array class that I need to write. The given test codes(I can't change) are in main. From main, an object of my array class will be created and different elements will be assigned to isPresent() from main.