question, you are required to write a program that takes as an input any decimal number (with fractional part) and then converts the fractional part to binary and display it on the screen. The program also takes in the number of fractional digits to show in the binary number (suppose this number could be entered and saved as floating-point, yet we test if it is integer or not later inside the program). Before converting the number, please take the following rules into consideration: • If the number to be converted has an integer part, the program should discard the integer part and convert the fractional part only. • If the number to be converted is negative then the program output should be Invalid. • If the number of required binary digits is not a positive integer, then the program output should be Invalid. There are several methods that can be used to perform the conversion task. Below, we will discuss two of these methods briefly and you have the freedom to use anyone of them to solve this assignment. Method 1: In this method, you have to split the fractional part from the integer part (if the number has an integer part), and multiply the fraction by two. After multiplication by two, the result wil

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In this question, you are required to write a program that takes as an input any decimal number (with fractional part) and then converts the fractional part to binary and display it on the screen. The program also takes in the number of fractional digits to show in the binary number (suppose this number could be entered and saved as floating-point, yet we test if it is integer or not later inside the program).
Before converting the number, please take the following rules into consideration:
• If the number to be converted has an integer part, the program should discard the integer part and convert the fractional part only.
• If the number to be converted is negative then the program output should be Invalid.
• If the number of required binary digits is not a positive integer, then the program output should be Invalid.
There are several methods that can be used to perform the conversion task. Below, we will discuss two of these methods briefly and you have the freedom to use anyone of them to solve this assignment.
Method 1:
In this method, you have to split the fractional part from the integer part (if the number has an integer part), and multiply the fraction by two. After multiplication by two, the result will start with either a 0 or 1. Take this 0 or 1 as the first fractional digit of your number. In the next step, split the fractional part of the previous result, and then multiply the fractional part by two again, and the result will have 0 or 1 in the integer part. This will be the second digit to the right of the first one. Keep repeating this process repeatedly until the fractional part is zero or you reached the required number of fractional digits entered by the user. The table below shows an example on how to apply Method 1 to convert 0.6875 to binray.

IMPORTANT NOTE 1 - Do not add any cout statements except for the final answer as specified above. Do not add "Enter a number", "the number of digits is" or any similar prompts. Also note that the grader is case-sensitive . Do not add any unnecessary spaces.

Sample Test Case 0
Input:
0.6875
Output:
101
Sample Test Case 1
Input:
0.67
Output:
101010
Sample Test Case 2
Input:
2.67
Output:
101010
Transcribed Image Text:Sample Test Case 0 Input: 0.6875 Output: 101 Sample Test Case 1 Input: 0.67 Output: 101010 Sample Test Case 2 Input: 2.67 Output: 101010
Conversion
Multiplication
Result
Done
0.6875*2 =
1
No
1.375
0.375*2 = 0.75
10
No
0.75*2 = 1.5
101
No
0.5*2 = 1.0
1011
Yes
Transcribed Image Text:Conversion Multiplication Result Done 0.6875*2 = 1 No 1.375 0.375*2 = 0.75 10 No 0.75*2 = 1.5 101 No 0.5*2 = 1.0 1011 Yes
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education