#ifndef CA_UWATERLOO_DWHARDER_NUMERIC_ARRAY_1_H #define CA_UWATERLOO_DWHARDER_NUMERIC_ARRAY_1_H #include #include // Class declarations class Numeric_array_1; // Function/operator declarations std::ostream &operator<<( std::ostream &out, Numeric_array_1 const &array ); // Class definitions class Numeric_array_1 { public: Numeric_array_1(); // Rule of five: // If you must implement any one of these, // you should consider implementing all five... ~Numeric_array_1(); Numeric_array_1( Numeric_array_1 const &other ); Numeric_array_1( Numeric_array_1 &&other ) noexcept; Numeric_array_1 &operator=( Numeric_array_1 const &other ); Numeric_array_1 &operator=( Numeric_array_1 &&other ) noexcept; // Accessors (observers or queries): // - Member functions returning information without changing the contents. // Return properties of the array: // size, capacity, and is the array sorted. std::size_t size() const noexcept; std::size_t capacity() const noexcept; bool is_sorted() const noexcept; // Access the value at a given index: double operator[]( std::size_t n ) const; // Return the index of the first minimum // or the last maximum, respectively. std::size_t min() const; std::size_t max() const; // Return statistical properties of the entries double mean() const; double std_dev() const; double median() const; // Find if x is in the array using: // a binary search if the array is sorted, // and a linear search otherwise. std::size_t find( double x ) const; // Mutators (modifiers): // - Member functions that will modify or // change the contents of the object. // Append a new value to the end of the array, // insert a new value into an array assumed to be sorted: std::size_t append( double x ); std::size_t insert( double x ); // Sort the array and return the number of // inversions in the original unsorted array std::size_t sort() noexcept; private: std::size_t capacity_; double *array_; std::size_t size_; bool is_sorted_; static constexpr std::size_t CAPACITY_INCREMENT{ 10 }; // Increase the array capacity by 'CAPACITY_INCREMENT' void increase_capacity(); // Check that the argument is finite, // so neither infinity nor NaN. static void check_for_inf_or_NaN( double x ); }; #endif