Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ please This is the code I have now but I don't know how to write the code for different bases #include #include #include

image text in transcribedimage text in transcribed

In C++ please

This is the code I have now but I don't know how to write the code for different bases

#include #include #include using namespace std;

int main() { int choice; bool variableConvert = true; while (variableConvert != false){ cout > choice;

switch (choice) { case 1: cout > binaryNum; for (int i = 0; i

break; case 2: cout > n; string s; while (n) { s += (n % 2) + '0'; n /= 2; } for (int i = s.size() - 1; i >= 0; i--) cout > choice; break; }

} return 0; }

Key Learning Objectives: - Understand binary, hexadecimal \& decimal bases - Input (numeric \& string) - Looping - Branching - Print formatting Assignment Problem: There are two functions that are a part of this problem: a. Base to Decimal: Given a number and its given base, convert the number to decimal (NOTE: Given bases can be 2-16) b. Decimal to Base: (Video with pseudocode for this) Given a number in decimal, and a base, convert the decimal to that base (NOTE: Resulting bases can be 2-16) There is bonus involved for the following additions: i. A loop to continue until a ' q ' is entered ii. Converting from any base to any base. Practical solution: a. You should have a menu that drives the choices to be made. b. It is suggested that you verify that the input is valid. c. It may be helpful to use functions (although this is not required, it will greatly improve readability) Please enter what you would like to do: a. Convert a number to decimal (enter a value \& given base) b. Convert a decimal to another base (enter a decimal value and a base) c. Convert a number from base1 to base2 (enter number, base1 and base2) q. Quit Enter your input value: FE Enter given base value: 16 The value FE in base 16 is 254 in decimal. please enter what you would like to do: a. Convert a number to decimal (enter a value \& given base) b. Convert a decimal to another base (enter a decimal value and a base) c. Convert a number from base1 to base2 (enter number, base1 and base2) q. Quit Enter your decimal value: 254 Enter resulting base value: 2 The decimal value 254 is 1111110 in base 2 Please enter what you would like to do: a. Convert a number to decimal (enter a value \& given base) b. Convert a decimal to another base (enter a decimal value and a base) c. Convert a number from base1 to base2 (enter number, base1 and base2) q. Quit Enter your input value: 11111100 Enter original base: 2 Enter output base: 16 The value 11111100 in base 2 is 252 in decimal. The value 11111100 is FC in base 16=FC

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

Students also viewed these Databases questions