home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / SETCLASS.ZIP / OOSET.H < prev    next >
C/C++ Source or Header  |  1991-11-02  |  3KB  |  117 lines

  1. //
  2. //                          PROBLEM 2, CHAPTER 4
  3. //                               LEARNING C++
  4. //                            by NEILL GRAHAM
  5. //
  6. //                               Joe Hatfield
  7. //                            CIS 72657,717
  8. //                           October 31, 1991
  9. //
  10. //
  11. // A set of integers, all in the range MIN through MAX, can be represented
  12. // by a character array c of size MAX - MIN + 1; element c[i - MIN] is 1
  13. // if i belongs to the set and 0 if it does not.
  14. //
  15. //
  16. //              For MAX = 20 and MIN = 10, length = 11
  17. //
  18. //             the set { 13, 14, 18 } can be represented
  19. //             by the following array c:
  20. //
  21. //        i        0    1    2    3    4    5    6    7    8    9    10
  22. //           -----------------------------------------------
  23. //    c[i]      0    0    0    1    1    0    0    0    1    0    0
  24. //
  25. //
  26. // File ooset.h
  27. // Header file for class ooset
  28. //
  29. //  Check for compiler
  30. #    ifndef __BCPLUSPLUS__
  31. #        error Must use BORLAND C++ Compiler
  32. #    endif
  33.  
  34. //  Define ooset.h
  35. #    ifndef __OOSET_H
  36. #    define __OOSET_H
  37.  
  38. //  Define NULL
  39. #    ifndef NULL
  40. #        if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  41. #            define NULL    0
  42. #        else
  43. #            define NULL    0L
  44. #        endif
  45. #    endif
  46.  
  47. //  Define Class type
  48. #    if defined(__SMALL__) || defined(__MEDIUM__)
  49. #        define _CLASSTYPE near
  50. #    elif  defined(__COMPACT__) || defined(__LARGE__)
  51. #        define _CLASSTYPE far
  52. #    else
  53. #        define _CLASSTYPE hugh
  54. #    endif
  55.  
  56. //  Check for includes
  57. #    if !defined( __IOSTREAM_H )
  58. #        include <iostream.h>
  59. #    endif
  60.  
  61. #    if !defined( __STDLIB_H )
  62. #        include <stdlib.h>
  63. #    endif
  64.  
  65. #     if !defined( __MEM_H )
  66. #        include <mem.h>
  67. #    endif
  68.  
  69. const MINIMUM = 10;
  70. const MAXIMUM = 20;
  71.  
  72. enum BOOLEAN { FALSE, TRUE };
  73.  
  74. class _CLASSTYPE set
  75. {
  76.         char* ptr;        // Pointer to the array
  77.         int min;        // The minimum range of the set
  78.         int max;        // The maximum range of the set
  79.         int len;        // The length of the array
  80.  
  81.     public:
  82.         set();                                    // Empty set Constructor
  83.         set( int num );                            // Singleton set Constructor
  84.         ~set( void ) { delete ptr; }            // Set Destructor
  85.         set( const set& s );                      // Copy set operator
  86.         set& operator= ( const set& set_two );    // Assignment operator
  87.  
  88.         // Complement operator
  89.         friend set operator- ( const set& s );
  90.  
  91.         // Difference operators
  92.         friend set operator- ( const set& set_one, const set& set_two );
  93.         set& operator-= ( const set& set_two );
  94.  
  95.         // Union operators
  96.         friend set operator+ ( const set& set_one, const set& set_two );
  97.         set& operator+= ( const set& set_two );
  98.  
  99.         // Intersection operators
  100.         friend set operator* ( const set& set_one, const set& set_two );
  101.         set& operator*= ( const set& set_two );
  102.  
  103.         // Equality operators
  104.         friend BOOLEAN operator== ( const set& set_one, const set& set_two );
  105.         friend BOOLEAN operator!= ( const set& set_one, const set& set_two );
  106.  
  107.         // Comparison operators
  108.         friend BOOLEAN operator<  ( const set& set_one, const set& set_two );
  109.         friend BOOLEAN operator>  ( const set& set_one, const set& set_two );
  110.         friend BOOLEAN operator>= ( const set& set_one, const set& set_two );
  111.         friend BOOLEAN operator<= ( const set& set_one, const set& set_two );
  112.  
  113.         // Output operator
  114.         friend ostream& operator<< ( ostream& stream, const set& data );
  115. };
  116. #endif    // define __OOSET_H
  117.