Question: I will attach Managed Array and GuardedArray GuardedArray: #ifndef __GUARDED_ARRAY_H__ #define __GUARDED_ARRAY_H__ typedef int ItemType; const unsigned MAX_LENGTH = 500; // // GuardedArray // -

I will attach Managed Array and GuardedArray GuardedArray: #ifndef __GUARDED_ARRAY_H__ #define __GUARDED_ARRAY_H__I will attach Managed Array and GuardedArray

GuardedArray:

#ifndef __GUARDED_ARRAY_H__ #define __GUARDED_ARRAY_H__ typedef int ItemType; const unsigned MAX_LENGTH = 500; // // GuardedArray // - A wrapper class for C++ arrays to make array access safe. // Specifically, initialization is guaranteed, and assertions are // in place to detect array index out of bound errors in array member // accesses. // class GuardedArray { public: // // Constructor // // Purpose: Initializes array elements to zeros // Argument(s): N/A // Side Effect: All array elements are initialized to zero. // Return: N/A // GuardedArray(); // // Constructor // // Purpose: Initializes all array elements to a given value. // Argument(s): // x : value to which array elements should be initialized. // Side Effect: All array elements are initialized to x. // Return: N/A // GuardedArray(ItemType x); // // read // // Purpose: Read array element at index i. // Argument(s): // i : index of element to be read. // Precondition(s): i  

ManagedArray:

#ifndef __MANAGED_ARRAY_H__ #define __MANAGED_ARRAY_H__ #include "guarded_array.h" // // ManagedArray // - A wrapper class for C++ arrays to facilitate insertion and removal of // array elements. // - Every instance of ManagedArray has a size that can be increased // until the maximum capacity MAX_LENGTH is reached. // class ManagedArray { public: // // Constructor // // Purpose: Initializes array to have zero size. // Argument(s): N/A // Side Effect: The array is initialized to be empty. // Return: N/A // ManagedArray(); // // Constructor // // Purpose: Initializes array to a given size. All array elements // are initialized to zero. // Argument(s): // N : size of array // Precondition: N  0 // Side Effect: Remove the array element at index i. Array // elements will be shifted to fill the "gap" left // by the removed element. The array size will be // decreased by one. // Return: N/A. // void remove(unsigned i); private: unsigned count; GuardedArray array; }; #endif
CS 115 Assignment 6 Due: Tuesday December 4h, 7:00pm 1. [50%) Review the following lectures: Pointers Dynamic Memory Management Dynamic Memory Management and ADTs Dynamic Memory Management and OOP Recall that GuardedArray is limited by a maximum capacity. Rewrite the GuardedArray class using dynamic memory management, so that the array may assume any user-specified capacity. The new GuardedArray class should be a wrapper of (1) an int pointer and (2) an unsigned capacity field, and should be equipped with the following member functions A default constructor that initializes the pointer to null and the capacity to zero A constructor that constructs a GuardedArray of a given capacity. An appropriate amount of memory should be allocated dynamically. Members of the array should be initialized to 0 A constructor that constructs a GuardedArray of a given capacity, and initializes the members of the array to a given int value. An appropriate amount of memory should be allocated dynamically A copy constructor that initializes a GuardedArray by another instance of GuardedArray. Deep copy should be performed An assignment operator that assigns the value of a GuardedArray to another. Deep copy should be performed. Self assignment should be properly handled A destructor that deallocates the memory of a GuardedArray A member function to read from a member of the array. Assertions should be in place to trap out-of-bound array index errors. A member function to write to a member of the array. Assertions should be in place to trap out of-bound array index errors. A member function to return the capacity of a GuardedArray Test your code by having ManagedArray uses this new version of GuardedArray rather than the one provided to you. Slightly edit ManagedArray so that it creates a GuardedArray of an initial capacity 500 Rerun the tests of sort, reverse and nop to confirm that your code functions properly CS 115 Assignment 6 Due: Tuesday December 4h, 7:00pm 1. [50%) Review the following lectures: Pointers Dynamic Memory Management Dynamic Memory Management and ADTs Dynamic Memory Management and OOP Recall that GuardedArray is limited by a maximum capacity. Rewrite the GuardedArray class using dynamic memory management, so that the array may assume any user-specified capacity. The new GuardedArray class should be a wrapper of (1) an int pointer and (2) an unsigned capacity field, and should be equipped with the following member functions A default constructor that initializes the pointer to null and the capacity to zero A constructor that constructs a GuardedArray of a given capacity. An appropriate amount of memory should be allocated dynamically. Members of the array should be initialized to 0 A constructor that constructs a GuardedArray of a given capacity, and initializes the members of the array to a given int value. An appropriate amount of memory should be allocated dynamically A copy constructor that initializes a GuardedArray by another instance of GuardedArray. Deep copy should be performed An assignment operator that assigns the value of a GuardedArray to another. Deep copy should be performed. Self assignment should be properly handled A destructor that deallocates the memory of a GuardedArray A member function to read from a member of the array. Assertions should be in place to trap out-of-bound array index errors. A member function to write to a member of the array. Assertions should be in place to trap out of-bound array index errors. A member function to return the capacity of a GuardedArray Test your code by having ManagedArray uses this new version of GuardedArray rather than the one provided to you. Slightly edit ManagedArray so that it creates a GuardedArray of an initial capacity 500 Rerun the tests of sort, reverse and nop to confirm that your code functions properly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!