Pardon me chaps, We are using stacks to convert a number, lets say 103, for instance to binary octal and hexadecimal. I am a bit perplexed by the whole situation and I was wondering if you blokes could perhaps share a little bit of your insight with me.I feel as though I've mastered the binary portion of the program.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
template <class T, int n>
class stack
{
private: T elt[n];
int counter;
public:
void clearstack() { counter = -1; }
bool emptystack() { return counter==-1?true:false; }
bool fullstack() { return counter==n -1?true:false; }
void push(T x) { counter++; elt[counter]=x; }
T pop() { T x; x=elt[counter]; counter--;return x; }
};
void main()
{
stack <int,7> s;
int m,n,p;
s.clearstack();
cout<<"Enter a number to convert: ";
cin>>m;
while( ! s.fullstack() )
{
n = m % 2;
s.push(n);
m = m / 2;
}
while(! s.emptystack())
{
p = s.pop();
cout<<p;
}
cout<<endl;
}
So if you could help me out with the whole hexadecimal portion of this program I would be very appreciative thank you very kindly.
(english enough for you sean)