Question: Code in C++ 1) Write a recursive function that converts an int to a hex string. To convert an int to a hex, first mod

Code in C++

1) Write a recursive function that converts an int to a hex string. To convert an int to a hex, first mod the number by 16. Take the remainder and convert it to a hex equivalent (so 10=A, 11=B, 12=C, etc.) Then divide the int by 16 and repeat the process with the result.

So, for example, to convert 590 to hex,

590 %16 = 14 (so E). 590/16 = 36

2) Create a class declaration for a hex number. The class should consist of 2 private fields an integer (for the integer version of the number) and a string (for the hex version of the number). The class declaration should also have (public methods and constructors): a constructor that takes as input an int, and a separate constructor that takes as input a string. It should also have 2 methods, one for converting an int to its corresponding hex number (in the form of a string) and a method that converts the string to its corresponding integer. It should also have getters and setters for the 2 fields. Now write the corresponding .cpp file. Note that the constructors and the setters should call the appropriate method so that the int field and the hex field always match up.

In your main, create at least 6 different hexnum objects. Make sure you test with different hex and integers.

36%16 = 4 36/16=2

2%16 = 2, 2/16 = 0

So the resulting hex number (in the form of a string) would be 24E

(if you need it, you can use a helper function).

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 Databases Questions!