home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / 9n06062a < prev    next >
Text File  |  1991-02-25  |  2KB  |  109 lines

  1. //
  2. //    TryThing    --  Test stub for Thing and 
  3. //            --  ThingList classes.
  4. //            --
  5. //            --  Also uses overloaded global
  6. //            --  new and delete operators
  7. //            --  to aid in debugging.
  8. //
  9. //    Version 1.01      --  2/25/91
  10. //
  11. //    Michael Kelly      --  Author
  12. //
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include "hsort.hpp"
  17. #include "th_int.hpp"
  18. #include "th_long.hpp"
  19. #include "th_doubl.hpp"
  20. #include "th_struc.hpp"
  21. #include "th_list.hpp"
  22.  
  23. #define N 5
  24.  
  25. a_struct my_struct[ N ] =  {
  26. { "mike", 3 },
  27. { "tom", 2 },
  28. { "joe", 5 },
  29. { "jim", 1 },
  30. { "frank", 0 }
  31. };
  32.  
  33. unsigned iterations;
  34. int i;
  35.  
  36. void action()
  37. {
  38. ThingList thing_list;
  39. IntThing int_thing[ N ] =  { 103, 29, 89, 55, 15 };
  40. DoubleThing double_thing[ N ] = { 5.3, 8.7, 0.01, 3.1416, 0.0 };
  41. LongThing long_thing[ N ] = { 500L, 2L, 85L, 909L, 6L };
  42. StructThing struct_thing[ N ] = {
  43.     my_struct[ 0 ], my_struct[ 1 ], my_struct[ 2 ],
  44.     my_struct[ 3 ], my_struct[ 4 ] };
  45.  
  46.  
  47.     if( int_thing[ 0 ].sortable() )
  48.     heapsort( N, int_thing );
  49.     if( long_thing[ 0 ].sortable() )
  50.     heapsort( N, long_thing );
  51.     if( double_thing[ 0 ].sortable() )
  52.     heapsort( N, double_thing );
  53.     if( struct_thing[ 0 ].sortable() )
  54.     heapsort( N, struct_thing );
  55.  
  56.  
  57.  
  58.     for( i = 0; i < N; ++i )
  59.     if( ! thing_list.add( int_thing[ i ] ) )  {
  60.         printf("\n\tCould not add a Thing to the list!\n");
  61.         return;
  62.     }
  63.     for( i = 0; i < N; ++i )
  64.     if( ! thing_list.add( long_thing[ i ] ) )  {
  65.         printf("\n\tCould not add a Thing to the list!\n");
  66.         return;
  67.     }
  68.  
  69.     for( i = 0; i < N; ++i )
  70.     if( ! thing_list.add( double_thing[ i ] ) )  {
  71.         printf("\n\tCould not add a Thing to the list!\n");
  72.         return;
  73.     }
  74.  
  75.     for( i = 0; i < N; ++i )
  76.     if( ! thing_list.add( struct_thing[ i ] ) )  {
  77.         printf("\n\tCould not add a Thing to the list!\n");
  78.         return;
  79.     }
  80.  
  81.     iterations = thing_list.iterate( &Thing::print );
  82.  
  83.     printf(
  84.     "\n\t %u iterations "
  85.     "of print() method performed\n",
  86.     iterations
  87.     );
  88.  
  89.     thing_list.ThingList::~ThingList();
  90.  
  91.     for( i = N - 1; i >= 0; --i )
  92.     struct_thing[ i ].StructThing::~StructThing();
  93.  
  94.     for( i = N - 1; i >= 0; --i )
  95.     double_thing[ i ].DoubleThing::~DoubleThing();
  96.  
  97.     for( i = N - 1; i >= 0; --i )
  98.     long_thing[ i ].LongThing::~LongThing();
  99.  
  100.     for( i = N - 1; i >= 0; --i )
  101.     int_thing[ i ].IntThing::~IntThing();
  102. }
  103.  
  104. int main(void)
  105. {
  106.     action();
  107.     return 0;
  108. }
  109.