C++ recursive base-13 conversion using a class method: determine the output when the initial value is 130.\n\n#include <iostream.h>\n\nclass Number\n{\n int Num;\npublic:\n Number(int x = 0) { Num = x; }\n void Display() { cout << Num; }\n void Modify();\n};\n\nvoid Number::Modify()\n{\n int Dec;\n Dec = Num % 13;\n Num = Num / 13;\n\n if (Num > 0) Modify();\n if (Dec == 10) cout << "A";\n else if (Dec == 11) cout << "B";\n else if (Dec == 12) cout << "C";\n else if (Dec == 13) cout << "D"; // unreachable for base-13 remainders\n else cout << Dec;\n}\n\nint main()\n{\n Number objNum(130);\n objNum.Modify();\n return 0;\n}\n

Difficulty: Medium

Correct Answer: A0

Explanation:


Introduction / Context:
This program prints a number in base 13 using digits 0–9 and letters A, B, C for 10, 11, 12 respectively. The method Modify transforms Num by repeatedly dividing by 13, recursing for higher places, and then printing the current remainder as a base-13 digit.



Given Data / Assumptions:

  • Initial Num = 130.
  • Remainder mapping: 10 → A, 11 → B, 12 → C.
  • Recursion prints higher-order digits first (after dividing), then the current remainder.


Concept / Approach:
Converting to base 13: at each step compute Dec = Num % 13 and Num = Num / 13. Recurse if Num > 0 to print the more significant digits first; then print the symbol for Dec. This is the standard recursive number-to-base printing pattern.



Step-by-Step Solution:

Start: Num = 130 → Dec = 130 % 13 = 0; Num = 130 / 13 = 10; recurse.Second frame: Num = 10 → Dec = 10 % 13 = 10; Num = 10 / 13 = 0; no recursion.Map Dec = 10 → print "A".Return to first frame → print Dec = 0 as "0".Concatenate outputs → "A0".


Verification / Alternative check:
130 in base 13 equals 10*13 + 0, so the digits are 10 and 0 → A0. Printing order matches the recursion.



Why Other Options Are Wrong:

  • 130: That would be base 10, not base 13 representation.
  • B0 or 90: Incorrect remainder mapping or arithmetic.
  • None of the above: A0 is exactly produced.


Common Pitfalls:
Expecting 13 to produce a remainder of 13 (remainders are 0–12), or forgetting that the routine prints higher-order digits first by recursing before output.



Final Answer:
A0

More Questions from Functions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion