Help with my code

BigInteger.h
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
#ifndef BIG_INTEGER_H
#define BIG_INTEGER_H

#include "BigIntegerException.h"

/**
Recall from integer type that covers largest range is 
long long, which is from –9,223,372,036,854,775,808 to 
9,223,372,036,854,775,807. You don't want these limitation
on how large number you can use.

Your task is to design this BigInteger class and implement
its operators to overcome this limitation of long long type.
Here are your tasks:
1. constructors:
  a. default constructor: should store number 0
  b. constructor with one string argument: store value
and throw NumberFormatException if argument is 
a empty string or string with non-numeric characters
  c. copy construtor: to clone a copy of an object instead
of just a pointer (see shadow copy behavior)

2. destructor: as a rule of thumb, when you allocate memory, 
clean up memory.

3. toString: return the number in a string format

4. operator+: to add two BigInteger objects

5. operator*: to multiply two BigInteger objects

With all above requirements, design an internal/private data 
members that are approriate to all above functions. See the
test cases (BigIntegerTest) to see its expected usage.
*/
class BigInteger {
private:
	string *ptr;
	string *temp;

public:
	// default constructor
	BigInteger();

	// constructor with one string argument
	BigInteger(string value) throw (NumberFormatException);

	// copy constructor
	BigInteger(const BigInteger& bigInt);

	// assignment operator
	BigInteger& operator=(const BigInteger& bigInt);

	// destructor
	~BigInteger();

	// print the number without leading zero
	std::string toString();

	// addition operator
	friend BigInteger operator+(const BigInteger& leftNum, const BigInteger& rightNum);

	// multiplication operator
	friend BigInteger operator*(const BigInteger& leftNum, const BigInteger& rightNum);
};

#endif 


BigInteger.cpp
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
#include "BigInteger.h"
#include <string>
#include <iostream>
using namespace std;
// view the header files and implement all the functions

BigInteger::BigInteger(){
	for (int i = 0; i < 500; i++)
	{
		ptr[i] = "0";
		temp[i] = "0";
	}
}

BigInteger::BigInteger(string value) throw (NumberFormatException)
{
	for (int k = 0; k < value.size(); k++)
	{
		ptr[k] = value.at(k);
	}
}

BigInteger::BigInteger(const BigInteger& bigInt){
	ptr = bigInt.ptr;
	temp = bigInt.temp;
}

BigInteger& BigInteger::operator=(const BigInteger& bigInt){
	for (int i = 0; i < 500; i++)
	{
		bigInt.ptr[i] = ptr[i];
	}
	return *this;
};

BigInteger::~BigInteger(){
	delete ptr;
	delete temp;
}

string BigInteger::toString(){

	return 0;
}

BigInteger operator+(const BigInteger& leftNum, const BigInteger& rightNum){

	return BigInteger(*leftNum.ptr + *rightNum.ptr);
}

BigInteger operator*(const BigInteger& leftNum, const BigInteger& rightNum){
	return 0;
}


I need two big numbers to be added and multiplied. I'm trying to convert them to a string so I can do this easier but I'm having problems doing the constructors right now. Can anyone comment on what I have so far? Thanks.
It would be far easier to use arrays of integers. That way, multiplying and adding isn't nearly as much of a challenge.
Registered users can post here. Sign in or register to post.