nput: 0 Output: Invalid Sample Testcase 1: Input: 1 847 Output: Invalid Sample Testcase 2: Input

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
input:

0

Output:

Invalid

Sample Testcase 1:
Input:

1

847

Output:

Invalid

Sample Testcase 2:

Input

1

77

Output:

63

Sample Testcase 3:

Input

2

(-54)

Output:

Negative

Sample Testcase 4:

Input

2

97

Output:

141

 
 
 
 
 
 
 
 
 
 
 
#include <iostream>
 
#include <cmath>
 
#include <cstdlib>
 
using namespace std;
 
 
int main()
 
 
{
 
  //Start your code here
 
 
 
   return 0;
 
}
 
 
 
In this task, you are required to write a code that converts an Octal number into its equivalent Decimal value or vice versa. The user first selects the conversion
choice by inserting 1 or 2.
• Choice 1 is followed by inserting an Octal integer and getting its Decimal equivalent value as an output.
• Choice 2 requires inserting a Decimal integer and prints out its Octal equivalent.
The Octal numeral system, is the base-8 number system, and uses the digits 0 to 7, that is to say 10 octal represents 8 Decimal and 100 octal represents 64
Decimal.
Convertion from an Octal integer into Decimal
In the Decimal system, each number is the digit multiplied by 10 to the power of its location (starting from 0). For example:
• 74 decimal = 7 x 10^1 + 4 x 10^0
• 1252 decimal = 1 x 10^3 + 2 x 10^2 + 5 x 10^1 + 2 x 10^0
each number is the digit multiplied by 8 to the power of its location (starting from 0). For example:
• 112 octal = 1 x 8^2 + 1 x 8^1 + 2x8^0
Converting an Octal integer into Decimal can be done by performing the last calculation. Hence, 112 in Octal is equal to 64 + 8 + 2 = 74 in Decimal.
Conversion from a Decimal integer into Octal
On the other hand, to convert a Decimal integer into Octal, follow the follwoing steps:
●
1. Divide the number by 8, you get a quotient and a remainder.
●
2. Take note of the remainder. It can be any number between 0 to 7. This number will be the last digit of the octal number, i.e., the rightmost digit.
3. Use the quotient from step 1 as your new initial number.
4. Repeat steps 1-3, and keep concatenating the remainder to the left of the previously obtained digits. Stop when the quaotient is zero.
Transcribed Image Text:In this task, you are required to write a code that converts an Octal number into its equivalent Decimal value or vice versa. The user first selects the conversion choice by inserting 1 or 2. • Choice 1 is followed by inserting an Octal integer and getting its Decimal equivalent value as an output. • Choice 2 requires inserting a Decimal integer and prints out its Octal equivalent. The Octal numeral system, is the base-8 number system, and uses the digits 0 to 7, that is to say 10 octal represents 8 Decimal and 100 octal represents 64 Decimal. Convertion from an Octal integer into Decimal In the Decimal system, each number is the digit multiplied by 10 to the power of its location (starting from 0). For example: • 74 decimal = 7 x 10^1 + 4 x 10^0 • 1252 decimal = 1 x 10^3 + 2 x 10^2 + 5 x 10^1 + 2 x 10^0 each number is the digit multiplied by 8 to the power of its location (starting from 0). For example: • 112 octal = 1 x 8^2 + 1 x 8^1 + 2x8^0 Converting an Octal integer into Decimal can be done by performing the last calculation. Hence, 112 in Octal is equal to 64 + 8 + 2 = 74 in Decimal. Conversion from a Decimal integer into Octal On the other hand, to convert a Decimal integer into Octal, follow the follwoing steps: ● 1. Divide the number by 8, you get a quotient and a remainder. ● 2. Take note of the remainder. It can be any number between 0 to 7. This number will be the last digit of the octal number, i.e., the rightmost digit. 3. Use the quotient from step 1 as your new initial number. 4. Repeat steps 1-3, and keep concatenating the remainder to the left of the previously obtained digits. Stop when the quaotient is zero.
Example: convert Decimal number 6521 to octal representation:
1. Divide by 8, i.e., 6521/8 = 815, remainder is 1.
2. Now, we will use the quotient from step 1, i.e., 815 as the new number, and repeat step 1.
3. We will continue repeating the above steps until we get 0 as the quotient.
System Message: WARNING/2 (<string>, line 35)
Block quote ends without a blank line; unexpected unindent.
4. Reading the remainders in reverse order, the number 14571 is the Octal value for 6521 in Decimal
Important Notes:
• If the inserted choice is wrong, the output will be "Invalid".
• If the inserted Octal or Decimal number is a negative value, the output will be " Negative".
• If the inserted Octal number has at least one digit which is 8 or 9, the output will be "Invalid".
• You are not allowed to add any additional headers/libraries to the code
1/0
Program Input:
• Conversion choice (1 or 2)
• An integer number to be converted based on the previous choice
Program Output:
• A single line that represents the converted value
Transcribed Image Text:Example: convert Decimal number 6521 to octal representation: 1. Divide by 8, i.e., 6521/8 = 815, remainder is 1. 2. Now, we will use the quotient from step 1, i.e., 815 as the new number, and repeat step 1. 3. We will continue repeating the above steps until we get 0 as the quotient. System Message: WARNING/2 (<string>, line 35) Block quote ends without a blank line; unexpected unindent. 4. Reading the remainders in reverse order, the number 14571 is the Octal value for 6521 in Decimal Important Notes: • If the inserted choice is wrong, the output will be "Invalid". • If the inserted Octal or Decimal number is a negative value, the output will be " Negative". • If the inserted Octal number has at least one digit which is 8 or 9, the output will be "Invalid". • You are not allowed to add any additional headers/libraries to the code 1/0 Program Input: • Conversion choice (1 or 2) • An integer number to be converted based on the previous choice Program Output: • A single line that represents the converted value
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY