| CSC 161 | Grinnell College | Spring, 2009 |
| Imperative Problem Solving and Data Structures | ||
Supplemental Problems extend the range of problems considered in the course and help sharpen problem-solving skills. Starred problems may be turned in for extra credit.
All instructions and problems on this page are subject to revision!
DO NOT depend upon the problem listing that follows — expect most or
all these problems to change before January 2009!
;;; Henry M. Walker
;;; Box Y-06
;;; Supplemental Problem 2
Also, a comment is needed for every procedure, stating in English what that
procedure is supposed to do.
Write a program that allows the user to enter the cost of an item and the amount paid by the customer, and then prints out the difference (the amount owed to the customer). Also print out how many bills of each denomincation should be given to the customer (one-, five-, ten-, and twenty-dollary bills), and the remainder to be paid in coins. Your computation should use the fewest number of bills. [Do NOT try to compute how many of each coin type should be given to the customer (pennies, nickels, dimes, and quarters).]
Since many modern computer systems use passwords as a means to provide protection and security for users, a major issue can be the identification of appropriate passwords. The main point should be to choose passwords that are not easily guessed, but which the user has a chance of remembering. For example, passwords related to birthdays, anniversaries, family names, or common words are all easily guessed and should be avoided.
Some common guidelines suggest that a password should contain at least 6 characters and include characters from at least three of the following categories:
Other guidelines indicate that elements of passwords should be pronounceable. One simple measure of this guideline suggests that any group of letters in a password should contain both vowels and consonants.
In Scheme, some procedures are already built-in to test some of these conditions. Specifically, the Scheme standard identifies the procedures char-alphabetic?, char-numeric?, char-whitespace?, char-upper-case?, and char-lower-case?. See the section on characters in the Scheme standard for more details.
(contains? str pred?)which applies the predicate pred? to each character in string str and which returns 1 if some character meets this predicate test and 0 otherwise. For example, contains? should return the following results:
(contains "Walker" char-upper-case?) ===> 1 (contains "Walker" char-lower-case?) ===> 1 (contains "Walker" char-numeric?) ===> 0 (contains "Walker" punctuation?) ===> 0
According to this scale, "Walker" would receive a "B" grade, with points for string length, vowel, consonant, upper-case letter, and lower-case letter.
After writing and debugging your procedures, use the submit process described at the beginning of these supplemental problems to turn in your code. In considering the correctness of your code, be sure to write out (in a paragraph) what cases each procedure might encounter, identify test cases to cover each of those cases, show the testing in your submit file, and comment on the extent to which your code handles those cases correctly.
Name Test
First Last 1 2 3 Average
Egbert Bacon 88 85 92 88.33
.
.
.
Maximum -- -- --
Minimum -- -- --
Angelo Jeff 44 Creston IA 50801 Kramer Mary 37 West Des Moines IA 50265 Lundby Mary 26 Marion IA 52302-0563Thus, a typical line gives the last name, the first name, the district number, the town of residence, the state (always IA), and the town's zip code. The information in these lines is arranged in columns.
Design and write a Scheme program that reads in data from this file and creates two output files, senators-by-district and senators-by-zip-code, in the current working directory. The senators-by-district file should contain the same data as the source file, in the same format, but with the lines arranged by senate district (column 3). The other file, senators-by-zip-code, should contain a list of all senators in the following format
Jeff Angelo Creston, IA 50801A blank line should appear after each senator and city address. In this format, the name appears on a first line (first name, then last), and the city, a comma, the state, and zip code is on the next line -- separated by single spaces in the format shown. Note that a variation of this format (with a street address, if available) might be used for a mailing label.
Any of the following problems may be done for extra credit. As noted in the course syllabus, however, a student's overall problems' average may not exceed 120%.
Of course, some fractions trivially have this property. For example, when numerator and denominator are multiples of 10, such as 20/30, one can always "cancel" the zeroes. Similarly, cancelation is always possible when the numerator and denominator are equal, as in 22/22. Your program should omit these obvious cases.
Albuquerque Bernalillo New Mexico 1891 331767 247 323935 14 5A blank line follows each entry, including the last.
Write a procedure which has a filename as parameter and which answers the following questions about the cities represented in the data files.
This program counts words and sentences in file "comp.text ".
Sentence: 1 Words: 29
Sentence: 2 Words: 41
Sentence: 3 Words: 16
Sentence: 4 Words: 22
Sentence: 5 Words: 44
Sentence: 6 Words: 14
Sentence: 7 Words: 32
File "comp.text" contains 198 words words in 7 sentences
for an average of 28.3 words per sentence.
In this program, you should count a word as any contiguous sequence of
letters, and apostrophies should be ignored. Thus, "word", "sentence",
"O'Henry", "government's", and "friends'" should each be considered as one
word.
Also in the program, you should think of a sentence as any sequence of
words that ends with a period, exclamation point, or question mark.
Exception: A period after a single capital letter (e.g., an initial)
or embedded within digits (e.g., a real number) should not be counted as
being the end of a sentence.
White space, digits, and other punctuation should be ignored.
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/161.sp09/suppl-prob.shtml
|
created 22 May 2008 last revised 22 May 2008 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |