#ifndef HUGEINT_H
#define HUGEINT_H
#include <iostream>
using namespace std;
class HugeInt {
friend ostream &operator<<(ostream &,const HugeInt);
public:
HugeInt(long = 0); //conversion default constructor
HugeInt( const char *); // constructor
HugeInt operator+(const HugeInt &); //add another HugeInt
HugeInt operator+(int); //add an int
HugeInt operator+(const char *); //add an int in a char *
HugeInt operator*(const HugeInt &); //add another HugeInt
HugeInt operator*(int); //add an int
HugeInt operator*(const char *); //add an int in a char *
private:
short integer[30];
};
#endif
Where you can use strings or int to initialize it. The number would be stored in an array, so if the number 2300 was stored in the integer array it would look like [0][0][0][0]...[0][2][3][0][0]. How would I go about multiplying 2 arrays and dealing with the carry overs? I'm going to overload the * operator so that I may be able to multiply two HugeInt variables. No need for a great solution, just some guidance. Thanks.
Operator overloading for user defined class.
Page 1 of 11 Replies - 177 Views - Last Post: 05 October 2012 - 09:49 PM
#1
Operator overloading for user defined class.
Posted 05 October 2012 - 09:36 PM
So I wanted to make a class HugeInt:
Replies To: Operator overloading for user defined class.
#2
Re: Operator overloading for user defined class.
Posted 05 October 2012 - 09:49 PM
What have you researched? What have you tried? Do you remember how you did multiplication in grade school? The same algorithm will work equally as well since you so there was no need for a great solution.
For the overloads that take strings, convert the strings to HugeInts then just call your HugeInt operator. For the overloads that take ints, covert the ints HugeInts as well.
For the overloads that take strings, convert the strings to HugeInts then just call your HugeInt operator. For the overloads that take ints, covert the ints HugeInts as well.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|