CSE 111, Fall 00, HW #10

CSE 111, Fall 2000

#### HW #10: SUBSTRING PROCESSING

Last Update: 13 November 2000 Note: material is highlighted

For each of the following problems, please turn in a copy of your program, accompanied by at least 2 sample runs with different data that test the facilities of your program.

If your program does not compile, or compiles but does not behave as expected, and you do not have time to correct it, then instead of the sample runs, you should submit a bug report.

1. Do Biermann, p. 58, #3:

Design, write, compile, and test (and debug, if necessary) a Pascal program that has the following input-output behavior:

input: string `S`, integer `n`
output: the first `n` characters of `S`

(i.e., the substring of `S` that consists of the first `n` characters of `S`).

Hint: At which character of `S` does this substring begin?
How long is this substring?

2. Do Biermann, p. 58, #4:

Design, write, compile, and test (and debug, if necessary) a Pascal program that has the following
input-output behavior:

input: string `S`, integer `n`
output: (the substring of `S` that consists of) the last `n` characters of `S`.
Hint: At which character of `S` does this substring begin?
How long is this substring?

3. Do Biermann, p. 58, #5:

Design, write, compile, and test (and debug, if necessary) a Pascal program that has the following
input-output behavior:

input: two strings, `S` and `T`
output: If `S` is a substring of `T`, then it outputs '`yes`', else it outputs '`no`'
Hint: Use the "index" function.
If `S` is a substring of `T`, what is index(`T, S`)? (Is it positive? Negative? 0?)
If `S` is not a substring of `T`, then what is index(`T, S`)?

For this problem, at least one of your sample runs must test a situation in which `S` is a substring of `T`, and at least one of your sample runs must test a situtation in which `S` is not a substring of `T`.

DUE: AT THE START OF LECTURE: WED., NOV. 15

file: 111F00/hw10.13nv00.html