First Assignment, due in on Tuesday 1st February
This
is only a little assignment to get you moving. It doesn't
involve very much. There are two real purposes: 1, to
make sure that everyone can actually write a program
that really works; 2, to make you remember how to
edit, create, and debug program before I need to set
something more complex.
The Assignment
Write a program
in C, that allows the user to type a number of strings (one
per line, to keep it simple), then sorts those strings,
and prints them out in ascending order.
Strong Recommendation
First, forget about strings, and write the program to read,
sort, and print out a list of Numbers. That way, you can
get your program to work without having to worry about
the peculiarities of strings. Then when it really works
perfectly, Make a copy of it and Keep It Safe. Once
you have got a program that works properly for numbers,
just make the little modifications required
to support strings instead.
If you don't solve all the string-related
problems in time, you can submit the working number sorter
that you kept safe
and still get some credit.
How it should Run
There are
two acceptable ways for it to work. The simplest is
that you run the program, it asks you how many strings you are
going to enter, and then lets you enter them. It would
look something like this (underlined things are typed
by the user):
$ cc hw1.c -o hw1
$ hw1
How many strings? 3
Enter 3 strings now
: dog
: bat
: cat
Sorted strings are
bat
cat
dog
$
It always seems
to me to be a little unprofessional making the user work out
in advance how much data they are about to enter. I think it
would be much better to just let the user type strings, and
have a special mark (like an empty line) at the end. That way,
it would look something like this:
$ cc hw1.c -o hw1
$ hw1
Enter some strings now, with a blank line at the end
: dog
: bat
: cat
:
Sorted strings are
bat
cat
dog
$
Submission
This assignment must be submitted electronically before the
end of Tuesday 1st February 2000. You do not need to turn it
in during class, just before the end of the day (midnight).
Remember that you can use any computer you like for the
working, but the program you submit must run on rabbit.
To submit
your answer, use the "submit" program on rabbit. Assuming that
your answer is in the file "hw1.c" as above, you would
type this command:
$ submit 218 hw1 hw1.c
hw1.c submitted
$
If there is something you need to tell me (or our grading
assistants) put it in a file with an obvious name (such
as "read.me") and submit that too.
$ submit 218 hw1 hw1.c read.me
hw1.c submitted
read.me submitted
$
Notes
You may limit the
maximum number of strings if you wish, to any reasonable
number (let's say 1000). That means that you don't have to
worry about linked lists or anything like that. You can
just declare an array of 1000 strings and use that.
Ideally, you
should not set any real limit on the size of each string,
but perfection is not required (this time). You may set
a reasonable limit on the size of each string if you
want to.