Homework: Multidimensional Arrays

  < Previous  Next >

Write your answers to the following questions in a file named hwkMultidimensionalArrays.cpp:
    1. Write the implementation for printNumberOfChildren(), given the following function prototype.
        bool Grandchildren::printNumberOfChildren(int numberOfParents, int* numberOfChildren);
      
      printNumberOfChildren() should print out how many children each parent has. For example, if numberOfParents is 3 and the numberOfChildren array has 3, 5, 17 as its contents, then printNumberOfChildren() would display:
      Parent 0 has 3 children
      Parent 1 has 5 children
      Parent 2 has 17 children
      
    2. Given the definition of the x_InitializeGrandchildrenNames2DArray() method below, write it's implementation. This method should allocate a two-dimensional array based on it's parameters numberOfParents and numberOfChildren and store the starting address in the private data member m_GrandchildrenNames2DArray. Each element should be of type string. Use numberOfParents as the number of rows with each row having the appropriate number of columns (as specified by the respective index of numberOfChildren). For example, if numberOfParents is 3 and the numberOfChildren array has 3, 5, 17 as its contents, then x_InitializeGrandchildrenNames2DArray() would make an array with 3 elements in the first row, 5 in the second and 17 in the third. The method returns false only if a memory allocation fails. You can assume that m_GrandchildrenNames2DArray does not point to allocated memory before the call to x_InitializeGrandchildrenNames2DArray().
        bool Grandchildren::x_InitializeGrandchildrenNames2DArray(int numberOfParents, int* numberOfChildren);
      
    3. Write the implementation of the corresponding Grandchildren::x_FreeGrandchildrenNames2DArray( int numberOfParents) method that deallocates the memory assigned to m_GrandchildrenNames2DArray.

Submission

Submit your cpp file at https://3110.cs.mtsu.edu/. For further instructions, please see the Miscellaneous page.

Rubric:

Points          Item
----------      --------------------------------------------------------------
_____ /  5      1
        
_____ /  5      Total
      

Last Modified: