Question: THIS IS A C++ ASSIGNMENT!! Programming assignment 11: Better Arrays Assigned: 11/19 Checkin: 11/28 - Start a new project, and implement 4 properties of your

THIS IS A C++ ASSIGNMENT!!

Programming assignment 11: Better Arrays

Assigned: 11/19 Checkin: 11/28 - Start a new project, and implement 4 properties of your array class, not counting constructors. Make sure you can demonstrate each of them in main() Due 12/3, by email before the start of class

Libraries you may use:

iostream

typeinfo

string

The use of any other libraries will result in the loss of points.

Purpose: The purpose of this assignment is to put into use all of the skills that we've been developing this semester. In class we worked on creating our own array class, with a lot of helper functions to improve the experience. In this assignment you will be creating your own improved array class.

Task: You will need to create a custom array class with the following properties:

Your class should be a template so the user can use your array for any arbitrary type

You should have a default constructor that initializes a dynamic array to 100 elements

You should have a parameterized constructor that takes the number of elements in the array as a parameter and initializes the dynamic array to that size

You will need a destructor to clean up your arrays

You should have a set method that takes a value (type T) and an array index and stores the value at the correct location in the array

You should have a get method that takes an array index and returns the element at that location

Your get and set methods should allow for negative array indices. A negative index should iterate backwards over the array (-1 is the last location, -2 is the second to last, etc)

Yourget and set methods should perform error checking. If the array index you povide is too large (or too small), they should not act upon the array. Instead, report an error message to the stderr stream (cerr), and throw an exception (in the case of the get).

You should also make sure to overload the bracket operators, so the user experience is consistent with normal arrays. The bracket operators should accept negative indices just as the get and set methods do. If the provided index is too big (or too small), make sure to report an error message to the stderr stream and throw an exception.

You should make sure to implement a deep copy function

A sample header to get you started:

 template  class array { private: Type *elements; int size; public: array(); array(int num_elements); ~array(); void set(int index, Type value); Type get(int index); Type &operator[](int index); array &operator=(const array& toCopy); }; 

Again, I'm leaving testing up to you, but I expect that you will be testing your array thoroughly in your main.cpp. Use for loops to test positive and negative indices, and show that all base functionality and error checking is working. Be sure to document all methods thoroughly.

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!