home *** CD-ROM | disk | FTP | other *** search
- /* main.cpp -- Main (and only) C++ code file from
- * "Abstract Classes" target, "Classes in Depth" project.
- * This sample illustrates the use of abstract class definitions.
- * (c) 1996 by Sybase Inc.
- */
-
- #include "wpch.hpp"
-
- // some application definitions to make Optima happy.
- WModuleHandle _ApplicationModule = NULLHMODULE;
- static WApplication _Application;
- WApplication *Application = &_Application;
-
- // Class declarations:
- #include "abstract.hpp"
-
- // Class definitions:
-
- // nextChar increments the character stored in an instance
- // taking into account that there are only 256 characters in
- // the ASCII table.
- // This function is used by both concrete classes (ArrChar
- // and OneChar) in the main function.
-
- void AbstractChar::nextChar()
- {
- if (recall() < (unsigned char)255) // check if ASCII is 255
- store(recall() + 1);
- else
- store(0); // if ASCII is 255 store
- } // with null value
-
- // prevChar decrements the character stored in an instance
- // taking into account that there are only 256 characters in
- // the ASCII table.
- // This function is used by both concrete classes (ArrChar
- // and OneChar) in the main function.
-
- void AbstractChar::prevChar()
- {
- if (recall() > (unsigned char)0)
- store(recall() - 1);
- else
- store(255); // if recall is 0, store with ASCII of 255
- }
-
- // show displays a message and the character.
- // This function is also used by both concrete classes (ArrChar
- // and OneChar) in the main function.
-
- void AbstractChar::show(const char* pMessage, boolean bNewLine)
- {
- cout << pMessage << recall();
- if (bNewLine)
- cout << "\n";
- }
-
-
- int main( int argc, const char *argv[] )
- /***************************************
- */
- {
- int ret = -1;
-
- OneChar Char1; // instantiate Char1
- ArrChar Char2; // instantiate Char2
- unsigned char aSingleLetter = 'F'; // initializes
- // aSingle Letter
-
- // use the various functions to manipulate Char1 which is
- // an instance of OneChar class
-
- Char1.store(aSingleLetter);
- Char1.show("Object Char1 stores character ");
- Char1.nextChar();
- Char1.show("The next character is ");
- Char1.prevChar();
- Char1.prevChar();
- Char1.show("The previous character is ");
-
- // use the various functions to manipulate Char2 which is
- // an instance of ArrChar class
-
- Char2.store(aSingleLetter);
- Char2.show("Object Char2 stores character ");
- Char2.nextChar();
- Char2.show("The next character is ");
- Char2.prevChar();
- Char2.prevChar();
- Char2.show("The previous character is ");
-
- cout << "Press ENTER to continue...\n";
- cin.get();
-
- return ret;
- }
-
-