Due by 11:59.59pm Sunday November 13 2016
Due by 11:59.59pm Tuesday, November 15, 2016
You may work with a partner on this assignment. Contact me and I will set up a Github repository for you to use on this assignment.
For this assignment, I want you to create a program called additup that will add up a sequence of positive integers. One catch, the integers can be any number of digits long.
Your program should read in a sequence of integers, one per line using the following algorithm.
% ./additup 1234 Total: 1234 9876 Total: 11110 1 bobo Total: 11111 1234567890987654321 Total: 1234567890987665432 ^D
There is also a sample binary (Linux) for you to play with in ~hoyle/pub/cs241/hw07/
In order to support arbitrarily long integers, you'll need to represent your data in a linked list format. I'll leave it up to you to decide if you want singly or doubly linked lists, but the nodes should look like one of the following:
Singly Linked struct BigInt { int digit; struct BigInt *next; }; Doubly Linked struct BigInt { int digit; struct BigInt *next, *prev; };
Some things to keep in mind:
Check to see if malloc() fails. If it does, print a message and immediately exit with a non-zero value. (e.g., EXIT_FAILURE from exit(3) or something from the sysexits(3) group if you'd prefer)
As there is very little output specified, I'm going to require that you match the sample output exactly.
To keep you thinking about your memory management, I want you to clean up all memory that you dynamically allocated before the end of the program. That means that you should be able to run under valgrind with no memory leaks reported.
I've provided a program called gen_nums that will generate random positive integer sequences for you. It is located in ~kuperman/pub/cs241/hw07/ as well. It requires 2 parameters with an optional third. They are:
I'm using the C pseudo-random number generator so that you should get identical sequences of numbers for the same input parameters. You can vary the seed to get different sequences if desired.
% ./gen_nums 10 3 1 6753 629127 9 % ./gen_nums 10 4 1 6753 629127 9 6062 % ./gen_nums 10 4 2 9 518475729 3794370229 710063
Create a file called README that contains
Now you should make clean to get rid of your executables and handin your folder containing your source files, Makefile, and README.
% cd ~/cs241 % handin -c 241 -a 7 hw7 % lshand
Here is what I am looking for in this assignment:
valgrind: [/5] README & Makefile [/5] additup: [/40] TOTAL: [/50]