Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

What are the determinants of cash cycle ? Explain

Answered: 1 week ago