Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ help Examples: Base 10 value: 14 --> Base 2 value: 1110 Base 10 value: 8 --> Base 5 value: 13 Base 10 value: 19

c++ help

Examples:

Base 10 value: 14 --> Base 2 value: 1110

Base 10 value: 8 --> Base 5 value: 13

Base 10 value: 19 --> Base 13 value: 16

Base 10 value: 29 --> Base 16 value: 1D

Your program must:

  1. prompt the user to enter the decimal value that they are interested in converting, along with the base that they would like to convert it to via standard input;

  2. ensure that the base-b specified by the user is such that 2 b 16; otherwise, prompt the user for the base;

  3. use a single block of code to calculate the equivalent value in base-b; that is, you shouldnt have blocks for the different bases, but a single block that calculates any possible value in base-b from that base-10 value provided by the user;

    1. My slides on data representation have an algorithm for doing this on slide 59 (you need worry only about an integral part): https://drive.google.com/file/d/0B_ouNNuWgNZCWWJjNGpPdjlITTg/view

  4. use 0-9 to represent the digits 0-9; use A to represent 10, B for 11, C for 12, D for 13, E for 14, and F for 15 (remember, a base-b positional system has digits 0-[b-1]);

  5. output the converted value, along with the minimum number of that base-b digits needed to represent it:

    1. For instance, the binary value 1011 would require four bits,

    2. and hexadecimal value F4E2 would require four digits as well.

  1. Conform to the following i/o format (user input in green; everything else is output):

    1. Example 1: Enter a decimal value : 10

Enter a base (2-16) : 16

Base-10 value : 10

Base-16 value : A

Digits required : 1

  1. Example 2: Enter a decimal value : 32

Enter a base (2-16) : 2

Base-10 value : 32

Base-2 value : 100000

Digits required : 6

  1. Example 3 (illustrates the condition where invalid base provided; prompt until base between 1-16 entered):

Enter a decimal value : 17

Enter a base (2-16) : 18

Enter a base (2-16) : 16

Base-10 value : 17

Base-16 value : 11

Digits required : 2

Labwork

  1. Working together, create a flowchart that details the proposed design of your application. This should be completed by walking through the problem in plain English with your team. How would you solve this problem by hand? How could translate this into an algorithm (step-of-instructions to accomplish some task)?

  2. Download the skeleton code from https://drive.google.com/open?id=1CAGfeGv9m4LN3S5rGjJ0qDPPOwE141cK

    1. I provide you with a function called digit_to_char(); youll need to use this function. If you find yourself needing to convert an int to a char, use this function! Do not attempt to convert an int to a char by some means that you find on google. Heres how to use my function:

      1. To convert some number, say 1, to 1, you can write char c = digit_to_char(1)

      2. Lets say you have the integer value stored in int i = 7; to convert the value stored in some variable to a character, you can write char c = digit_to_char(i)

    2. To think about how can we store the result of the calculation? Could we use a vector? What about those As, Bs, etc. Perhaps we could use my function and convert the ints into chars and store a collection of chars? How can we store a collection of characters? Could we use a vector? Wait, how? For what? Hmm things to chat with your group about.

  1. Implement the program in C++. Make sure that you compile frequently and test diligently. Dont do this all at once!

    1. Ensure that the source file containing your solution for this labwork is named decimalToBaseB2.cpp.

    2. First get things working for base-2

    3. Then get things working for bases 1-9

    4. Finally, figure out how to implement this procedure for bases 1-16

  2. Given function:char digit_to_char(int i) { stringstream ss; ss << i; char c; ss >> c; return c; }

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 Systems For Advanced Applications 9th International Conference Dasfaa 2004 Jeju Island Korea March 2004 Proceedings Lncs 2973

Authors: YoonJoon Lee ,Jianzhong Li ,Kyu-Young Whang

2004th Edition

3540210474, 978-3540210474

More Books

Students also viewed these Databases questions

Question

What lessons in intervention design, does this case represent?

Answered: 1 week ago