Starting from:

$30

CS251-Project 1 Myvector Class Solved

In this project you’re going to re-implement vector as your own myvector class, using an implementation of your own design. The assignment consists of 4 parts, which walks you through the process of starting with a simple myvector of integers, and ending with a templated-version of myvector based on your own implementation. Approach the assignment part by part. Part 01: See zybooks section 1.9. Complete exercise. Part 02: See zybooks section 1.10. Complete exercise. Part 03: See zybooks section 1.11. Complete exercise. Part 04: At this point, you should have a working myvector class that is (a) templated, and (b) implemented in some approach other than the dynamically-allocated array we have discussed in class. Make sure you have 3 constructors: default, copy constructor, and one that takes an initial_size. As discussed in part 03, the goal is for you to develop an approach that improves upon the array-based implementation in some way. For example, perhaps you want to take an approach that avoids the cost of re-allocating the array when it's full, e.g. using a linked-list. Of course, with a linked-list the cost of accessing an element will jump from O(1) to  O(N), so that’s a costly trade-off. Perhaps you can think of a better approach that avoids the cost of reallocating the array, while retaining O(1) access to any element in most cases? Take some time to think about your implementation (and the trade-offs), draw some diagrams, and then implement. Here in part #04, the expectation is that you’ll work outside of zybooks so that you can do more extensive testing, since the “Movie Reviews” program is not an extensive test of myvector functionality. How you do this testing we’re going to leave to you, but testing is a skill that takes practice to develop. In short, think of ways to break your myvector class, and write code to make sure your vector class works as required. Can you insert thousands Here in part #04 you are also required to add three additional functions to your myvector class, as defined below: // // erase // // erase the element at position i from the vector by overwriting it and // reducing the size (# of elements); the ith element is returned // // Assume: 0 <= i < Size // T erase(int i); // // [] // // returns a reference to the element at position i so the element can // be read or written // // Assume: 0 <= i < Size // T& operator[](int i); // // rangeof // // Returns the elements in the range of positions i..j, inclusive. // The elements are returned in a dynamically-allocated C-style array. // // Example: if i is 2 and j is 4, then an array containing 3 // elements is returned: element position 2, element position 3, and // element position 4. // // Assume: 0 <= i <= j < Size // T* rangeof(int i, int j) In general, assume all parameters to the myvector class are valid --- we’ll worry about proper error checking later. Do not add a destructor, we’ll discuss destructors and proper memory deallocation in future projects. However, you should free memory within your other functions, e.g. in class we discussed the freeing of the old array in push_back.  Requirements Your approach needs to use pointers in some way, above and beyond a single pointer to a dynamicallyallocated array. A simple one or two-way linked-list is a valid approach, but will not receive full credit --- you can do better than that. Do not use any of the built-in containers of C++ (e.g. do not use std::vector to implement myvector). We aren’t looking for the best possible data structure, those are coming later. Just something better than a linked-list, if posible. You will be expected to update the comments in "myvector.h", including the header comment to explain your implementation approach. Ultimately we will be grading both the correctness and the quality of your implementation in "myvector.h". Be sure the header comment includes your name, and motivates your approach --- what trade-offs are you making in comparison to the dynamic, array-based approach? Keep all implementation details private. You'll probably need to define a private struct or class, e.g. to define a **NODE** in a linked-list. The proper way to do this is within the *private* section of your **myvector** class, like this: template class myvector { private: struct NODE { … }; // rest of myvector class, which can now use struct NODE };

More products