Prev Up Next
Go backward to 6.7 Decision Trees and Modulus Arithmetic
Go up to 6 Labs
Go forward to 6.9 Floating Point Precision

6.8 Streams

Looking through a stream of characters for a specific pattern or sequence is frequently done by computers. For an example, think about what a compiler does with a program. It needs to look for comments, operators, identifiers, and constants.

In this lab I want you to do a bit of text processing yourself. (Not quite a compiler for sure.) You can use your standard input, or if you wish to read ahead in your book and process the input from a file. Both approaches are fine. Extra credit will be given if you take the "UNIX" approach of looking on the command line for a file name, and if it exists use it, otherwise use the standard input (keyboard or redirected input).

Write a program that process an input stream doing the following:

After each line read it prints out the following information: At the end of the file print out the following totals: Given the following example input.
This has a comment; And the comment is discarded. 101010010010
A hidden binary number 9991999; Of 1
1010109AAAA10; The last binary number is decimal 2 
This output should be in the following format:
No Binary Number       15 Letters           0 Digits
               1       19 Letters           7 Digits
               2        4 Letters           9 Digits
3 Lines --------------------------------------------
               3       38 Letters          16 Digits  
Test your program with the following sample data set. It is available by anonymous ftp at
ftp://red.cscwc.pima.edu/pub/csc130/stream.dat.
; This is the test date for the lab "Stream"
; Louis Taber  3/29/98
; CSC130  Pima Community College
                           ; Blank Line
ABCDEFGHIJKLMNOPQRSTUVWXYZ ; Uppercase letters
abcdefghijklmnopqrstuvwxyz ; Lower case letters
1234567890                 ; Digits - binary number: 0
11111111                   ; Binary number 255
1000000000000000           ; This may give you 
                           ;   a negative number (OK)
                           ;   Do you know why?
10101010a10101010b111      ; Last binary number: 7
[]|--+=*#@                 ; Some special symbols
The last Line

Turn in a copy of your program and its output when used with the above test data marked with: Place the lab in the instructor hand in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Prev Up Next