Question: Coding: I will give you my code and the things I am missing and the picture of the assignment and could you help finish it
Coding:
I will give you my code and the things I am missing and the picture of the assignment and could you help finish it
Code rubric:
Program supports the three numbering
systems and gives the correct answer,
including fractional parts
Program gives instructions to the user
to input the following parameters as
per the sample run that was provided
The number to convert
The source base ie the base to
convert From
The target base ie the base to
convert to
Program contains the following
functions:
bool
ValidateInputinputnumber
int
convertnumberinputnumber,
sourcebase, targetbase
Function bool ValidateInput
inputnumber checks if the input
consists of legal characters. For
example, Binary numbers can only be
or
Program handles multiple conversions
in one session ie allowing the user
to continue or quit and Code readability and comments
My code:
#include
#include
#include
Function to validate input
bool ValidateInputconst std::string& numinput, int inputbase
for char currentdigit : numinput
if inputbase
if isdigitcurrentdigit
return false; Decimal numbers can only have digits
else if inputbase
if isxdigitcurrentdigit
return false; Hexadecimal numbers can have digits and AF
else if inputbase
if currentdigit currentdigit
return false; Octal numbers can only have digits
else if inputbase
if currentdigit && currentdigit
return false; Binary numbers can only have digits or
return true;
Function to convert the number
int ConvertNumberconst std::string& numinput, int inputbase, int outputbase
int conversionresult ;
if inputbase
conversionresult std::stoinuminput;
else
int exponent ;
for int i numinput.size; i ; i
char currentdigit numinputi;
int digitvalue inputbase std::stoistd::string currentdigit nullptr, : currentdigit ;
conversionresult digitvalue std::powinputbase, exponent;
exponent;
Convert result to the target base
std::string finalresult ;
while conversionresult
int digitremainder conversionresult outputbase;
char currentdigit digitremainder digitremainder : A digitremainder ;
finalresult currentdigit finalresult;
conversionresult outputbase;
std::cout "The result of converting the number numinput from base inputbase
to base outputbase is:
finalresult std::endl;
return ;
int main
std::cout "Welcome to the Numbering System Calculator!" std::endl;
std::cout std::endl;
char userchoice;
do
std::string numinput;
int inputbase, outputbase;
std::cout "Please enter the following inputs:" std::endl;
std::cout "The number to convert:
;
std::cin numinput;
std::cout "The source base ie the base to convert From:
;
std::cin inputbase;
std::cout "The target base ie the base to convert to:
;
std::cin outputbase;
if ValidateInputnuminput, inputbase
std::cout "Invalid input for the given source base." std::endl;
else
ConvertNumbernuminput, inputbase, outputbase;
std::cout
Do you wish to continue with other numbers?" std::endl;
std::cout "Enter Y to continue
Enter N to continue
;
std::cin userchoice;
std::cout std::endl;
while userchoice Y userchoice y;
std::cout "Quitting calculator. Thank you!" std::endl;
return ;
Things I am missing: In the pictures
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
