home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX09091.H
-
- // Files used in this example:
- //---------------------------------------------------------
- // EX09091.H this file
- // %F,15,EX09091.CPP%EX09091.CPP
- // %F,15,EX0909.CPP%EX0909.CPP
- //---------------------------------------------------------
-
- // Used to store a pair of integers
- typedef struct { long first, second;} LongPair;
-
- //---------------------------------------------------------
- // The Grades Class manages an associative array of grades
- //---------------------------------------------------------
- class Grade
- {
- public:
- // Used to associate a letter grade to a numeric grade
- // range
- typedef struct
- {
- char letter[4]; // Used to store a letter grade
- LongPair range; // Used to store a numeric grade range
- } GradeAssoc;
-
- static const LongPair null;
-
- //------------------------------------------------------
- // FUNCTION: operator[]
- // PARAMETERS: char * p A letter grade
- // Return Value: LongPair A numeric range
- //------------------------------------------------------
- LongPair
- operator[]( char* p);
-
- //------------------------------------------------------
- // FUNCTION: operator[]
- // PARAMETERS: LongPair A numeric range
- // RETURN VALUE: char * p A letter grade
- //------------------------------------------------------
- char*
- Grade::operator[]( int x);
-
- //------------------------------------------------------
- // Iterates through all values in the Grade Associative
- // array
- //------------------------------------------------------
- friend class GradeIterator;
-
- //------------------------------------------------------
- // FUNCTION: NumElem
- // RETURN VALUE: The number of grades in the associative
- // array
- //------------------------------------------------------
- const int
- NumElem() const { return 5;}
-
- private:
- //------------------------------------------------------
- // The associative array of Numeric grade ranges and Letter
- // grades
- //------------------------------------------------------
- static GradeAssoc GradeList[];
-
- //------------------------------------------------------
- // Used to compare two Letter grades
- //------------------------------------------------------
- // friend int _Optlink // IBM CSet II version
- // CompareLetter( const void* keyval, const void* datum);
- friend int // Borland and Microsoft version
- CompareLetter( const void* keyval, const void* datum);
-
- };
-
-
- ostream&
- operator<<( ostream& os, LongPair range);
-
-
- ostream&
- operator<<( ostream& os, Grade::GradeAssoc assoc);
-
- //---------------------------------------------------------
- // Use to iterate through a the associative array of grades
- //---------------------------------------------------------
- class GradeIterator
- {
- const Grade* pGrade; // points to the associative array
- int index; // used to increment through the associative array
- public:
- //-------------------------------------------------------
- // FUNCTION: constructor
- // PARAMETERS: Grade& grade
- //-------------------------------------------------------
- GradeIterator( const Grade& grade);
-
- //-------------------------------------------------------
- // FUNCTION: operator()
- // RETURN VALUE: the next Grade association in
- // the associative array
- //-------------------------------------------------------
- Grade::GradeAssoc*
- operator()();
- };
-
-
-