#include <iostream>
using namespace std;
const int MYSTACK_SIZE = 100;
class myStack
{
private:
int count; // number of items in the myStack
int data[MYSTACK_SIZE];
public:
myStack();
~myStack();
void push(const int item); // push an item on the myStack
int pop(); // pop item off the myStack
int getCount() const; // return count
};
myStack::myStack() // constructor
{
count = 0; // zero the myStack
}
myStack::~myStack() {} // default destructor
void myStack::push(const int item)
{
if (count < MYSTACK_SIZE)
{
data[count] = item;
++count;
}
else cout << "Overflow!\n";
}
int myStack::pop()
{
if (count >0)
{
--count;
return (data[count]);
}
else
{
cout << "Underflow!\n";
return 0;
}
}
int myStack::getCount() const
{
return count;
}
class number
{
private:
int intInput;
public:
virtual int print_it();
};
//What am I supposed to do with this?
int number::print_it()
{
return intInput;
}
class binary: public number
{
private:
int intInput;
int binRemainder;
public:
void print_it(int);
};
void binary::print_it(int intInput)
{
myStack reverse;
while (intInput > 0)
{
binRemainder = intInput % 2;
intInput /= 2;
reverse.push(binRemainder);
}
while(reverse.getCount() > 0)
{
cout << reverse.pop();
}
};
class octal: public number
{
private:
int intInput;
int octRemainder;
public:
void print_it(int);
};
void octal::print_it(int intInput)
{
myStack reverse;
while(intInput > 0)
{
octRemainder = intInput % 8;
intInput /= 8;
reverse.push(octRemainder);
}
while (reverse.getCount() > 0)
{
cout << reverse.pop();
}
}
class hex16: public number
{
private:
int intInput;
int hexRemainder;
public:
void print_it(int);
};
void hex16::print_it(int intInput)
{
myStack reverse;
int pop;
while (intInput > 0)
{
hexRemainder = intInput % 16;
intInput /= 16;
reverse.push(hexRemainder);
}
while (reverse.getCount() > 0)
{
pop = reverse.pop();
if (pop > 9)
{
cout << char('A' + pop - 10); // displays digit > 9 as char
}
else
{
cout << pop;
}
}
}
int main() {
int intInput;
cout << "Enter a decimal to be converted: ";
cin >> intInput;
binary bin;
octal oct;
hex16 hexa;
number * convert1 = &bin;
number * convert2 = &oct;
number * convert3 = &hexa;
convert1->print_it();
convert2->print_it();
convert3->print_it();
cout << "Binary: " << convert1->print_it() << "\nOctal: " << convert2->print_it() << "\nHexadecimal: " << convert3->print_it() << endl;
cout << endl;
system("pause");
return 0;
}