Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Michael Reaves
- CSCI 3110
- hwkMultidimensionalArrays
- 2/12/16
- */
- //1a)Write the implementation for printNumberOfChildren(), given the following function prototype.
- bool Grandchildren::printNumberOfChildren(int numberOfParents, int* numberOfChildren)
- {
- for (int i=0; i<numberOfParents, i++)
- {
- std::cout << "Parent " << i << " has " << numberOfChildren[i] << " children\n";
- }
- return true;
- }
- //1b)Given the definition of the x_InitializeGrandchildrenNames2DArray() method below, write it's implementation.
- bool Grandchildren::x_InitializeGrandchildrenNames2DArray(int numberOfParents, int* numberOfChildren)
- {
- m_GrandchildrenNames2DArray = new string*[numberOfParents];
- if (!m_GrandchildrenNames2DArray)
- {
- return false;
- }
- for( int i=0; i<numberOfParents; i++)
- {
- m_GrandchildrenNames2DArray[i] = new string[numberOfChildren[i]];
- if(!m_GrandchildrenNames2DArray)
- {
- return false;
- }
- }
- }
- //1c)Write the implementation of the corresponding Grandchildren::x_FreeGrandchildrenNames2DArray( int numberOfParents) method that deallocates the memory assigned to m_GrandchildrenNames2DArray.
- Grandchildren::x_FreeGrandchildrenNames2DArray( int numberOfParents)
- {
- for(int i=0; i<numberOfParents; i++)
- {
- delete [] m_GrandchildrenNames2DArray[i];
- }
- delete [] m_GrandchildrenNames2DArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement