// ---------------------------------------------------------------------------- // Header file for all DataPack programs. datapack.hpp // Created by Alice Fischer on Sunday August 23, 2009 // ----------------------------------------------------------------------------- #pragma once #include "tools.hpp" // Includes all the other headers you need. typedef float BT; // Generic base type for data pack; BT must implement <= #define INITIAL_LENGTH 4 class DataPack { private: // ------------------------------------------------------------------ int n; // The current number of items in the array. int max; // Allocation length of the array. BT* store; // For a dynamically allocated data array. void grow(); public: // ------------------------------------------------------------------- DataPack() { // default constructor n = 0; max = INITIAL_LENGTH; store = new BT[max]; cout << "Store allocated.\n"; // C++ throws an exception if the allocation fails. No test needed here. } ~DataPack() { delete[] store; cout << "Store deallocated.\n"; } // ------------------------------------------------------------------------- int getN() const { return n; } BT getItem(int i) const { return store[i]; } void add(BT item) { if (n == max) grow(); store[n++] = item; } void readData(); void printData(ostream& out) const; void sortData(); };