Apr 30, 2013

GWC CS G175 C++ Assignment 11 - Due 4/29/2013

Write a base class “number” that holds a single integer value (value of intInput) and contains one pure virtual member function, print_it().  This will make the base class abstract in order to prevent its instantiation.  Define three derived classes to print the value in hexadecimal, octal, and binary (overriding the print_it() method). Write a program to demonstrate the use of all the derived classes. The user should enter the value to be converted (intInput).
In order to demonstrate polymorphism, the code in main() should look like:

number* Example;
Example = new hexadecimal(intInput);
// compiler takes care of binding and prints the value in hexadecimal
delete Example;
Example = new octal(intInput);

For this exercise, the conversion code should be similar to the one used in Assignment _9.  Therefore you should again use the stack class provided. However, in this case, you don’t need a complete menu, just ask for a decimal value to convert and show the result of the 3 conversions.
Additional info:
This assignment 11 requires polymorphism.  You need to create a base class "number" that contains an integer as member data, as well as a pure virtual function "print_it". Then derive from it three classes: hexadecimal, octal and binary.  Each of the derived class should override the method print_it.  Each print_it method will print the value stored in the base class member data in its according format (hexadecimal in hexa, etc.).
The driver (main()) should create the objects in sequence, using a pointer to the base class number, as shown in the lab description above, that will print the  conversion of the int previously entered by the user in the 3 different formats...
  • I do not post codes before the due date, since that does not help you.
  • Codes may be incorrect because I am a learner like you. Use it at your discretion.
 Code (will be updated)