![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Define a class Biginteger that stores arbitrary large integersHi guys ... I have problems making one task ... pls somebody help with it cause i have to present it in 2 days and i cant make it
Here is the task : Define a class Biginteger that stores arbitrary large integers, by keeping their digits in a dynamically allocated array of integers. Supply the "big three" memory management functions. Use this class to demonstrate (a) the difference between initialization Biginteger s; Biginteger t = s; and assignment Biginteger s; Biginteger t; s = t; (b) the fact that all constructed objects are automatically destroyed (c) the fact that the copy constructor is invoked if an object is passed by value to a function (d) the fact that the copy constructor is not invoked when a parameter is passed by reference (e) the fact that the copy constructor is used to copy a return value to the caller. Supply a constructor Biginteger(string) that reads a sequence of digits from a string. Overload + and - operators to add and subtract the digit sequences. Overload the stream operators << and >>. Demonstrate all these functions and operators. it is insane thank you very much ! |
|||
|
#2
|
|||
|
|||
Re: I am stuck ... can someone assist me pls !Quote:
Fundamentally, you are wanting abstract arithmetic of arbitrary precision. So, the first thing you need to do is figure out how to detect overflow & deal with it accordingly. Once you have resolved this in your head, the rest will being falling into place. If you are under a stringent deadline, you should begin now as there are several parts to the implementation. |
|
#3
|
|||
|
|||
Re: Define a class Biginteger that stores arbitrary large integersIt's really best for YOU to try creating the class. Then, when you get stuck, post what you have so that we can help. Maybe start with something like this:
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Define a class Biginteger that stores arbitrary large integersAs you all know, unsigned int has range 0 to 65536 and this use 4 bytes in most platforms.
Try to relate this with length memory you have allocated. I also want to know how. This overflow problem will get solved once you using character or string. The copy constructor should return reference and not by value. Overload + and - as below : Code:
If these two function overload inside a class, then take one argument, else outside of a class then take two arguments. |
|
#5
|
|||
|
|||
Re: Define a class Biginteger that stores arbitrary large integersQuote:
Anyway, I guess you can't make that kind of assumption, if you don't know the platform. If you only need to implements addition and subtract operation, I'd follow fakepoo tip, and operate digit by digit. For example, as Peter suggest: CPP / C++ / C Code:
Regards. __________________
Please, correct me if I'm wrong, and sorry for my english ;) |
|
#6
|
|||
|
|||
Re: Define a class Biginteger that stores arbitrary large integersFound a small problem in your function. Here is probably what you want:
CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: Define a class Biginteger that stores arbitrary large integersUppss!!! Thanks
__________________
Please, correct me if I'm wrong, and sorry for my english ;) |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I'm stuck in a problem.... plzzzzzz help | sool87 | C++ Forum | 12 | 09-Nov-2007 06:40 |
| Stuck on Codes | joesmithf1 | C++ Forum | 2 | 10-Jun-2007 22:11 |
| Stuck error C2275 | chrisn42 | C++ Forum | 1 | 07-Apr-2007 21:20 |
| Stuck on C Programming | PEANUTS | C Programming Language | 2 | 17-Jan-2007 14:58 |
| Stuck | daking_09 | C++ Forum | 4 | 03-Apr-2006 10:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The