CS246 Homework 3: pointers and arrays
Due: Tuesday, Feb 23, 2016 - 11:59 pm
What to hand in:
- Include a README file: if your program behaves in anyway differently from specified, or there are bugs you'd like to point my attention to, this is the place for it.
- Include a Makefile to make your program
- Submit to electronic mercurial repository called hw3 in /rd/cs246s2016/<username>/ as usual.
Big int [100pts]
In this program we will simulate very large integers with arrays in the following way: digits are stored into the array starting with the least significant. That is, given an integer 123, it is stored with 3 at index 0, 2 and index 1 and 1 at index 2.
Write the following functions:
-
int bigplus(const int *x, const int sizex, int *y, int sizey, int *res)
, which takes two arrays x and y and their respective sizes, performs addition and stores the result into the array res. Return the number of digits of the resulting sum (i.e. number of digits stored into res).
-
int bigmult(const int *x, int sizex, const int *y, int sizey, int *res)
, which takes two arrays x and y and their respective sizes, performs multiplication and stores the result into the array res. Return the number of digits of the resulting product (i.e. nubmer of digits stored into res).
Copy the framework code /rd/cs246s2016/shared/hw3/bigint_frame.cpp and use it as a starting point. A main complete with test cases as well as a print function have been provided for you. Additional requirements:
- Use pointer notation to address the arrays whenever possible (i.e. no square brackets allowed).
Your functions should behave rationally with different input given in main, i.e. your functions might be called with arrays with different values and sizes than those given.
- Do not modify main, besides uncommenting. You may modify values and sizes of the input arrays temporarily for testing purposes.
- Try to create a solution using as little extra memory as possible.
- Grade school addition, and grade school multiplication is a good place to start when thinking about your algorithms:
32 999
+88 ×23
--- ---