Introduction to Turing

advertisement
Introduction to Turing
Save this link somewhere (binder
perhaps):
http://www.beens.org/turing/
Programming:
- A set of instructions that tells a
computer what to do.
- Application programs include
software like Microsoft Word,
Internet Explorer, games, etc.
- An operating system
(sometimes abbreviated as
"OS") is the program that, after
being initially loaded into the
computer by a boot program,
manages all the other programs
in a computer. The other
programs are called applications
or application programs. The
application programs make use
of the operating system by
making requests for services
through a defined application
program interface
- We will be creating application
programs
Mr. Brunton’s Style rules:
 I expect each program to contain
comments (A comment is a line of
“code” that the computer does not
execute). Each program should
have a series of three comments
at the top of each program:
1. Your name
2. Program description
3. Date
 Note: there are two ways to create
comments:
% insert single line comment
OR
/* Insert a multiple line
comment here
This would be useful for the
three comments
I expect at the top of each
program */
 I also expect comments
throughout each program
explaining what a block of code
does.
Output:
To output a statement to the user,
we use the “put” statement. The
following is an example of an
output statement. Try if for
yourself and run it:
put “Have a good day.”
Change the program to say:
“Have a great day Mr. Brunton!”
Calculations:
Computers got their names by
starting as “computers” …
meaning they compute
mathematical problems. Enter the
following to see what you get as a
result:
put 2 + 2
put 2 * 3
numbers
put 6 - 2
numbers
put 9 / 3
numbers
% add two numbers
% multiply two
% subtract two
% divide two
A quick Math Review:
Much like you have to, a computer
follows math rules.
1. This means that it follows
the BEDMAS rules when
calculating; so double check
the use of brackets, etc.
2. You have two basic types of
numbers when calculating:
integer (no decimal places)
and real (with decimal places).
Try the following and test the
results:
put 4 / 3
% real number (with
decimal places)
put 2 * 3
% integer (no decimal
places)
put 5 + 6 * 3 % what answer
should this produce?
put (5 + 6) * 3 % is this different
from the previous line?
Output a Series:
1. You can combine statements
and calculations. For example,
try:
put “2 + 2 = ”, 2 + 2
% add
two numbers, combined with a
statement
Note how the comma separates
the statement from the
calculation.
2. You can change the way your
output is formatted. Try the
following:
put 2 + 5, 3 * 7, 5 – 2 % a series
of calculations, no format
put 2 + 5, “ “ , 3 * 7, “ “ , 5 – 2 %
a series of calculations, separated
by a space
put 2 + 5 : 5, 3 * 7 : 5, 5 – 2 : 5 %
a series of calculations, separated
by a column (with a width of 5)
3. Outputting a series of
statements. Try the following:
put “To be or not to be”
output two lines
put “That is the question”
%
put “Albert ” ..
% two
output statements on one line
using the double dot ( .. )
put “Einstein”
Create the following practice
programs and save them as
Output#.t in your notes folder. For
example, Output1.t, Output2.t,
Output3.t, etc.
1. Write a program that calculates
the area of a circle of radius 10
metres. Hint 1: combine a
statement with a calculation. Hint
2: area of a circle is r2 .
Exponents use two multiply
characters ( ** ). For example
2**3 would produce 8.
2. Create a program that
calculates the tax (13% HST) on a
purchase of $12.50. Hint: you
might have to round your answer.
Modify the following statement to
suit your needs:
put 1.66355345 : 10 : 2 %
column width = 10, rounded to 2
decimal places.
Download