Lecture 11 – October 3rd
You do NOT need to
have a function in the Pascal program due tonight.
I had four (4)
procedures but no functions in mine.
3:30 pm section –
Here are the things to try that the 2:00pm section started in class. Note that this is more detailed than what I
wrote in
The 2:00pm class
and that some variable names have been changed.
You
Do not need to
turn this in but IF YOU DON”T DO IT, YOU WILL HAVE
TROUBLE
COMPLETING THE IN-CLASS EXERCISE TO BE DONE ON
THURSDAY.
program StringPlay (input, output);
type myString = packed array [1..35] of
char;
var someString : myString;
begin
(* task #1 *)
(* write a little program that will read 5
strings of type myString *)
(* from the keyboard and echo them
back. You do not know how long the *)
(* strings are (but they should be less
than or equal to 35 characters
(* long). WHAT HAPPENS IF THEY ARE
LONGER???? *)
(* task #2 *)
(* try to access - retrieve and/or alter
individual characters in *)
(* a string of type myString after getting
it and printing it as an *)
(* entity.
Print it again after altering it or print a specific *)
(*single character from it before reading
the next string *)
(* task #3
*)
(* read a string a of type myString a
character at a time. Stop *)
(* when you encounter a blank because
you've found a word and *)
(* put it in an array of words . For this task, the following *)
(* type declaration may be useful: words = array [1..10] of myString; *)
end.
Here’s the program we ran in class
illustrating the passing of an array into a procedure.
Here is a modified version of the program we
ran in class. This program will compile
and run because it doesn’t exceed the bounds of the array. However, if you try to store a value in the 6th
position of the 5 element array OR try
to print the 6th element of the 5 element array, the program MAY
simply write over one of the other variables OR it MAY crash with a runtime
error. The behavior is
unpredictable. You should modify the
code and test it by running it several times.
HOWEVER: it is ALWAYS erroneous
to exceed array bounds and you should not do it in your code EVER!!!
Here are
some additional notes from last
Thursday (September 28th)
Please read the
text and review the Chapter 5 slides again. If you have ANY questions about the material,
send me an e-mail with your question
and the page that raised the question by Monday, October 9th. Otherwise I will assume that you will be
prepared to be tested on anything in the chapter.
Please read
chapter 6 and the Chapter 6 slides. We will discuss them in a future class.
Here are some additional notes from the 2pm class today courtesy of
Michelle Klotz.