Assignment_9

# Assignment_9 - Computer Science G175 C Programming...

• Notes
• 1

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

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)
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

• Fall '06
• Mike
• Computer Science, Binary numeral system, Decimal, one digit, c++ programming assignment

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern