Format: In turning in any programs for the course, please follow these directions:
;;; 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.
adjacent-sums that takes a non-empty
list of numbers and returns a list of the sums of adjacent pairs, thus:
(adjacent-sums '(1 2 3 4 5 6 7)) ===> (3 5 7 9 11 13) (adjacent-sums '(-5 12 13 0 -8)) ===> (7 25 13 -8) (adjacent-sums '(7/3 -1/2 8/5 9/4)) ===> (11/6 11/10 77/20) (adjacent-sums '(4 7)) ===> (11) (adjacent-sums '(16)) ===> ()Here's how we'd write it:
(define adjacent-sums
(lambda (ls)
(if (null? (cdr ls))
'()
(cons (+ (car ls) (cadr ls)) (adjacent-sums (cdr ls)))
)
)
)
adjacent-elements that
takes any non-empty list ls and returns a list of two-element
lists, each two-element list consisting of two adjacent elements of
ls.
(adjacent-elements '(a b c d e)) ===> ((a b) (b c) (c d) (d e)) (adjacent-elements '(5 12 12 0)) ===> ((5 12) (12 12) (12 0)) (adjacent-elements '(first second)) ===> ((first second)) (adjacent-elements '(only)) ===> ()
#t or #f) that takes any non-empty list of real
numbers and determines whether they are in ascending numerical order, in
the sense that each one is strictly less than the one that follows it.
(ascending? '(-50 0 50 100 150)) ===> #t (ascending? '(3.8 4.1 5.0)) ===> #t (ascending? '(1 2 3 5 4 6 7 8)) ===> #f (ascending? '(0 0 0 0)) ===> #f (ascending? '(-2 -3)) ===> #f (ascending? '(17)) ===> #t
Write a procedure that takes as arguments the sitter's starting time in hours and minutes and the ending time in hours and minutes and then computes the sitter's fee. Assume all times are between 6:00 pm and 6:00 am.
Work proceeds in three steps:
Translate the insertion sort from the Scheme lab on sorting, so that it becomes a method in Java.
Modify the sorting algorithm, so that while it orders the count array it also moves the words array in a corresponding way. Thus, the count and words arrays will continue to be parallel, with count[i] giving the word count for words[i].
Use the resulting ordered array to print out the 10 most common words read from the keyboard.
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%.
Multiplication of Three-Digit Integers
749
x 381
-------
749
5992
2247
-------
285369
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/153.sp00/suppl-prob.html