# Assignment 2 Solution

\$30.00 \$24.90

Category:

## Description

Exercise 4.28 (Printing the Decimal Equivalent of a binary number) Allow the user to input at run time from the keyboard an integer containing only 0s and 1s (i.e. a binary integer) and print its decimal equivalent. Use the modulus % and the division / operators to pick off the “binary” number’s digits one at a time from right to left. (Do not use the library exponential function in this assignment). Much as in the decimal numbering system, where the right most digit has a positioned value of 1, the next digit left has a positioned value of 10, then 100, then 1000 and so on, in the binary numbering system the rightmost digit has a positioned value of 1, the next digit left has a positioned value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 2 * 100 + 3 * 10 + 4*1. The decimal equivalent of binary 1101 is 1 *1 + 0 * 2 + 1 * 4 + 1 *8 or 13.

Before you write any code, create the pseudo code and show your stepwise refinement of that pseudocode just like on page 125 (section 4.10). Include this stepwise refinement in a Microsoft word document. Using your pseudocode, write the C++ program. Note you do not need to create a class, you may do this all in one “non-reusable” single source code main program (see the rational for this approach in the middle of page 122).

Read the electronic appendix H from the text book on the Visual C++ debugger which has also been placed on the T-Square web site for you. Use it while debugging your program. Learn how to use it now to save you time on later more complicated programs.