CS1410 13.4 Programming Project #8: Dynamic Array Template solved

$24.99

Original Work ?

Download Details:

  • Name: ProgrammingProject8_DynamicArrayTemplate.zip
  • Type: zip
  • Size: 2.45 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

4.7/5 - (7 votes)

Background At this point you should have written code for a complete vector of integers class (The Dynamic Array project). We will add a few additional functions to DynArray, and then make it a class template so it can store objects of any type. Objective Successfully implement a generic class using templates in C++. Step 1 Starting with a copy of your DynArray class, add the following member functions: 1. int back()  This function returns the value of the last integer in the used portion of the vector, but it does not remove it. Throw a runtime_error if the vector is empty. This function returns by reference. 2. int front() This function returns the value at the beginning the vector, but it does not remove it. Throw a runtime_error if the vector is empty. This function returns by reference. 3. DynArray(const DynArray&) This copy constructor does a deep copy of the object’s contents. 4. DynArray& operator=(const DynArray&) This assignment operator does a deep copy of the object’s contents. Don’t forget to delete the old data. 5. T& operator[ ](int n); This operator modifies the array operator so that is it compatible with a vector at( ) function in avoiding the fact that an array has no over bounds error reporting. After you have added these functions to your new DynArray class, write a driver that tests these new functions. Once you are satisfied that your DynArray class works, move on to step two. You won’t turn in your test code for this step.
Step 2 Make your DynArray class generic by making it a template. Your new class template will have the type of the items it will hold as the template parameter: template Note that you must insert trace statements for “grow” and “assign”. This verifies that your code is functioning properly.