Write a program (called integer_vector.cpp) that does the following:

1.Implement a class called BasicVector that:

  • Contains private member fields for:
    • data : integer pointer that is used to point to a dynamically allocated 1D integer array
    • vector_size : the current number of items in data
    • vector_capacity : the maximum number of items that can be contained in data before it needs to be resized
  • Contains the private member function:
    • resize : No return type (void), no parameters. Dynamically creates a new 1D array with twice the capacity of the existing array. Copy all of the existing elements over into the new array, update vector_capacity, use a temporary variable store the current address of data and delete [] to free the old array. Point data to the new array.
  • Contains public member functions:
    • at : returns an int reference to the array element specified. Has conditional logic that prevents using an index larger than the vector_size of the BasicVector object by calling exit 1 to terminate the program. Accepts a single parameter, int index.
    • operator[] : returns an int reference to the array element specified. Has conditional logic that prevents using an index larger than the vector_size of the BasicVector object by calling exit 1 to terminate the program. Accepts a single parameter, int index. Do not use the friend keyword, implement as a class member function
    • front : returns an int reference to the first array element. Calling front on an empty array is undefined behavior, so you do not need to account for it. Just assume it shouldn't be done.
    • back : returns an int reference to the last array element. Calling back on an empty array is undefined behavior, so you do not need to account for it. Just assume it shouldn't be done.
    • push_back : accepts an int and puts it in the first open index at the back of the array. No return type (returns void) If the vector_size of the array matches the vector_capacity before the new element is inserted, you will need to call the resize function, and then insert the new value. vector_size needs to be incremented after the element is inserted.
    • insert : accepts two int, an index to insert at, and the value to be inserted. In order for a value to be inserted, all of the elements from the given index to the end of the array need to be shifted once to the right to make room for the inserted value. Be sure to check if this will cause the vector_size to overtake vector_capacity, and call resize before any elements are shifted. No return type (void). Do not allow insertion past the last element in the vector. Increment vector_size after successful element insertion.
    • pop_back : no parameters, no return type. Removes the current last element from the array by setting element to 0 and decrementing vector_size. Should do nothing if array is empty.
    • size : returns vector_size field
    • capacity : returns vector_capacity field
    • print : no return type, no parameters. Outputs the vector_size and contents of data on a single line, use the following format:
      elements(5): 2 -3 16 7 0
  • Contains a non-default constructor (you do not need a default constructor):
    • Accepts one parameter for capacity. If the capacity is less than 16, use 16 as the capacity of data. Otherwise, set vector_capacity to the next largest power of 2, and create data with that new capacity.
  • Contains a destructor:
    • That sets all the filled elements in data to 0, and discards with array properly with delete []

2.Ensure that the member functions of BasicVector adhere to certain limits on asymptotic complexity as specified below, with the assumption that our n (input) is the size of the array stored in our vector class:

  • resize, and any functions that potentially invoke resize have a complexity of O(n)
  • All other member functions have a complexity of O(1)

3.Create an interactive "command" driven prompt system that parses commands from the user that are used to invoke the appropriate functions:

  • Initially prompt the user for the starting capacity of the vector and create a vector object by invoking the non-default constructor of BasicVector
  • Enter a looping prompt that parses the following commands with the appropriate parameters, and uses the vector created in the previous step to invoke the appropriate member functions:
    • at < index> -Invoke the at function, passing the index as its parameter, print result
    • get < index> -Invoke the operator[] function, passing index as its parameter, print result
    • front -Invoke the front function, print the result
    • back -Invoke the back function, print the result
    • insert < index> < value> -Invoke the insert function, passing index and value as its two parameters
    • push < value> -Invoke the push_back function, passing value its parameter
    • pop -Invoke the size function, print the returned value
    • size -Invoke the size function, print the returned value
    • capacity -Invoke the capacity function, print the returned value
    • print -Invoke the print command
    • quit -Break out of loop, exit program normally.

Expected prompt/input with example inputs:

Enter starting capacity of double vector: 10 Now accepting commands (quit to exit program):
> push 10.4
> size 1
> capacity 16
> print elements(1): 10.4
> quit

Exiting Program.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.