You are on page 1of 2

CMPS 250 Spring 2016, Assignment 1 Part II (C Version)

(Part II Due: Friday February 26, 2016)

Assignment 01 Accumulating UUIs (C Version) (Part II Due: Friday February 26, 2016)
The purpose of this assignment is to get you stated programming in C.
The term unsigned integer refers to any non-negative integer value. The term unlimited unsigned integer (UUI)
refers to the representation of unsigned integers that has no stated upper limit (or maximum value). In other
words, the number of digits in the representation of an UUI is limited only by the memory capacity of the
computer system on which it is running. Thus, extremely large magnitudes are representable.
A straightforward way to represent an UUI is as a string; that is, as a sequence of characters where each
character value is one of the numeral digits 0 9. Unlike Java, which has the standard class String, C represents
string values using arrays with the null character serving as a sentinel value to indicate the end of the string.
Thus, in C the string literal Hello is represented using an array of six elements with H in element position 0,
e in element position 1, etc. and with \0 is element position 5.
The goal of this assignment is for you to develop a C program that reads in a sequence of UUI values accumulating
and reporting their sum until the sentinel value zero is read. You are to represent each UUI as a string as
described above. In order to provide for the unlimited aspect it will be necessary for your program to make
appropriate use of the standard malloc function to dynamically allocate memory for the required arrays.
For the purposes of this assignment we may assume that the inputted UUI value will not exceed 64 digits in length.
This will allow your program to make a valid assumption about the representation of the inputted value. However,
since the number of inputted values is not predetermined, no such assumptions can be made regarding the internal
representation of the accumulating sum. You may observe however that the representation of the sum of two UUI
values can never be more than one digit longer than the larger of the two UUI values.
Example Illustration:
server1# ls
UUI.c
UUI.h
UUIAccumulator.c
server1# cc UUIAccumulator.c UUI.c -o UUIAccumulator
server1# ls
UUI.c
UUIAccumulator
boolean.h
UUI.h
UUIAccumulator.c
server1# UUIAccumulator
SENTINEL is 0
Accumulator is 0
Enter an UUI:17
Current accumulation is 17
Which is equivalent to 17
Enter an UUI:
45
Current accumulation is 62
Which is equivalent to 62
Enter an UUI:123456789
Current accumulation is 123456851
Which is equivalent to 123,456,851
Enter an UUI:100000000000000000000000000000000
Current accumulation is 100000000000000000000000123456851
Which is equivalent to 100,000,000,000,000,000,000,000,123,456,851
Enter an UUI:0000000000000000000000000000000000000000000000001
Current accumulation is 100000000000000000000000123456852
Which is equivalent to 100,000,000,000,000,000,000,000,123,456,852
Enter an UUI:0
Final accumulation is
100000000000000000000000123456852
Which is equivalent to 100,000,000,000,000,000,000,000,123,456,852
server1#

P. M. Jackowitz

boolean.h

Page 1 of 2

CMPS 250 Spring 2016, Assignment 1 Part II (C Version)

(Part II Due: Friday February 26, 2016)

To help you gain some insight into the use of strings in C, I provide you with the C source program, Example.c,
that is illustrated below.
server1# cc Example.c -o Example
server1# Example
<Hello>
<Hello> has length 5
<Good-bye> has length 8
Enter capacity:17
----------------Enter string:aaaaaaaaa
<aaaaaaaaa> has length 9
<XXXXXXXXXXXXXXXXX> has length 17
server1# Example
<Hello>
<Hello> has length 5
<Good-bye> has length 8
Enter capacity:17
----------------Enter string:cccccccccccccccccdddddddddddddddddddd
<cccccccccccccccccdddddddddddddddddddd> has length 37
<ddddd> has length 5
server1#

Of particular note above is the buffer overflow error illustrated in the second execution. Note that when the
input string is longer than the memory allocated for the string, the input is still stored. In this case, the long input
has somehow overwritten another string! This is a well-known, but nevertheless dangerous aspect of C.
It should go without saying, but all of the program components you develop are required to be well-written and well
commented. Also, make sure to include comments in UUI.c that:

identify you as the developer of the work submitted


indicate that it is a solution to Assignment 01 II in CMPS 250 for Spring 2016
acknowledge any persons (by full name) with whom you collaborated in developing your solution (or stating
that you worked alone)
point out any flaws of which you are aware.

Of course, you are use the Submission form for the AS01_II folder to submit your work to me, and you may
additionally use the message area on the Submission Form to convey brief remarks, if you wish, but it is not
necessary.
Good luck,
P.M.J.

P. M. Jackowitz

Page 2 of 2