CLASS TO CONVERT FROM ANY NUMBER BASE TO ANOTHER

A: CREATE A CLASS TO CONVERT FROM ANY NUMBER BASE TO ANOTHER (FOR Example: from DECIMAL to BINARY)

CLASS SHOULD

- have only one private long integer variable

- contain overloaded constructors as follows

* className() (DEFAULT CONSTRUCTOR - creates an object with default integer value of zero)

* className( int x ) (CONSTRUCTOR - creates an object with default integer value of x in decimal base)

* className( char x, char c) (CONSTRUCTOR - creates object with integer convert to decimal from base c)




- have a public member function get_value() such that

* get_value() - returns the decimal value of integer variable

* get_value( char c ) - returns the base c value of decimal integer variable

* get_value( int x, int y) - returns the list of base values between the base x and base y for the integer variable

- x and y must be greater than zero AND y must be greater or equal to x

- create the conversion functions as you see fit (public or private - utility function)
Last edited on
Something you don't understand about your assignment?
how to create class with this information?
One piece of advice I can give. If converting from larger base to smaller base, you can divide the number by the smaller base and read the remainders in reverse order:
14 base 10
convert base 2

14%2=0 (then divide by base)
7%2=1
3%2=1
1%2=1

read in reverse: 1110


When converting from smaller to larger base:
1110 base 2
convert base 10

1*(2^3)+1*(2^2)+1*(2^1)+0*(2^0)
8+4+2
14


You might find it easier to first convert to base 10, than dividing in other bases.
i know all these even i have program without using class all i don't how to do this program with the class.. :(
Last edited on
Topic archived. No new replies allowed.