Confidential Teaching Materials
Homework 8 Criteria, Page 1 of 9
Homework 8 Grading Criteria
Note: To receive any credit whatsoever, your answers must be legible and readily readable in the
judgment of the grader. Add brief explanatory comments as necessary to make sure your answers
are clear and unambiguous to the grader.
[p1] 80 points
Arrays are useful in that they allow to access elements by an index. The drawback to arrays is that their size
must be fixed. This can cause some problems in software design because it forces the programmer to guess the
maximum number of elements he/she may need.
To get around this limitation, object-oriented languages such as Java allow a programmer to use a Vector class.
Through its public methods, a Vector allows random access to a dynamically-allocated data structure. Elements
in the data structure are accessed by their position. The first element in the structure is position 1, the second is
2, etc.
Your job is to implement a vector class. Since a user should be able to make a vector of any data type, your
class must use a generic parameter. Your vector class should use a linked list as its data structure to store the
elements in the vector, and should implement the following functionality:
function Element_At returnsa DataType (position isoftype in num)
Given a position, returns the element at that position.
You do not have to worry about the position being invalid.
procedure Remove_Element (position isoftype in Num)
Removes the element in the given position in the vector.
You do not have to worry about the the position being invalid.
function Size returnsa Num ()
Returns the number of elements in the vector.
function Contains returnsa Boolean (element isoftype in DataType)
Returns true if element is found in the vector; otherwise,
returns false.
procedure Add_Element (element isoftype in DataType)
Adds the given element to the end of the vector.
procedure Insert_Element_At (element isoftype in DataType,
position isoftype in num)
Adds the given element before the given position.
You do not have to worry about the position begin invalid.
function Is_Empty returnsa Boolean ()
Returns true if the vector has no elements; false is returned
otherwise.
Note that DataType in the above module headers indicates your class’s generic parameter. In modules that have
a position parameter, you may assume that the position will always be passed as a valid integer. Also assume
that the = operator will work on any type of generic parameter.
Feel free to add any “helper” modules in the protected section