Huge Integer problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Lopez
    New Member
    • Feb 2012
    • 1

    #1

    Huge Integer problem

    I have to do the huge integer problem,
    Create a class HugeInteger which use 40-element array
    of digits to store integers as larg as 40 digits each.
    Provide member functions input, output, add, subtract ?
    The hugeinteger has a int*. So the array in the
    hugeinteger has to be dynamically allocated in the
    input function (which reads from a text file).

    ok so one of the hugeintegers has to be a pointer
    to a hugeinteger. The hugeinteger has to be allocated
    IN input function.

    I have NO CLUE how to use the hugeInteger pointer
    with the input function. Like how do i get it to
    allocate in the input function?
    since a regular Hugeinteger and a pointer to a hugeinteger
    will be using the same member function. Please please someone help me i've been working on this code for about 12 hours straight....
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Do this problem in pieces.

    First, write a main() with an array of 4 ints called H1, like for HugeInteger #1.
    Second, add a second array of 4 int called H2
    Third, add a third array of 4 int called Sum.
    Fourth, hard code some values into H1 and H2. Initialize Sum to zeros.
    Fifth, write a loop to add H1 to H2 and put the result in Sum. Don't forget that you will need an int for carry.
    Sixth, Get this working.
    Seventh, move the loop to function and pass in H1, H2 and Sum.
    Eighth, get this working.
    Ninth, create a struct and put H1 in the struct. Change the function to take a struct* argument, H2 and Sum.
    Tenth, get this working.
    Eleventh, move the function inside the struct. Remove the struct* argument.
    Twelfth, verify everything is still working.
    Thirteenth, make the H1 private and the member function public. Now chnage the word struct to class.
    Fourteenth, verify everything still works.
    Fifteenth, now change the arrays to 40 ints.
    Sixteenth, verify the code still works.

    From here you can add functionality in small increments. Follow the rule of do a little, debug then do a little more. Always be sure your code works before adding new features. This way your code is based on a previous version of itself that worked.

    Let me know what happened.

    Comment

    Working...