home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  2.9 KB  |  98 lines

  1. /* main.cpp -- Main (and only) C++ code file from 
  2.  * "Abstract Classes" target, "Classes in Depth" project.
  3.  * This sample illustrates the use of abstract class definitions.
  4.  * (c) 1996 by Sybase Inc.
  5.  */
  6.  
  7. #include "wpch.hpp"
  8.  
  9. // some application definitions to make Optima happy.
  10. WModuleHandle _ApplicationModule = NULLHMODULE;
  11. static WApplication _Application;
  12. WApplication *Application = &_Application;
  13.  
  14. // Class declarations:
  15. #include "abstract.hpp"
  16.  
  17. // Class definitions:
  18.  
  19. // nextChar increments the character stored in an instance
  20. // taking into account that there are only 256 characters in
  21. // the ASCII table.
  22. // This function is used by both concrete classes (ArrChar
  23. // and OneChar) in the main function.
  24.  
  25. void AbstractChar::nextChar()
  26. {
  27.   if (recall() < (unsigned char)255)  // check if ASCII is 255
  28.     store(recall() + 1);             
  29.   else
  30.     store(0);                         // if ASCII is 255 store
  31. }                                     // with null value
  32.  
  33. // prevChar decrements the character stored in an instance
  34. // taking into account that there are only 256 characters in
  35. // the ASCII table.
  36. // This function is used by both concrete classes (ArrChar
  37. // and OneChar) in the main function.
  38.  
  39. void AbstractChar::prevChar()
  40. {
  41.   if (recall() > (unsigned char)0)
  42.     store(recall() - 1);
  43.   else
  44.     store(255);      // if recall is 0, store with ASCII of 255
  45. }
  46.  
  47. // show displays a message and the character.
  48. // This function is also used by both concrete classes (ArrChar
  49. // and OneChar) in the main function.
  50.  
  51. void AbstractChar::show(const char* pMessage, boolean bNewLine)
  52. {
  53.   cout << pMessage << recall();
  54.   if (bNewLine)
  55.     cout << "\n";
  56. }
  57.  
  58.  
  59. int main( int argc, const char *argv[] )
  60. /***************************************
  61. */
  62. {
  63.     int ret = -1;
  64.  
  65.         OneChar Char1;                         // instantiate Char1
  66.         ArrChar Char2;                         // instantiate Char2
  67.         unsigned char aSingleLetter = 'F';     // initializes
  68.                                                // aSingle Letter
  69.       
  70.         // use the various functions to manipulate Char1 which is
  71.         // an instance of OneChar class
  72.       
  73.         Char1.store(aSingleLetter);
  74.         Char1.show("Object Char1 stores character ");
  75.         Char1.nextChar();
  76.         Char1.show("The next character is ");
  77.         Char1.prevChar();
  78.         Char1.prevChar();
  79.         Char1.show("The previous character is ");
  80.       
  81.         // use the various functions to manipulate Char2 which is
  82.         // an instance of ArrChar class
  83.       
  84.         Char2.store(aSingleLetter);
  85.         Char2.show("Object Char2 stores character ");
  86.         Char2.nextChar();
  87.         Char2.show("The next character is ");
  88.         Char2.prevChar();
  89.         Char2.prevChar();
  90.         Char2.show("The previous character is ");
  91.         
  92.         cout << "Press ENTER to continue...\n";
  93.         cin.get();
  94.  
  95.     return ret;
  96. }
  97.  
  98.