CSCI 200 - Foundational Programming Concepts & Design - Fall 2022

Lab 3C - Array Test Suite

This lab is due by Tuesday, October 11, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Instructions


A skeletal test suite has been provided for you in array_tests.zip.

Your job: implement each function such that all tests pass.

You will first want to make the function prototypes and definition stubs so your code will compile, link, and run. Then begin implementing each function one at a time. The expected function signatures are described via the comments below (also included in the test suite). After you have completed the implementation for a function, update the comment with the Big O complexity of the function.

/**
 * @brief Allocates an integer array of a target size on the free store.
 * Upon function return, pArray will point to starting address and the
 * contents of pArray will all be initalized to zero.
 *
 * @param pArray pointer to integer array
 * @param INIT_SIZE initial array size as an integer
 *
 * @note Runtime of function O(?)
 */
array_allocate();

/**
 * @brief Returns the value of the element at a target position.  If the
 * position it not within the array size, throws a standard exception
 *
 * @param pArray pointer to integer array
 * @param SIZE size of the array as an integer
 * @param POS position to retrieve value from
 * @return int element value at given position
 * @throws standard exception if array is null or position out of range
 *
 * @note Runtime of function O(?)
 */
array_get_element_at();

/**
 * @brief Sets the value of the element at a target position.  If the
 * position is out of range, does nothing.
 *
 * @param pArray pointer to integer array
 * @param SIZE size of the array as an integer
 * @param POS position to set value at
 * @param VALUE value to place at target position
 *
 * @note Runtime of function O(?)
 */
array_set_element_at();

/**
 * @brief Deallocates an integer array, returning its memory back to
 * the free store.  Upon function return, pArray will be set to be a
 * null pointer and the array size will be set to zero.
 *
 * @param pArray pointer to integer array
 * @param size size of the array as an integer
 *
 * @note Runtime of function O(?)
 */
array_deallocate();

/**
 * @brief Inserts a value at a target position.  If the position is
 * out of range, inserts at the front/back as appropriate.  Upon
 * function return, the array will be increased in size by one.  The
 * array size will be updated to the new size.
 *
 * @param pArray pointer to integer array
 * @param size size of the array as an integer
 * @param POS position to insert value at
 * @param VALUE value to insert at target position
 *
 * @note Runtime of function O(?)
 */
array_insert_at_position();

/**
 * @brief Returns the minimum value within the array.  If array size is
 * zero or the array is uninitialized, throws a standard exception.
 *
 * @param pArray pointer to the integer array
 * @param SIZE size of the array as an integer
 * @return int minimum value within the array
 * @throws standard exception if array is null or position out of range
 *
 * @note Runtime of function O(?)
 */
array_min();

/**
 * @brief Returns the maximum value within the array.  If array size is
 * zero or the array is uninitialized, throws a standard exception.
 *
 * @param pArray pointer to the integer array
 * @param SIZE size of the array as an integer
 * @return int maximum value within the array
 * @throws standard exception if array is null or position out of range
 *
 * @note Runtime of function O(?)
 */
array_max();

/**
 * @brief Returns the first position within an array a target value
 * is located at.  If the target value is not present within the
 * array, returns -1.
 *
 * @param pArray pointer to the integer array (the haystack)
 * @param SIZE size of the array as an integer
 * @param TARGET target integer value to search for in the array (the needle)
 * @return int position within the array target value is located (or -1 if not present)
 *
 * @note Runtime of function O(?)
 */
array_find();

/**
 * @brief Removes a value at a target position.  If the position is
 * out of range, removes from the front/back as appropriate.  Upon
 * function return, the array will be decreased in size by one.  The
 * array size will be updated to the new size.
 *
 * @param pArray pointer to integer array
 * @param size size of the array as an integer
 * @param POS position to remove value from
 *
 * @note Runtime of function O(?)
 */
array_remove_from_position();

When your program prints PASSED for a given unit test instead of FAILED, then you know that your function implementation for that test is complete.


Hints



Functional Requirements



Lab Submission


Submit your array_functions.h, array_functions.cpp file(s).

You will submit your solution to this lab with the rest of Set3. Detailed instructions for doing this are posted in Assignment 3.


This lab is due by Tuesday, October 11, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.