Assignment 2 Solution

$30.00 $24.90


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.

Turn in pdfs of your test cases results by uploading them to T-Square (please no JPEG or PNG or word, upload a pdf doc for your test cases). Also in addition, upload the source code files (uncompiled) on or before the due date so your program may be tested. How your code is commented, how well you tested the program (just one test case or enough test cases to prove it works), any extra functionality, how you output your test results and details of program output will all be taken into consideration when grading your program. Your format of your code should look like that of the book. Note the comments in the book above every function explaining what that function does. You should have comments at the top that includes your name, the date, explains what the program does and comments above the functions explaining what they do in addition to some comments as needed on lines that explain what that line does.