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)

B:

OVERLOAD ALL THE COMPARISON OPERATORS (==, !=, <, <=, >=, >)

- to be able to compare one or more of the base objects against others

OVERLOAD THE PREFIX AND POSTFIX INCREMENT AND DECREMENT OPERATORS (++, --)

- to increment the integer decimal value of the object



C. CREATE ERROR HANDLING (I.E. EXCEPTIONS HANDLING CLASS)

CLASS SHOULD BE USED TO STORE / SELECT ERROR INFORMATION TO DISPLAY ON EXCEPTION





d: CREATE A PROGRAM TO TEST YOUR CLASS AND FUNCTIONS

- Program should have menu to direct users on options

- Program must allow user to enter values for information to convert

* throw/catch exceptions on invalid characters input

- Program must allow user to continue to use program until they choose to exit



Allow user to create linked lists (linked class nodes) of converted values and update the list information on screen as the user continues to use the program.



DESTROY dynamic variables on exit (i.e. release all dynamic memory back to freestore) – failure to do so will cost you 10% points.
Well, you a really good specification there - what is the problem?

Show us your code - we will not do your homework.
I know but i need some help to start this program. I am confuse about where to start because i not really good with creating class.
I have created program without creating a class and here it is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include <iostream>
#include <conio.h>
#include <cmath>
using namespace std;

void convert (char value[100], int base);
int charVal(char ch, int base);

int main()
{
	char value_Choose[100]; //the value user want to convert from
	int base;
	cout<<"\nHere is the program which shows value from 2-36 base:"
		<<"\nPlase enter positive value: ";
	cin.getline(value_Choose,100);
	cout << "Enter base: ";
	cin >> base;
	
	convert (value_Choose,base);
		
	_getch ();
	return 0;
}

// now to show output.....
void convert (char value[100], int base)
{
	int i;
	int z=0;
	int total=0;
	double dbase = base;
	//cout << "DEBUG: value[0]= " << value[0] << "  charVal=" << charVal(value[0]) << endl;
	//cout << charVal(value[0])* base + charVal(value[1]) << endl;

	for (i=strlen(value)-1; i>=0; i--)
	{
		total = total + pow(dbase,z) * charVal(value[i], base);
		z++;
	}
	cout << total;
}
int charVal(char ch, int base)
{
	int returnVal;
	if (ch >='0' && ch <='9')
		returnVal= ch - '0';
	else
	{
		ch = toupper(ch);
		if (ch >='A' && ch <='Z')
			returnVal= ch - 'A'+10;
		else
		{
			cout << "Error: Must be 0-9 or a-z or A-Z)";
			returnVal= -1;
		}
	}
	if (returnVal > base-1)
		{
		cout << "Error: Digit must be less than " << base << endl;
		returnVal= -1;
	}
	return returnVal;
}


Is this good?
1
2
3
4
5
6
class className {
private:
    // member
public:
    // methods
};
but how i can use this in my program , define with class?
Last edited on
Hahahah, Okechukwu's class? Aaanyway, I'm also trying to figure out some good methods of conversion.

Found this: http://www.searchmarked.com/math/how-to-convert-from-base-10-decimal-to-any-other-base.php

But not much else so far. I'm kind of understanding how to convert between bases between 2-10, but anything above that is just confusing to even imagine, mostly from a symbolic point of view. >.>
Last edited on
so did you do this program i am having hard time to understand this program.
@DatapawWolf
Do you go to ECC?
ya i in ECC in CIS 223 class and this is my final project and i haven't done it, having hard time to understand this time . i don't why but this semester i had to much to do and haven't got proper time to understand second level of programing
Last edited on
The easiest way to convert bases is to use modulus and division.
Topic archived. No new replies allowed.