| 6.170 |
Laboratory in Software Engineering
Spring 2000
Problem Set 0: Programming Diagnostic
Due: February 3, 2000
Handout 4 |
Purpose
This is a very short assignment that will check whether you have the background
we expect in 6.170. If the assignment takes you more than one hour, you
should expect to do extra work over the first three weeks of the course
to improve your basic programming skills.
The Problem
Write a procedure of one argument, a string, which produces a table that
reports the number of times each character appears in the string.
-
You may write your solution in any programming language you like.
-
Assume that the input consists only of the 26 lower-case letters of the
English alphabet.
If you write in Java, C, C++, PASCAL, or a similar language:
-
The input will be a string. For example, if your procedure is called ReportCharacterCounts,
you would call it with the following line of code:
ReportCharacterCounts("bazaar");
-
The output will be a printed table. For each character C appearing X times
in an input string S, where X>0, the procedure should print C : X
on a new line. The lines may be printed in any order. For example,
given the argument "bazaar", the procedure might produce the following
output:
r : 1
a : 3
z : 1
b : 1
If you write in Scheme, LISP, or a similar language::
-
The input will be a list of symbols. For example:
(report-character-counts '(b a z a a r))
The output may be either printed by the procedure itself (i.e. using display)
or may be the return value of the procedure. Again, order does not matter,
but the output should only contain the characters appearing one or more
times in the input. Either of the following two outputs is acceptable (and
each pair may appear on its own line if you prefer):
(r 1) (a 3) (z 1) (b 1)
((r 1) (a 3) (z 1) (b 1))
Please turn in the following as hardcopy:
-
A listing of your code (again, in any language)
-
Sample output from your program on the inputs bazaar and mississippi