Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. /*
  2. Michael Reaves
  3. CSCI 3110
  4. hwkMultidimensionalArrays
  5. 2/12/16
  6. */
  7.  
  8. //1a)Write the implementation for printNumberOfChildren(), given the following function prototype.
  9. bool Grandchildren::printNumberOfChildren(int numberOfParents, int* numberOfChildren)
  10. {
  11. for (int i=0; i<numberOfParents, i++)
  12. {
  13. std::cout << "Parent " << i << " has " << numberOfChildren[i] << " children\n";
  14. }
  15. return true;
  16. }
  17.  
  18. //1b)Given the definition of the x_InitializeGrandchildrenNames2DArray() method below, write it's implementation.
  19. bool Grandchildren::x_InitializeGrandchildrenNames2DArray(int numberOfParents, int* numberOfChildren)
  20. {
  21. m_GrandchildrenNames2DArray = new string*[numberOfParents];
  22. if (!m_GrandchildrenNames2DArray)
  23. {
  24. return false;
  25. }
  26. for( int i=0; i<numberOfParents; i++)
  27. {
  28. m_GrandchildrenNames2DArray[i] = new string[numberOfChildren[i]];
  29. if(!m_GrandchildrenNames2DArray)
  30. {
  31. return false;
  32. }
  33. }
  34. }
  35.  
  36. //1c)Write the implementation of the corresponding Grandchildren::x_FreeGrandchildrenNames2DArray( int numberOfParents) method that deallocates the memory assigned to m_GrandchildrenNames2DArray.
  37. Grandchildren::x_FreeGrandchildrenNames2DArray( int numberOfParents)
  38. {
  39. for(int i=0; i<numberOfParents; i++)
  40. {
  41. delete [] m_GrandchildrenNames2DArray[i];
  42. }
  43. delete [] m_GrandchildrenNames2DArray;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement