|
Programming In Turing - exercises
Exercise #1:
Your name & address will
be displayed on 4 lines on the screen.
The first line is your name, the second line is the name of the street,
the third line is the city and province ,and the fourth line is the postal
code.
Solution
put ""
% The following line outputs the programmer's name on the screen.
put
"" : 35, "Mr. Lista"
% The next line outputs the programmer's house number
% and street name.
put
"" : 24, "45 Norfinch Drive"
% This line displays the programmer's city and province.
put
"" : 30, "Downsview", ", ", "Ontario"
% The following line of code outputs the programmer's
% postal code on the screen.
put
"" : 32, "M3N 1W8"
Exercise #2:
Each program must start
with 5 pieces of information. They are:
(a) the programmer's name,
(b) the date on which the program was written,
(c) the name of saved program,
(d) the teacher’s name, and
(e) a brief description of the program.
Your task for this
exercise is to write a program that will show these five elements for the
program in Exercise #1.
Solution
put "Name: Answer Person"
put
"Date: May 27th, 2002"
put
"Saved As: Exercise 2"
put
"Teachers Name: Mr. Lista"
put
"Purpose : This program displays the name, street, city,"
put
" province" and postal code of the programmer."
% This line places a blank line at the beginning of the display.
put
""
% The following line outputs the programmer's name on the screen.
put
"" : 35, "Mr. Lista"
% The next line outputs the programmer's house number and
% street name.
put
"" : 24, "45 Norfinch Drive"
% This line displays the programmer's city and state/province.
put
"" : 30, "Downsview", ", ", "Ontario"
% The following line of code outputs the programmer's postal
% code on the screen.
put
"" : 32, "M3N 1W8"
Exercise #3:
This
program will display a graphic -- a flag or a logo.
Rewrite the same program to display another national flag.
Solutions
|
setscreen
("graphics:vga")
put "Name: Mr. Lista"
put
"Date: May 29th, 2002"
put
"Saved As: Exercise 3"
put
"Teachers Name: Mr. Lista "
put
"Purpose : This program displays a Canadian flag."
% The next line draws and fills the left red bar on the
% Canadian flag.
drawfillbox
(20, 50, 170, 350, 4)
% This line draws and
fills the right red bar on the Canadian flag.
drawfillbox
(470, 50, 620, 350, 4)
% This line draws the
white background for the flag.
drawfillbox
(170, 50, 470, 350, 15)
% This line of code uses
a special built–in function to draw
% and fill the maple leaf on the flag.
drawfillmapleleaf
(220, 100, 420, 300, 4)
|
 |
Exercise #4:
A program that allows
the user to input any message and then flashes the
message, centered on the screen, in all possible colours.
put "Name: Answer Person"
put
"Date: May 22nd, 2000"
put
"Saved As: A:6_13_4.T"
put
"Teachers Name: n/a "
put
"Purpose : this program allows the user to enter any message and"
put
" the message will be displayed in the centre of the screen in"
put
" all possible colours."
% This statement creates
a variable that will be used to hold the
% message input by the
user.
var
message :
string
% These are blank spaces
to separate the five line introduction
% from the message
prompt.
put
""
put
""
% The following line is
a prompt statement for the user
% to input a message
put
"Enter the message to be displayed:"
% This get statement is
used to input the message.
get
message : *
% The following for
counter counts through all possible
% colours of text.
for
counter : 1 .. 15
% The colour command
that follows changes the text colour to
% the value of the
counter.
colour
(counter)
% The following command
locates the text near the centre
% of the screen.
locate
(15, 25)
% This line prints the
message out on the screen.
put
message
% The next line is a
small delay that slows the colour changes
% so they are visible.
delay
(500)
end for
Exercise #5:
This program displays
"Who is the genius?" in the middle of the
screen. The program
waits for two seconds, displays thirty question marks
centred under "Who is
the genius?", waits two seconds, clears the screen, and
then centres forty
exclamation marks. Under the exclamation marks, your name
should appear. Use
repetition structures for the question and exclamation marks.
put "Name: Answer Person"
put
"Date: May 22nd, 2000"
put
"Saved As: A:6_13_5.T"
put
"Teachers Name: n/a "
put
"Purpose : to display 'who is the genius?', thirty question"
put
" marks, forty exclamation marks, and the programmer's name"
put
" using the delay and locate commands."
% This locate command is
used to position the following text in
% the centre of the
screen.
locate
(13, 30)
% The question 'who is
the genius?' is displayed on the screen.
put
"Who is the genius?"
% The next line is a
delay of 2 seconds before the next
% text is printed.
delay
(2000)
% This locate command
will locate the following text a line
% bellow the question.
locate
(14, 23)
% The row of thirty
question marks is displayed.
put
"??????????????????????????????"
% There is another two
second delay.
delay
(2000)
% This code clears the
screen of all information.
cls
% This locate command
centres the exclamation marks on the screen.
locate
(13, 20)
% Displays the forty
exclamation marks.
put
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
% The displayed text
will be centred and placed one line
% below the exclamation
marks.
locate
(14, 30)
% The programmer’s name
is displayed.
put
"The Answer Person"
Exercise #6:
Write a program that allows the user to input the radius of a circle and then
draws twenty circles across the middle of the screen with this radius.
% This command sets the program into graphics mode.
setscreen ("graphics:vga")
% This is the five line introduction.
put "Name: Mr. Lista"
put "Date: May 28nd, 2002"
put "Saved As: Exercise 6"
put "Mr. Lista"
put "Purpose : to write a program that enables the user to input"
put " the radius of a circle and 20 circles of that radius will be"
put " displayed across the screen."
% This variable is created to store the radius value the user inputs.
var radius : int
% The following are blank lines to separate the five line
% introduction from the radius prompt on the output display.
put ""
put ""
% These lines prompt the user to enter a radius.
put "Please enter the radius (pixels) for twenty circles.
Keep in mind the screen"
put "is 640x480."
% This code takes the input radius value and stores it in
% the radius variable.
get radius
% This for counter counts through all of the twenty circles.
% It reduces the amount of code used compared to the code
% required to draw them individually.
for counter : 1 .. 20
% This built in Turing function draws bright green circles in the
% middle of the screen according to the radius the user input.
drawoval (counter * 30, 240, radius, radius, 11)
end for
% This code locates the '[Press r to rerun, ENTER to continue]' at
% the bottom of the screen.
locate (26, 1)

|
|
|