// This ensures that this file is included at most once // in any program, as there may be multiple include // statements. #pragma once #include #include "Pair.hpp" //////////////////////// // Class declaration // //////////////////////// class Array; /////////////////////////// // Function declarations // /////////////////////////// // All function definitions are in the 'Array.cpp' file. // Initialize 'array' with the given capacity. // - Dynamically allocate an array of 'capacity' entries. // - Initialize each entry to 'initial_value'. // - If no initial value is supplied, initialize each // entry to 0.0. void array_init( Array &array, std::size_t const capacity, double const initial_value = 0.0 ); // Clean up 'array'. // - Deallocate the dynamically allocated array. // - Reset the member variables so that the object no // longer refers to the deallocated array. void array_clean_up( Array &array ); // Reset every entry in 'array' to 'new_value'. // - If no new value is supplied, reset each entry to 0.0. void array_reset( Array &array, double const new_value = 0.0 ); // Calculate the average of the entries in 'array'. double average( Array const &array ); // Determine whether the entries in 'array' are sorted // from least to greatest. // - If the array is sorted, return its capacity. // - Otherwise, return the index of the first entry that // is less than the entry immediately before it. std::size_t is_sorted( Array const &array ); // Return a comma-separated string containing the entries // in 'array'. std::string to_string( Array const &array ); // Return the indices of the maximum and minimum entries // in 'array'. // - 'first_' is the index of the maximum entry. // - 'second_' is the index of the minimum entry. Pair maxmin( Array const &array ); ////////////////////// // Class definition // ////////////////////// // Store the capacity of a dynamically allocated array // together with a pointer to its first entry. class Array { public: std::size_t capacity_; double *array_; };