-
stacks - push - pop
I have two classes (number and stack), I have to take a user input number and convert it into binary, hex, and octal. Im getting there but how do you 'push' the remainder on the stack? Do you do it through in the main program or in the classes.cpp in the function push? The same with 'pop'????
Can someone please explain this too...."The program should show all 3 conversions each loop, you should be able to convert more than one vlue (overall loop for additional processing")?????
I don't have much started, but this is what I got.....
Code:
class number
{
public:
int remainder;
number* remainder;
number();
~number();
};
class stack
{
public:
int count;
int head;
void getnumb(int);
void display();
bool pop();
bool push();
};
#include <iostream>
#include number.h
using namespace std;
number::number()
{
cout << "Executing constructor..." << endl;
remainder = 0;
}
number::~number()
{
}
stack::stack()
{
count = 0;
head = NULL;
}
stack::~stack()
{
}
bool stack::push(int remainder)
{
bool success;
number* nptr = new number; //new node
stack* top;
nptr->rem = remainder; //store info
if (stack is full)
{
success = false;
}
else
{
if (head = = NULL) //insert into empty stack
{
nptr->next = head;
head = nptr;
}
else //insert into top of stack
{
nptr->next = top;
top = nptr;
}
count++;
}
success = true;
}
(Main program) ...
#include <iostream>
using namespace std;
int main()
{
int numb, digit;
cout << "number: " << endl;
cin >> numb;
while (numb > 0)
{
digit = numb % 2;
cout << digit;
numb = numb/2;
}
system ("pause");
return 0;
}
-
guessing...
>> Im getting there but how do you 'push' the remainder on the stack? Do you do it through in the main program or in the classes.cpp in the function push? The same with 'pop'????
Do it in the main program. Instantiate an object of stack and push/pop the remainder
>> ...."The program should show all 3 conversions each loop, you should be able to convert more than one vlue (overall loop for additional processing")?????
Code:
WHILE there's input number
convert input number to binary and display it
convert input number to hex and display it
convert input number to octal and display it
END WHILE