CMSC 201
Programming Project Four
Hailstone Sequences
Clarification Note
Here are some important clarifications on project four.
(1) Do not use sprintf to construct the file name. We want to give
you a chance to use some of the string manipulation characters (e.g.,
strcat and friends). Recall what the problem is: given two integers
for a range, say 9 and 18, construct a string like
hail9to18.out. You can use strcat to concatenate strings, but
how do you get the string "18" from the integer 18? You will have to
write a function that takes an integer and returns a string of the
digits in the integer.
HINT: you can get the right-most digit of integer N via (N%10). You
can map that to the appropriate string (e.g., "4") in any of several
ways. You can extract all of the digits in turn by repeatedly
dividing N by 10 and reading out the digit, until the number N becomes
0.
(2) You must use a dynamically allocated array to store the
sequence
lengths when printing a histogram. We want to give you some
experience in dynamic memory allocation and use. While it's true that
the ranges will be 13 or less and you therefore *could* use a
preallocated array of length 13 you will not be allowed to do it this
way. For each range, you must allocate memory for an array of the
appropriate length to hold the length values as they are generated.
You must also free the memory after it is no longer needed.
NOTE: We suggested that the array be an arry of HAIL structures where
each
one holds two integers: a value and a sequence length. You can use a
different design if you want, but you must you a dynamically allocated
array just big enought for the current range.
CSEE
|
201
|
201 S'05
|
lectures
|
news
|
resources
|
help |
|