Recitation -- Stack Exercise

This exercise uses the Stack class from the Deitel text, which we are discussing in lecure class. Remember, a Stack has just one access point (the "top") -- and the primary functions are push (for inserting data into the stack) and pop (for removing items from the stack). This implementation uses the linked list implementation (also from Deitel). Download all 3 files from here:

Stack template class

Write a main program that uses a Stack of integers to take a base-10 integer value and print its binary representation.

Here is the algorithm

create an empty stack
read in the number to be converted (from standard input)

while number not equal to 0
   find remainder when number is divided by 2
   push remainder on the stack
   divide number by 2

while stack is not empty
   pop element from top of stack and display 

Here are a few sample outputs from the program

(User input underlined)
Enter an integer: 123
The number 123 translated into binary is: 
1111011

Enter an integer: 50
The number 50 translated into binary is: 
110010

Enter an integer: 12345
The number 12345 translated into binary is: 
11000000111001

Enter an integer: 99999
The number 99999 translated into binary is: 
11000011010011111