Question: You are going to write a program that changes a decimal number into a hexadecimal number. In order to do this, you will write a
You are going to write a program that changes a decimal number into a hexadecimal number. In order to do this, you will write a stack class. The stack class should be implemented using the node class and will use dynamic memory to create nodes similar to the linked list. The data for the node will be an integer. The stack class should be generic. The code to use the stack and convert the number should be in the main program.
1. Divide the decimal number by 16. Treat the division as an integer division.
2. Write down the remainder (in hexadecimal).
3. Divide the result again by 16. Treat the division as an integer division.
4. Repeat step 2 and 3 until result is 0.
5. The hex value is the digit sequence of the remainders from the last to first.
Specific information for class:
- Stack class data
- top points to first Node in list
- count keeps track of number of Nodes in list
Stack class functions
- Any needed constructors
- Push adds a Node to the top of the stack
- Pop Removes a Node from the top of the stack
- Stack_top Returns the item at the top of the stack without affecting the stack
- Empty returns true if stack is empty, false otherwise
Note: Remember that a stack is created in static (automatic memory) and a Node is in dynamic memory.
Requirements for main:
In the main program, you will ask the user for a decimal number. You will use the stack program that you wrote to change the decimal number into a hexadecimal number and print the result.
Sample:
Enter a number:
10
The hexadecimal number is : A
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
