Some of these questions are slightly open-ended, so remember to start by building something
simple. SAVE IT, then progressively make it snazzier. For example, tackling the third
question, it would make sense to start by writing a program which has the numbers already
hard-coded into the program to check that you can actually find the max, min, mean and
stdD of a collection of numbers. When that works, move on to i/o by reading the numbers
from the keyboard in the way we've discussed in class. Finally, try reading numbers in from a file
(initially from a file whose name has been hard-coded into the program, but later from a file whose
name has been acquired by the program as described below);
first with the file having just one line of space-separated numbers, and then many such lines.
- Write a program which will take a collection of integers and manipulate it in each of the following ways:
- add up the numbers entered at the keyboard. The sum of the numbers should be displayed, and there
should be a natural way to indicate that you've finished entering numbers to be added.
- display the max and min of the collection, together with displaying how many numbers had been
entered.
Your program should offer the user the option to either add the numbers or do the max/min part, and shold allow the
user to continue using the program until they indicate that they've had enough.
- Write a program to compare two Strings of characters. Your program should provide options to:
- indicate how many characters are common to both strings (and allow the option to do this in both a
case-sensitive and case-insensitive manner, at the user's choice).
- decide if two strings are the same or are reverses of each other (again both with and without case
sensitivity).
- Write a program which will offer two ways to handle data to be analysed; the
data being a collection of numbers (doubles). The 'analysis' will comprise
finding the max and the min of the collection of numbers, as well as the mean* and
the standard deviation*. The first way of gathering the data should invite the user
to type in numbers at the keyboard once the program has been started, with the 'typing'
of an empty string or the typing of a non-number being used to terminate the list of
numbers. The second choice to be provided
should ask the user for the name of a file to be read from, this file containing a space
separated list of 'doubles' spread over several lines. When the program starts, it should ask the user if
they'd prefer to type in data or give the name of a file holding the data, and then run
accordingly. In both cases the answer should be displayed on the screen, though an option should be provided
to write the analysis data to a file whose name has also been asked for by the program.
* The mean, m, of a list of numbers, (a1, a2, a3, ..., an), is the average, ie
m = (a1 + a2 + ... + an) / n ; and the standard deviation, s, is the square root of the
average of the squares of the differences between the numbers and the mean, ie
s = sqrt[ ( (a1 - m)^2 + (a2 - m)^2 + ... + (an - m)^2 ) / n ] . (Note that there is
some variation in the stats community about whether to divide by n or (n-1) when computing the standard deviation.
This arises perhaps since dividing by n fits within the whole theory of moments, which puts things like means,
std devs, skewness, kurtosis, etc in a consistent framework, whereas dividing by (n-1) reflects nicely the numbers
of degrees of freedom, which fits well within sampling theory. Since there are good arguments for adopting each
version, we'll adopt the division by n version simply to aim for consistency of answers within the course.)