How to write a constructor function to initialize the list to an empty list (array). The argument of the constructor will determine the maximum items which may be entered into the list.
and how to make it return true if the list is full
Printable View
How to write a constructor function to initialize the list to an empty list (array). The argument of the constructor will determine the maximum items which may be entered into the list.
and how to make it return true if the list is full
>How to write a constructor function to initialize the list to an empty list (array).
>how to make it return true if the list is fullCode:Constructor :: Constructor ( int n )
{
// Don't forget to check for errors
array = new char[n];
size = n;
}
Make a helper function that specifically checks if the array is full and returns true if it is:
And lastly, be sure to free the allocated space with your destructor.Code:bool Constructor :: isFull()
{
size_t len;
if ( ( len = strlen ( array ) ) == size )
return true;
cout<<"Total space: "<< size <<"\n"
<<"Available space: "<< size - len <<"\n";
return false;
}
-Prelude
that was so helpful thank you very much and God bless you.