Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started