BigInt

I need help with my project for my c++ class. I am a little confused on how to get started. I am making a class called "bigint" and i have to have a global constant "size". How do I make that global "size" the size of bigint? If "size" is an array and "bigint" is an object how does that work? Heres the instructions for the program..

Requirements:
-You must use the class construct to implement your ADT.
-The ADT bigint need only work for positive numbers.
-Use a global constant value for the maximum size of the bigint that is, a constant sized array.

Implementation:
-The size of the bigint must be specified by a global constant
-A method (constructor) to initialize a bigint to zero.
-A method (constructor) to initialize a bigint to an int value you provide [0, maxint]. Example: bigint(128).
-A method (constructor) to initialize a bigint to a char[] you provide. You can assume what is provided is a valid bigint. Example: bigint("299793").
-A method to write a bigint that prints at most 60 digits per line.
-A method to compare if two bigints are equal. It should return a bool - true if equal and false otherwise.
closed account (o1vk4iN6)
I wouldn't put the size into the global namespace but rather as a static variable in the class. Note it has to be const otherwise it isn't know at compile time.
1
2
3
4
5
6
7
8
9
10
11
12
13

class BigInt
{
public:

    static const unsigned size = 32;

private:

    blue32huthut array[size];

};
Last edited on
Okay well say I do that. How do I initialize BigInt to 0?

If i do something like this it says "expression must have a const value".

1
2
3
4
bigint::bigint(){
	for(int i=0; i <= MAXINT; i++)
		bigint[i] = 0;
}
And this is my class definition:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef BIGINT_H
#define BIGINT_H
class bigint{
	public:
		bigint();
		bigint(int);
		bigint(char);
		void output(bigint);
		bool compare(bigint, bigint);
                const int MAXINT[500];

	private:
		bigint[MAXINT];
                
};

#endif 
Last edited on
closed account (o1vk4iN6)
const int MAXINT[500];

You're creating a const array with a size of 500...
You can't have a member of a class that has the same name of it, unless it's a constructor.
I like how this question is solved here but unresolved in the duplicate.
Topic archived. No new replies allowed.