Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Updated 2/21: Corrected the function header for the constructor to add and changed the default capacity to 100 Updated 2/22 to clarify that you can
Updated 2/21: Corrected the function header for the constructor to add and changed the default capacity to 100
Updated 2/22 to clarify that you can and certainly are expected to use arrays in your implementation. What is not permissible is to use the array class in the C++ STL: array - C++ Reference (cplusplus.com)
Updated 2/23: Add one line of code to resize() function in BoundedArrayConst.cpp -- it wasn't actually resizing the array previously.
PROBLEM 2 10 POINTS In some application settings, it is useful to have a fixed-capacity array that can store up to M elements. The actual size m of the array (also sometimes called the logical size) can be less than M, but it can be grown up to the capacity M, as shown in Figure 1 below. This type of data structure is sometimes referred to as a bounded array since the array size can grow but has a hard upper bound. 271/384 Logical size Capacity Figure 1. Illustration of a bounded array. The capacity denotes the number of contiguous storage locations allocated in memory. The actual or logical size of the array denotes the number of elements stored in the array and can increase up to the capacity. The header and source files BoundedArrayConst.h and BoundedArrayConst.cpp contain an implemen- tation of a bounded array data structure to store variables of type double where the capacity is specified by a constant. The member functions have been created to closely match those of the STL vector class. Your task is to modify the implementation of BoundedArrayConst so that the capacity is specified by a regular variable rather than a constant. Call the new class BoundedArray and make the following changes to BoundedArrayConst: Set the default value for the capacity to be 100 elements. Add a constructor with the following header to allow the user of the class to choose the capacity along with the number of elements: BoundedArray(int numelements, int maxNumElements); Modify all included member functions as necessary to ensure their correct operation. To do this, you will have to use dynamic memory allocation using pointers and the new and delete operators. Note: You may not use any external container classes in this problem, such as the vector or array classes in the STL! You can and certainly are expected to use arrays in your implementation, but not the array class in the C++ STL'. Submit your header file and source code in files named BoundedArray.h and BoundedArray.cpp, respectively! PROBLEM 2 10 POINTS In some application settings, it is useful to have a fixed-capacity array that can store up to M elements. The actual size m of the array (also sometimes called the logical size) can be less than M, but it can be grown up to the capacity M, as shown in Figure 1 below. This type of data structure is sometimes referred to as a bounded array since the array size can grow but has a hard upper bound. 271/384 Logical size Capacity Figure 1. Illustration of a bounded array. The capacity denotes the number of contiguous storage locations allocated in memory. The actual or logical size of the array denotes the number of elements stored in the array and can increase up to the capacity. The header and source files BoundedArrayConst.h and BoundedArrayConst.cpp contain an implemen- tation of a bounded array data structure to store variables of type double where the capacity is specified by a constant. The member functions have been created to closely match those of the STL vector class. Your task is to modify the implementation of BoundedArrayConst so that the capacity is specified by a regular variable rather than a constant. Call the new class BoundedArray and make the following changes to BoundedArrayConst: Set the default value for the capacity to be 100 elements. Add a constructor with the following header to allow the user of the class to choose the capacity along with the number of elements: BoundedArray(int numelements, int maxNumElements); Modify all included member functions as necessary to ensure their correct operation. To do this, you will have to use dynamic memory allocation using pointers and the new and delete operators. Note: You may not use any external container classes in this problem, such as the vector or array classes in the STL! You can and certainly are expected to use arrays in your implementation, but not the array class in the C++ STL'. Submit your header file and source code in files named BoundedArray.h and BoundedArray.cpp, respectivelyStep 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