• C++进制转换题


    C++进制转换题

    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:

    1. Decimal numbers must be in the range 0 to 255 (you must check for this)
    2. Binary numbers must not be more than 9 binary digits (you must check for this)
    3. A binary number must always be entered with a leading zero (the first digit you enter must be 0)
    4. A decimal number must never be entered with a leading zero (check for this)
    5. Decimal numbers must never be displayed with leading zeros
    6. Binary numbers must always be displayed as 8 bits with a space after 4 bits (see the examples)
    7. The space will not be used when entering binary numbers - you do not have to check for this
    8. There are several different error messages - see examples 4 to 7
    9. Do not use a library function to convert binary to decimal - write your own function
    10. Do not use a library function to convert decimal to binary - write your own function
    11. You must include at least two (2) functions (these could be 9 and 10 above)

    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.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    源码传送门

    传送门:https://pan.baidu.com/s/1JJs9vbZahUCB6cQvXLgAVg?pwd=1111

  • 相关阅读:
    JMeter做http接口功能测试
    java-php-python-ssm校园约自习网站计算机毕业设计
    形态学操作—开运算
    [excel与dict] python 读取excel内容并放入字典、将字典内容写入 excel文件
    CorelDraw插件开发-X4-反调试分析-CDR插件开发
    【Linux】socket网络编程
    【python】学会这八个自动化脚本,摸鱼的借口那不就来啦~
    若依(ruoyi)管理系统(前后端分离版)本地运行教程(Windows)
    【Ascend C算子开发(入门)】——Ascend C编程模式与范式
    docker 安装 minio (单体架构)
  • 原文地址:https://blog.csdn.net/qq_35960743/article/details/126947563