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 (i.e., the base to
convert From)
The target base (i.e., the base to
convert to)
Program contains the following
functions:
1. bool
ValidateInput(input_number)
2. int
convert_number(input_number,
source_base, target_base)
Function bool ValidateInput
(input_number) checks if the input
consists of legal characters. For
example, Binary numbers can only be
0 or 1
Program handles multiple conversions
in one session (i.e., allowing the user
to continue or quit) and Code readability and comments
My code:
#include
#include
#include
// Function to validate input
bool ValidateInput(const std::string& num_input, int input_base){
for (char current_digit : num_input){
if (input_base ==10){
if (!isdigit(current_digit)){
return false; // Decimal numbers can only have digits 0-9
}
}
else if (input_base ==16){
if (!isxdigit(current_digit)){
return false; // Hexadecimal numbers can have digits 0-9 and A-F
}
}
else if (input_base ==8){
if (current_digit '0'|| current_digit >'7'){
return false; // Octal numbers can only have digits 0-7
}
}
else if (input_base ==2){
if (current_digit !='0' && current_digit !='1'){
return false; // Binary numbers can only have digits 0 or 1
}
}
}
return true;
}
// Function to convert the number
int ConvertNumber(const std::string& num_input, int input_base, int output_base){
int conversion_result =0;
if (input_base ==10){
conversion_result = std::stoi(num_input);
}
else {
int exponent =0;
for (int i = num_input.size()-1; i >=0; i--){
char current_digit = num_input[i];
int digit_value =(input_base ==16)? std::stoi(std::string(1, current_digit), nullptr, 16) : (current_digit -'0');
conversion_result += digit_value * std::pow(input_base, exponent);
exponent++;
}
}
// Convert result to the target base
std::string final_result ="";
while (conversion_result >0){
int digit_remainder = conversion_result % output_base;
char current_digit =(digit_remainder 10)?(digit_remainder +'0') : ('A'+ digit_remainder -10);
final_result = current_digit + final_result;
conversion_result /= output_base;
}
std::cout "The result of converting the number " num_input " from base " input_base
" to base " output_base " is:
>>" final_result std::endl;
return 0;
}
int main(){
std::cout "Welcome to the Numbering System Calculator!" std::endl;
std::cout "-----------------------------------------------------" std::endl;
char user_choice;
do {
std::string num_input;
int input_base, output_base;
std::cout "Please enter the following inputs:" std::endl;
std::cout "The number to convert:
>>";
std::cin >> num_input;
std::cout "The source base (i.e., the base to convert From):
>>";
std::cin >> input_base;
std::cout "The target base (i.e., the base to convert to):
>>";
std::cin >> output_base;
if (!ValidateInput(num_input, input_base)){
std::cout "Invalid input for the given source base." std::endl;
}
else {
ConvertNumber(num_input, input_base, output_base);
}
std::cout "
Do you wish to continue with other numbers?" std::endl;
std::cout "Enter (Y) to continue
Enter (N) to continue
>>";
std::cin >> user_choice;
std::cout std::endl;
} while (user_choice =='Y'|| user_choice =='y');
std::cout "Quitting calculator. Thank you!" std::endl;
return 0;
}
Things I am missing: In the pictures
Coding: I will give you my code and the things I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!