159.102 Instructions for Assignment 1
Assignment 1 starts in Week 2 and is due in Week 5(Thursday Sep. 22,2022 at 7pm)(China Time).
You should plan to complete the assignment about a week early. Then you still have time for revisions ifsomething unexpected happens to slow you down.
lt is a good idea to put your name and lD number in a comment at the top of your program.
Write a C++ program that converts binary numbers to decimal and decimal numbers to binary. Theprogram prompts the user to enter a number. You must read the number as a string. If the number isbinary, convert it to decimal.If the number is decimal, convert it to binary.If the number is not valid,
then an appropriate error message must be displayed.Use the examples below to (a) see what is requiredand (b) see the type of output that can occur.
Notes:
Your display must look the same as the examples shown below.
Example 1:
Enter a number: 8
Converting decimal to binary. The result is 0000 1000
Example 2:
Enter a number: 010
Converting binary to decimal. The result is 2
Example 3:
Enter a number: 10
Converting decimal to binary. The result is 0000 1010
Example 4:
Enter a number: hello
This is not a valid number.
Example 5:
Enter a number: 027
This is not a valid binary number.
Example 6:
Enter a number: 256
This decimal number is outside the range 0 to 255.
Example 7:
Enter a number: 00101001010
This binary number has more than 9 binary digits.
传送门:https://pan.baidu.com/s/1JJs9vbZahUCB6cQvXLgAVg?pwd=1111