Design and code a number converter, that can convert a positive decimal integer number among the base-x formats, where x=2,3,, 12:
base-2: a string of 0 and 1. For example, 1010.
base-3: a string of 0, 1 and 2. For example,21210.
base-11: a string of 0, 1, , 9 and a, where the value of a is 10. For example,a783a5.
base-12: a string of 0, 1, , 9, a and b, where the value of a is 10 and the value of b is 11. For example,2a5b.
In general, in base-x, there are x digits used to represent the number. The decimal value of a number a3a2a1a0 in base-x is:
a3a2a1a0 = (a3x3)+ (a2x2)+ (a1x1)+ (a0x0)
For example,the decimal value of a base-3 number 21210 is
(234) + (133) + (232) + (131) + (030) = 162 + 27 + 18 + 3 + 0 = 210
the decimal value of a base-12 number 2a5b is
(2123) + (10122) + (5121) + (11120) = 21728 + 10144 + 512 + 11 = 4967
Requirements:
The program recieves an input number in the base-x format (x is specified by the user, the input number has at most 5 digits), then converts this number into a required format (also specified by the user).
The program can print sufficient guiding message to ask the user to input the number and choose the output format. For example:
Grading criteria:
Correctness: 3 marks.
The program can correctly print guiding messages, receive inputs, convert the number as required, print the outputs.
Robustness: 1 marks:
If the program recieves incorrect or self-contradictary inputs, the program can print proper feedback to users and let them retry.
Good programming style: 1 marks.
The source code are properly structured (e.g., using indents) and well commented.
Bonus: 1 marks.
Other (useful) features beyond the above requirements. If your program includes any bonus feature, please submit a separate WORD document to clearly introduce it and make sufficient comments in the source code to explain the corresponding codes.
Reviews
There are no reviews yet.