University of Calgary

Counting Characters

Counting Characters
Source: Katrin Becker, 1987
Write a program that reads a text document and produces a count and frequency of all letters (a,b,c,...) contained within.
This program is only to count letters and both upper and lower case letters should be counted in the same category (i.e. 'A', and 'a' are counted in the same group).
This program should NOT use regular file I/O: run the program using re-directed input as follows:
The end of input marker in the text will be the tilde (~). This indicates the end of data. Data should be read character by character. Each letter must be counted and when all letters have been counted print a table showing the total count for all letters as well as individual totals (for each letter) and frequencies (% of the whole). Make your output clear and readable.
EG.
TOTAL: 523 letters
LETTER
COUNT

FREQUENCY

A

72

13.76%

B

13

2.48%

C

46

8.79%

D 0 0.0%

Your program should be friendly without being too verbose, and it should be reasonably robust (provided the user typed in valid numbers the program should NOT blow up).
The program must be fully documented and follow appropriate style constraints. You must provide sufficient evidence that the program compiles and executes correctly.

Notes on Marking:
In order to pass it must work. (Some marks will be given to all *reasonable* attempts, working or not)

Requirements:
  • adequate, clean design;
  • adequate documentation
  • handles all letters: 'a'-'z';'A'-'Z'
    without using a 'case' or a series of 'if's

  • user interface reasonable?
  • adequate testing?
  • handles all characters
    while still maintaining case INsensitivity

BONUS:
1. Do full ASCII table (128 characters).
2. Use another means to detect 'end-of-input' besides a stopper value.



Updated: August 28, 2005 03:04 PM