//=========================================================================== // Class declaration for data items. // A. Fischer, May 29, 2001 file: item.hpp //=========================================================================== #pragma once #include #include "exam.hpp" #include "ordered.hpp" //-------------------------------------------------------------------------- class Item : public Exam, public Ordered { public: static const int max_sentinel = int(INT_MAX); static const int min_sentinel = int(INT_MIN); Item(const char* init, int sc): Exam(init, sc){} ~Item() { cout <<"Deleting Item " << score <<"\n"; } int key() const { return score; } // Exam ordering operators bool operator< (const int& k) const { return key() < k; } bool operator==(const int& k) const { return key() == k; } // The symbol PRIMARY_INTERFACE describes which of two alternative Ordered // interfaces to implement #ifdef PRIMARY_INTERFACE // Promises fulfilled by Exam ordering operators above // Comparison with another Item is defined in terms of the above bool operator< (const Item& s) const { return key() < s.key(); } bool operator==(const Item& s) const { return key() == s.key(); } #else // Promises fulfilled by operators below and by key() function. // These subsume the Item comparison operators of the PRIMARY_INTERFACE bool operator< (const Ordered& s) const { return key() < s.key(); } bool operator==(const Ordered& s) const { return key() == s.key(); } #endif };