Question: C + + why is my output only 1 , 3 , 4 when i just want to remove 5 5 . code: template class
C why is my output only when i just want to remove
code:
template
class Collection
Objects array; pointer dynamically allocate array
int currentSize;
int capacity;
public:
Constructor
Collectionint capacity : capacitycapacity
array new Objectscapacity;
deconstructor to avoid memory leakage
~Collection
delete array;
checks if collection is empty
bool isEmptyconst
return currentSize ;
int makeEmpty
return currentSize ;
add more elements to the array if enough capacity.
void insertconst Objects& n
ifcurrentSize capacity
arraycurrentSize n;
else
std::cout "Collection is full to enter another element" std::endl;
remove element from array.... but it doesn't work yet
void removeconst Objects& index
forint i ; i currentSize; i
ifarrayi index
forint j i; j currentSize ; j
arrayj arrayj ;
currentSize;
this functin will search the arrray if it contains specify number
void contains
prints the entire array
void print
std::cout "Collection contents: std::endl;
forint i ; i currentSize; i
std::cout arrayi std::endl;
;
int main
Collection Collection;
Collection.insert;
Collection.insert;
Collection.insert;
Collection.insert;
Collection.insert;
Collection.insert;
int removeNum ;
Collection.removeremoveNum;
Collection.print;
return ;
Thank you in advance!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
