/cs4500-a1-p2

Assignment 1 Part 2

Primary LanguageC++

Array API

For this assignment, we decided to create the API for an array

object class

This class creates a generic object type. Here, we test whether two Objects are equal to each other, as well as a hash function.

array class

This class extends our object class. We also have a deconstructor that deletes the array.

array class methods

All of our methods are virtual, so they can be accessed and manipulated outside of the class.

size() //returns the number of elements in this array
index_of(Object* o) //returns index of given object in this array
push(Object* o) //pushes given object onto end of this array
add(size_t idx, Object* o) //adds given element to the array at the given index
add_all(size_t idx, Array* a) //adds all given elements to the array at the given index
get(size_t idx) //returns element of the array at the given index
set(size_t idx, Object* o) //sets the given index to the given element
remove(size_t idx) //removes the object at the given index
clear() //removes all elements from the array
equals(Object* o) //checks if this array is equal to the given object
hash() //adds together the hashes of all the objects

BoolArray, IntArray, FloatAray, StringArray

In order to fit the spec of the assignment, we have added subclasses that inherit the array class. These arrays support boolean, integer, float and string values. Each of these methods takes in arguments based on its respective class.

index_of(Object* o) //returns index of given object in this array
push(Object* o) //pushes given object onto end of this array
add(size_t idx, Object* o) //adds given element to the array at the given index
add_all(size_t idx, Array* a) //adds all given elements to the array at the given index
get(size_t idx) //returns element of the array at the given index
set(size_t idx, Object* o) //sets the given index to the given element
remove(size_t idx) //removes the object at the given index

test-array class

Contains tests that test all the functions above and for each respective type.

running

To run, compile and run tests using the command "make"