Jump to content

Program request....


Recommended Posts

Manipulation of large numbers can be a problem when the range of integers and floats is severely restricted because of the machine or the language used. Many languages allow a long integer type and a double float type, but even these larger ranges are too restrictive for many applications requiring more digits of precision. One way of dealing with this problem is to represent the numbers in another way, for instance as arrays with one or more digits per array element.

You are to create a class which will allow clients to manipulate positive integer values of up to 25 digits as arrays or strings (no input or computed value will be more than 25 digits). Define the size as a named constant, so that it could be increased as necessary without having to rewrite any executable statements (only the constant definition would be changed). The class should contain private variables to represent a single big integer as an array or string. You should provide functions to:

1) input a value for a big integer from keyboard or text file

2) output a big integer

3) add two big integers, returning a big integer sum

4) subtract two big integers, returning a big integer difference

Program requirements:

1) The class defines and represents only one big int so that a client can declare as many big

ints as the application requires and operate them in any combination.

2) Maximum size of the number should be defined and reference as a named constant.

3) Each big integer must be represented as an array or string.

4) A default constructor should assign a value of 0 to a big integer.

5) At least one of the I/O functions must be an overloaded operator function.

6) At least one of the arithmetic functions must be an overloaded operator function.

7) The client program should call a class function to read each big int. It should read and

evaluate the operator and call a class function to calculate the big int sum or difference. It

then calls a class function to output the result of the addition or subtraction. The class

provides the tools but does not direct the action. The client declares and opens the file,

passing the file to the class function for input.

Ive been trying to do this for a few days now with no luck. I need it done in C++, If anyone can help me I would much appreicate it!

Link to comment
Share on other sites


i gave you a pointer. within 2 pages you should have something that will help from google. I said i wont write it for you but gave you a great hint (the google page that is returned when you search for "mulitprecision math" gives lots of options for what you want).

P.S. if you know how to create a stack or a linked list this is even simpler. Create a class that defines a dynamic array. in the class have an integer that tell you how many digits are defined (allocated memory for) and one that tells you how many are used. Then fill the memory with the numbers in reverse order e.g [0] has the least significant byte

so the number 65537 is 11, 65536 is 01 as you move to the right you are moving through the boundries of the integers (e.g int is 16 bits, bit 17 is the lsb of the next byte so you get 11111111 00000000, then next you get 00000000 00000001 {array values [0] and [1]})

you have also been told that no input will be longer than 25 characters so you could read it as a string and convert to an array of 25 characters and work on it then :)

Edited by phkninja
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...