"Kai-Uwe Bux" <jk********@gmx .netwrote in message
news:fh******** **@murdoch.acc. Virginia.EDU...
The claim that is hard to believe is that the students learned "how to
write
substantial programs on the first day in the classroom". That claim also
is
very hard to evaluate unless the students actually did write substantial
programs (e.g., as an exercise) before the second day of class (which in a
one-week course would presumably be the next day). As "substantia l" is a
little vague, I would be very interested to learn what program(s) you had
the students write before the second day of class that you consider
substantial. That would help to put the publishers blurb in perspective.
Here is the first day's homework assignment for the Stanford course. Note
that we did not expect every student to answer every question, but we were
always pleased with how far they got.
-----------------------------------------------------------------------------------------------
1. Write a program to count the number of words in an input file.
2. Extend that program to count the number of occurrences of each word.
3. Ensure that the output to problem #2 is sorted by the number of
occurrences. That is, print all words that occur once, followed by those
that occur twice etc.
4. Write a program to read a collection of numbers from the standard input
and the compute and print their median.
5. Given a file of student names and exam scores (formatted as described
below), compute the student's final grade. The input will be records such
as:
Smith 87 92 93 60 0 98 75 90
Carpenter 47 90 92 73 100 87 93 91
...
(Name, grades on six homework assignments, midterm, final)
The program should calculate the final grade as a weighted sum: The median
homework grade counts 40%, the final 40% and the midterm 20%.
So, for the input above, the output would be
Smith 86.8
Carpenter 90.4
...
NOTE: the decimal points should all line up.
6. Extend the previous assignment to print a histogram of grades by ranges:
A 90- 100
B 80- 89.99...
C 70- 79.99...
F <70
The output should list how many students fall into each category.
7. Design and implement a program to produce a permuted index. A permuted
index is one in which each phrase is indexed by every word in the phrase:
So, given the following input
The quick brown fox
jumped over the fence
the output would be
The quick brown fox
jumped over the fence
The quick brown fox
jumped over the fence
jumped over the fence
The quick brown fox
jumped over the fence
The quick brown fox
(Note to Usenet readers: You need to use a constant-width font to read the
table above properly.)
A good algorithm is suggested in The AWK Programming Language by Aho,
Kernighan and Weinberger. That solution divides the problem into three
steps:
1. Read each line of the input and generate a set of rotations of that line.
Each rotation puts the next word of the input in the first position and
rotates the previous first word to the end of the phrase. So the output of
this phase for the first line of our input above would be:
The quick brown fox
quick brown fox The
brown fox The quick
fox The quick brown
Of course, it will be important to know where the original phrase ends and
where the rotated beginning begins.
2. Sort the rotations.
3. Unrotate and print the permuted index, which involves finding the
separator, putting the phrase back together and printing it properly
formatted.