Thursday, July 30, 2009

C++ question?

I'm trying to create a class that acts basically just like an int, but has a much larger range. My plan is to take numbers in as strings to increase the range...for example, if the class is known as "LargeInt":





LargeInt x = 523473;





The numbers 523473 will be taken in as a string and stored as an array of chars as the numerical values. This way, I can manipulate the numbers by overloading the arithmetic operators, so that I can add, subtract, multiply and divide LargeInts.





I pretty much have an idea of how to overload the operators, however, I'm confused as to how to take the numbers in as strings. Any advice?

C++ question?
dude take just take the number in as a string





string s1 = "523473";








Then you have to use the string functions like


strlen(s1)





Then you'll have to do some kind of a for loop to add the two numbers.
Reply:Overload the default constructor to support a string parameter. And overload the assignment operator.





Edit: And take a look at http://gmplib.org/
Reply:Hi, there's no need to create that class from scratch. Try using the standard template library. The Standard template library of C++ does all these things for you so u don't have to reinvent the wheel, the downside? templates are quite hard to comprehend at 1st, but you'll get the hang of it. After some time, you'll be doing smart pointers, and so on...





By the way, what compiler are you using (VC++, Openwatcom, MingW, etc)?

local florist

No comments:

Post a Comment