Assignment_9

Assignment_9 - integers (code for a stack class has been...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science G175 - C++ Programming Assignment 9 Assignment_9.cpp (4 points) Create a program that will accept numbers in decimal and display them in either binary, octal or hexadecimal. Use a switch statement to select the option (binary, octal, or hex) picked from the menu and make use of modulus (%) and divide operators. A sample run of the program is shown: Enter a number in decimal: 255 Convert the number from decimal into: 0 – Binary 1 – Octal 2 – Hexadecimal 2 The number 255 (decimal) is FF in hexadecimal. Store the base to convert to chosen by the user as an integer and use a while() loop that performs integer division and modulus operations on the number entered by the user. As the result would be reversed, your program will need the capability to reverse the order of the digits as part of the number conversion process. To do this, create a stack class based on the “last-in, first-out” concept that allows you to push (write) and pop (read)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: integers (code for a stack class has been posted to the website for you to use). Using a stack object, you will push the results of your computation (loop using % and /) as you get them (one digit at a time, as an integer). Once done, you will pop the values from the stack to get them in the right order and use another loop to cout them. In this output loop (while popping the values, you will need to handle the values (intBuffer) that may be greater then 9 when dealing with hexadecimal. This can be done using code similar to: if (intBuffer > 9) cout << char('A' + intBuffer - 10); // displays digit > 9 as char else cout << intBuffer; In addition to these labs, also review the Word document Session 9 that has been posted to the website. Please refer to our textbook, chapter Lesson 11 for additional information. Page 1 of 1...
View Full Document

Ask a homework question - tutors are online