Explore BrainMass

C++ program to convert numbers from one base to another

Write a C++ program that will convert any base 10 number v to any base b. Input two values, the first is the base 10 number and the second value is the base that the base 10 number v is to be converted to. The base can only be between 2 and 9. Invalid input should be flagged.

input 175 3
output 175 in base 10 is 20111 in base 3.

The program must use function to convert numbers from one base to another, and it should read its input from a file.

Content (to be used for testing) of attached Word file named as "Base Conversion File.dat":
175 2
175 8
175 5
3 8
98 4
98 7
98 9
256 2
256 8
256 4
111 5
999 6
100 10
60 3
100 1
512 2


Solution Preview

Please find attached 371252.cpp that has been tested working with the attached input file. Used input file and ...

Solution Summary

The program reads in pairs of (number in base 10, target base) from input file "Base Conversion File.dat" and writes the number converted to target base, in output file "output.txt". It assumes fair and valid input, that is, the input file contains even count of numbers and all are positive integers.