|
|
|
|
eXercise #11
Sub-Programming
- Write a simple procedure called Greet which instructs
the computer to clear the screen and then output the littoral 'Hello
and I really mean that'. Test out your procedure.
- Write a procedure called DrawBorder which clears
the screen, which creates a border of asterisks around the entire
screen and which leaves the cursor in the bottom right hand corner
of the screen. (Note that, to avoid scrolling after the asterisk in
line 25 column 80 has been written, you can make your border 79 columns
wide rather than 80 columns wide. Later, you will be shown a method
of creating an 80 column wide border.) It is suggested that you use
FOR..Do loops to efficiently place asterisks.
- Write a procedure called WriteMonth which writes
out the full name of a month based on the current value of some variable
month which is of type
type months = (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec);
This program is allowed to use a variable that is declared in the
body, and assigned prior to the procedure call.
NOTE: this procedure does something that is generally frowned upon
- we will rectify the error later.
- Write a function called Die which returns a random
integer between 1 and 6 inclusive.
- Write a function called Yes which requires that
the user type one of 'Y', 'y', 'N' or 'n' and which returns the value
true if 'Y' or 'y' is typed or false if 'N' or 'n' is typed. Do not
let the user out of the procedure until they have typed one of the
acceptable characters (sometimes called 'error trapping').
- Use the functions Die of Question 4 and Yes
of Question 5 to write a fragment of code which displays random numbers
between 1 and 6 inclusive until the user types 'N' or 'n' to the question
'Another roll?,'.
- The subrange type yearLevels is defined as
type yearLevels = 5..12;
Write a function called EnteredYearLevel which continually
asks the user for a year level until the user types a number between
5 and 12 inclusive and which returns this number as the value of the
function. Be careful and ensure you handle the fact the user may 'accidentally'
type in an incorrect number.
- Write a real function called Average which prompts
the user for how many data elements are to be averaged, then prompts
the user for each integer data element then returns the average of
those integers. To 'trigger' this function, a call similar to the
following could appear in the body of the program:
writeln ('The average is ', Average:0:3);
|
|
|
|
|
|
|