Wednesday, May 16, 2007

 

Week of May 14: Program Tracing / Arrays

This weeek we finish our little unit on program tracing. There will be a test, requiring you to trace and give the output for 5 programs.

From the Turing textbook, we introduce the concept of arrays. Arrays enable you to create large numbers of related variables and to process them as a group.

 

Week of May 14: - Program Tracing / Arrays

This week we finish program tracing, ending with a test.

From the Turing textbook, we begin Chapter 14, Arrays. Arrays are a special data type that enables you to create large numbers of variables and to process them as a group.

Monday, April 30, 2007

 

POSTPONED TO NEXT WEEK - Test on Turing, Ch.11 will be first class next week

Because of conflicts with a music field trip, the programming test on Chapter 11 (Handling Strings) is re-scheduled to the first class of next week.

As usual, the questions will be modeled on the questions at the end of the chapter (excluding those we've labeled as "Optional. For students wanting a challenge") and the questions in the "Extra Exercises" file.

Next week we will continue into Chapter 12 of the Turing textbook.

Sunday, April 29, 2007

 

Practise string handling with real text

As you practise handling strings in Turing, it's more fun to use "real" text. One great source of full-length books in ASCII format is www.gutenberg.org.
Now that you know how to access external files with your programs (Ch. 10), you can write programs to analyze a famous book and calculate what percentage is vowels, find the average length of a sentence, find the longest word, encrypt the text by replacing characters - all kinds of interesting things.

(Amaze your English teacher by announcing you know the exact number of times the words "love" and "hate" appear in Romeo and Juliet. Yowzah! Replace every other word in the whole book with your name and see if it is still readable. Change all the i's to 1s, the b's to 6s, the e's to 3s, the s's to 5s. Go crazy.)

Remember that the text should not contain any quotation marks, since Turing will interpret them as signs for tokens. Before you use the text, do a quick Search and Replace in Notepad to replace all the quotation marks (") with apostrophes (').

Thursday, April 19, 2007

 

Substituting One Pattern for Another (Ch. 11)

Let's say you want to change the string "music" to "muzic".

The method Turing uses is to separate the first part, to just before the "s" for which you want to substitute a "z", add the "z", then add the rest of the string that followed the "s". In other words, like this:


You get the first part, "mu", by taking the string from postion 1 until index (string, pattern) minus 1. Again, as we did in the previous exercise, let's simplify by creating the variable pos : int := index (string, pattern). So separating the "mu" of "music" looks like this:

word (1 .. pos - 1

We add the "z" like this:

+ "z"

and we finish by adding the part of the string AFTER the "s" like this:

pos + 1 .. *


In summary, the complete line to substitute the "s" in "music" for a "z" is

word: = word ((1 .. pos -1) + "z" + (pos +1 .. *))


What do you do with the pieces of string!

Wednesday, April 18, 2007

 

Counting patterns in a string (Ch. 11)

Once you are quite familiar with the basic string-handling tools of this chapter (see previous blog entry, and try "Extra Exercises"), you can expand your abilities.

Study carefully the section on Counting Patterns in a Word (p. 182), since it introduces a technique that you will apply in other, related situations. The idea is that, after you search for and find one pattern in a string, before searching again you REDEFINE THE WORD.

You redefine it so that the new word begins somewhere after the position where the first pattern started. For example, if the word was "mississippi" and the pattern was "iss," we would want the word to be redefined as "issippi." How do we do that? The new word will begin somewhere after position 2, where we found the first "iss," using index (word, pattern). But you don't want it to begin exactly AT position 2. You want it to begin at position 2 plus the length of the pattern, in our example the length of "iss." In otyher words, the redefined word begins at

word (index(word, pattern)) + length(pattern)

and it includes the remaining part of the word, namely,

..*)

Putting it all together we redefine the word as follows:

word := word (index(word, pattern) + length(pattern) .. *)



It's easier to understand if you follow the textbook and use a variable pos for the position of the pattern - in our example, iss - and a variable size for the length of the pattern. Your code looks much simpler if you use two variable like these:

pos : int := index (word, pattern)
size : int := length (pattern)

Thus the long, confusing line to redefine the word is much easier to understand when it's simplified to

word := word (pos + size ..*)

Saturday, April 14, 2007

 

Turing, Ch. 10 and 11

    Chapter 10 is short and simple. You learn
  1. how to get input from a text file (rather than from the keyboard) using Run With Args on the menu bar
  2. how to output to a text file (rather than to the screen)
  3. how to use the end-of-file (eof) marker when getting input from a file
  4. how to get an entire line of input at once (rather than one word at a time)

    Don't spend too much time on Chapter 10. Try the programs in the textbook, learn how to use files, then move on to Chapter 11. There will NOT be a test on Chapter 10. You need to know it for later chapters.


Chapter 11 (Handling Strings) gets quite interesting. There will be a couple of small sections that require you to concentrate, but if you get the basic tools down at the beginning, it will not be a problem.

    The first part of the chapter shows you several basic tools for manipulating strings in Turing.
  1. finding the length of a string with length()
  2. joining (catenating) strings with the + operator
  3. selecting part of a string, e.g. word (4..6)
  4. searching for a pattern in a string e.g. index ("dandelion", "lion")


Thursday, March 22, 2007

 

Week of March 26 - Tests on Turing, Ch. 9

During next week (March 26 - 30) there will be a programming test on Turing, Ch. 9 (Selection). Since the chapter is simpler than most, this test will be shorter than usual.




Be sure you know how to program
- simple selection (if - then - else - end if)


- multichoice selection (if - then - elsif - then - else - end if)

- the case construct


We will also return to the Norton textbook.

Friday, March 09, 2007

 

Have a great March Break!


Thursday, March 01, 2007

 

Test next week on Turing, Ch.8 (PixelGraphics)



The test at the beginning of next week will, as usual, consist of questions very similar to those at the end of the chapter (but not the most difficult of them)and the "Extra Practice" questions.

STUDY! PRACTISE! Then you will not find the test difficult.

Change of plan -- After the test, we will continue with the next chapter of Turing (not the Nrton textbook).

Saturday, February 24, 2007

 

Nearing the end of Turing, Ch. 8: Pixel Graphics

Wow! People are doing some amazing things in class! It's more than I expected. I hate to leave this chapter because I love seeing everybody trying things, experimenting and exploring and going beyond what's in the book -- AND HAVING A GOOD TIME!!

But gee, we do have more topics to cover (like IF and text editing and other things), so we'll have a programming test pretty soon and then move back to the Norton textbook first.

The Pickup Folder has answers to the questions at the end of Chapter 8. We'll look at them in class, too, of course.

It's almost time to say goodbye to Chapter 8.

Friday, February 09, 2007

 

Back to Turing (Ch. 8: Pixel Graphics)

Despite what I said in the previous blog entry, we did have another test on the Norton textbook, Lesson 28, and it will go into the coming report card.

Now it's back to Turing and the best, most fun part of the course - pixel graphics. This is where you let your creativity loose and make beautiful, colourful, exciting programs.

And it's not even very hard to do (drawdot, drawline, drawbox, etc.).


Thursday, January 25, 2007

 

Norton 27 - Test late next week

On the last class of next week (Jan.29 - Feb.2) there will be a test on Norton, Lesson 27. That will be the last mark for the coming report card.

Wednesday, January 17, 2007

 

We return to the Norton textbook next week (week of Monday, Jan. 22)


Next week we return to the Norton textbook. Please remember to bring your copy to class.

Friday, January 12, 2007

 

Test on Ch. 7 of Turing (Character Graphics)

We will finsh Ch. 7 this week and have a programming test on Ch. 7 next week.

Tuesday, January 09, 2007

 

A new flower blooms! - "TIK Source" discussion board and more


Brian L. has moved the TIK site I mentioned in an earlier posting so that he can offer lots more features, not just blog-type postings but a full discussion board. Check it out.
http://tiksource.ca.tt/




Sorry to add this, but if you tend to be, um, "playful," remember that inappropriate use could cause its decease.

Sunday, January 07, 2007

 

It's 2007!



Wednesday, December 20, 2006

 

Week of Dec. 18

After the test on Norton 9 and 10, we work on Turing, Computer Graphics.

Most students find the two chapters on graphics to be the most fun part of the course. In this first chapter, you learn some of the basics of graphics and animation. In the next chapter, Pixel Graphics, you go a few steps further and can begin to make some beautiful and fascinating graphics and animations.


Tuesday, December 12, 2006

 

Brian's Alternative TIK Blog

Brian of Period H is keeping an "Alternative" blog for our TIK course at
http://tikjci.blogspot.com/


Hopefully it's all good stuff, interesting and fun and useful and so on.

Brian thinks the design, colours, etc. of my blog are boring, so he's done something different.

One improvement over my blog is that you can leave comments on Brian's blog.

NOTE: You have to talk to Brian to get the username and password, because logging in is required to enter the blog. (Ask Brian about it, not me.)

Sunday, December 10, 2006

 

Week of Dec. 11 - Norton 9 and 10. Test next week.

At the beginning of this week, we go over the answers to Lesson 9 (it was assigned for homework over the weekend). Afterwards, we continue on to Lesson 10.

Because Lesson 10 is a very short lesson, which we will finish before the end of the week, we will return to the Turing textbook in the last class this week.

TEST NEXT WEEK, LESSONS 9 AND 10
The test will be at the start of next week, so that you have the weekend to study. It will cover lessons 9 and 10 (not Lesson 8).


Monday, December 04, 2006

 

Week of Dec. 4, Norton textbook

This week we will finish Ch. 8 (CPUs) and go on to Ch. 9 (Storage).


Thursday, November 30, 2006

 

Lesson 8 worksheet - links to websites now corrected


The question sheet for Lesson 8 (CPUs) has been updated so that the links to websites now work correctly. The corrected file is in the Pickup Folder.

The corrections in the updated file are:

For more information on the history of Intel chips, including photos, see
http://www.intel.com/museum/online/hist_micro/hof/index.htm
(For a less Intel-centric view of microprocessors, see Great Microprocessors of the Past at http://www.sasktelwebsite.net/jbayko/cpu.html
or the “Microprocessor” article at Wikipedia http://en.wikipedia.org/wiki/Microprocessors )

Friday, November 24, 2006

 

Norton textbook, week of Nov. 27

Starting the week of Nov. 27 we return to the Norton textbook.

We also move temporarily to Room 267 while the windows are being replaced in our regular classroom.

Sunday, November 19, 2006

 

Two tests this week (Nov. 20-24)

This week we will have two tests: (1) a short, 15-20 minute multiple choice test for you to show your understanding and (2) in the final class of the week, a test in which you will have the entire class to show how well you can write programs.

The programming test will have questions very similar to the questions at the end of the chapter or in the "extra practice" exercises you have been working on. No questions on the test will be as difficult as the questions in the textbook we've called "challenging." In other words, if you can solve the standard questions, you can do very well on the test.

The programming test may have as many as seven questions. This may seem like a lot but, in fact, some of them are quite easy so that everyone has a chance to do well.

Saturday, November 18, 2006

 

Week of Nov. 20

The Pickup Folder has solutions for Questions 1-12. At the beginning of the week in class, we will discuss solutions for Questions 13-16.

The Pickup Folder also has a file entitled "Hints" which points out the easier questions in the textbook and gives hints for the questions that contain difficulties.


Sunday, November 12, 2006

 

Week of Nov.13-17

We continue learning how to use loops in Turing.

On Wednesday in Home Form you will get your first report card. If your mark is not as good as you'd like, remember the old saying -
"If at first you don't succeed, try, try again."

There are always students who struggle with programming at the beginning of the school year but later "get it" and improve greatly.

Thursday, November 09, 2006

 

Notes on Turing Ch. 6 - the answers

The Pickup Folder now has a pdf file with answers to the questions you have been working on. You may check your answers. (As usual, the pdf is locked so that you may read it and save a copy, but you may not print it or copy/paste text from it.)
(Ch06_Repetition_makingNotes_ANSWERS.pdf)

 

mistakes in math can be hilarious

Have a giggle at some of the mistakes people make in math (It's true! These are funny!)
http://thrillingwonder.blogspot.com/2006/11/new-breakthroughs-in-mathematics.html


Monday, November 06, 2006

 

How these operators, /, div, round, are different

It's important to be very clear in your mind about the differences among these three operators.

15/4 = 3.75
15 div 4 = 3
round (15/4) = 4


/ is normal division. When speaking we say "15 divided by 4."

div is special. It gives the result of division and throws away any remainder, even if the remainder is as large as .9. It is not the same as round(). When speaking we say "15 div 4."

round() rounds a number, either up or down, according to the usual rules of math, that is, rounding up if >= .5 and rounding down if < .5.

Sunday, November 05, 2006

 

Turing, Ch 6 - hints for a few questions

The questions below are challenging questions for the stronger programming students. If you can't figure them out, don't worry. You can safely ignore them.

QUESTION #9 (p. 114) asks you to find the sum of a number of terms of the series of numbers 1 + x + x**2 + x**3 + x**4 .. . This is a challenging question for the stronger students in the class.
HINTS:
- The tricky part in this question is in how you set up the counter (index) for your counted loop.
- You need to recall a little math - What's the value of x0 and x1?

QUESTION #13 (p. 115) asks you to find all the factors of an integer.
HINTS:
- Try all integers from 1 to the number.
- For each one, how do you decide whether it is a factor? Well, a factor of a number divides into the number evenly. That's the definition of a factor.
- Hint: Have a look at a very useful operator called div (p. 101).

QUESTION #14 (p. 115) asks you to take an integer from the user and output the number of digits in it. This is a challenging question for the stronger students in the class.
HINTS:
- Tell the user to enter an integer of 6 digits or less. The book doesn't mention this, but obviously there's a problem if the user can enter ANY number, no matter how large.
- Use div and multiples of 10 as a divisor.

QUESTION #16 (p. 115) asks you to generate random real numbers between, 4 and 5, 0 and 10, and so on. Be sure you learn how to do this. (It's not hard once you think about it, knowing what rand(number) does.)

 

Report cards (Nov. 15)


You have had a chance to look over the marks for tests and assignments that go into calculating your report card mark, checking for errors and asking questions. This week I will submit the marks.

You will receive your report card in Home Form on November 15.

If you happen to be disappointed by your results, remember that these are very preliminary marks. Because it's so early in the year, you do not have a large number of tests and assignments going into your final average, which means that one atypical mark (unsually low, unusually high) can have an exaggerated effect on your final average. So it's possible this report card will not reflect your achievement as accurately as we'd like. Nevertheless, your parents don't want to wait until February to find out whether you are doing well in the course, so we issue this early report card, despite its shortcomings. (You might want to show this explanation to your parents.)

As you accumulate more tests and assignments, your average will become increasingly accurate. And, if you get better marks in the future, your average will continue to climb. By the next report card you should be satisifed that - whether good or bad - your mark is not misleading.

YOU CAN RAISE YOUR MARK. JUST MAKE THE EFFORT.

 

Week of Nov. 6 - Turing, Ch. 6: Repetition (Loops)

We are now working on Chapter 6 (Repetition) of the Turing textbook. You will learn how to use the three types of loops.
- infinite loops
- conditional loops
- counted loops

Loops are a basic building block of any programming language, so once you learn how to use them in Turing, you will find it easy to learn them in Java, C, VB and other languages. By the end of this chapter, you will be able to write some very interesting programs.




Work through the chapter the usual way:

1. Read the chapter, answering questions from the file in the Pickup Folder and trying all the programs in the chapter.

2. Write programs for the questions at the end of the chapter. Create a separate file for each question, and name each after the pattern "Ch06_Q01.t".

3. Write programs for the questions you will find in an additional .pdf file in the Pickup Folder. Remember, programming is like learning to play a musical instrument in some ways - you get better the more you practise. The more programs you write, the more used you get to common pitfalls, the more familiar you are with syntax, and the better you become at finding solutions for computer problems.

 



Saturday, October 28, 2006

 

Hint for coming test on Norton 7

Here are 2 questions that will appear on the coming test on Norton, Lesson 7:


Thursday, October 26, 2006

 

Test on Norton 7 next week

There will be a test on Lesson 7 (Transforming Data to Information) of the Norton textbook next week.

You may earn 90-95% by knowing only your notes. If you want a chance of earning 100%, review Lesson 7 of the textbook as well as studying your notes.

After the test, which will last 15-20 minutes, we will return to programming in Turing, so be sure to bring your Turing textbook.


 

Answers for Norton 7 are in Pickup Folder

Answers for both Part 1 and Part 2 of the questions on Norton, Lesson 7 are now in the Pickup Folder.

They are in a secured .pdf format so that you may make a copy of the file and read the answers, but you will not be able to print it or do a copy/paste of text from it.

Why did I do it this way? While you were reading and making notes on the chapter, your brain absorbed some of the information. Now some of the information in the notes is already stored in your mind. So studying for the text will be easier.

See? It looked like I was making you work for nothing, but actually I was doing you a favour. "Gosh , sir, now I get it!"

Sunday, October 22, 2006

 

Norton, Lesson 7 - assignment

You may do this assignment in your handwriting or you may print it from a word processor. Be sure your full name and your period are at the top of the page.

(1) Write 6 letters of your name as text and binary.

(2) Then write the first three pairs of your student number as binary numbers. Be sure to encode the numbers as numbers in binary notation, not as ASCII characters. For example, take 91 as the number ninety-one, not a nine followed by a one.

See the following example:


 

how to convert a decimal number to a binary number

Converting a decimal number to it binary equivalent is not difficult. Use the simple table technique shown at http://www.is.wayne.edu/olmt/binary/page3.htm

Friday, October 13, 2006

 

Week of Oct. 16 - Norton textbook, Ch.7


This week we return to the Norton textbook.

We will work on Lesson 7 ("Transforming Data into Information").

The usual files will be waiting for you in the Pickup Folder.

Tuesday, October 10, 2006

 

Solutions to Turing, Chapter 5, #13, 14, 15



% The "Ch05_13" Program
const MISC:= 100
const TICKETCOST := 65
var foodCost, diskJockey, hallRental, decorations, waitingStaff, total: real
put "Enter the cost of food"
get foodCost
put "Enter the cost of the DJ"
get diskJockey
put "Enter the cost of the rental of the hall"
get hallRental
put "Enter the cost of the decorations"
get decorations
put "Enter the cost of the waiting staff"
get waitingStaff
put ""
total:= foodCost + diskJockey + hallRental + decorations + waitingStaff + MISC
put "To break even you must sell ", total/ TICKETCOST," tickets"




% The "Ch05-14" Program
var test1Mark, test2Mark, test3Mark, test4Mark, test5Mark: real
var test1Total, test2Total, test3Total, test4Total, test5Total: real
var test1Average, test2Average, test3Average, test4Average, test5Average :
real
var name: string
put "Please enter your name"
get name
put""
put "Enter the mark for your first test, ", name,":"..
get test1Mark
put "What is the maximum mark value for this test? "..
get test1Total
test1Average := test1Mark / test1Total* 100
put""
put "Enter the mark for your second test", name,":" ..
get test2Mark
put "What is the maximum mark value for this test? "..
get test2Total
test2Average := test2Mark / test2Total* 100
put""
put "Enter the mark for your third test", name,":" ..
get test3Mark
put "What is the maximum mark value for this test? "..
get test3Total
test3Average := test3Mark / test3Total* 100
put""
put "Enter the mark for your fourth test", name,":"..
get test4Mark
put "What is the maximum mark value for this test? " ..
get test4Total
test4Average := test4Mark / test4Total* 100
put""
put "Enter the mark for your fifth test", name,":" ..
get test5Mark
put "What is the maximum mark value for this test? " ..
get test5Total
test5Average := test5Mark / test5Total* 100
put""
put "The average for", test1Mark," /", test1Total," is ", test1Average, " %"
put "The average for", test2Mark," /", test2Total, " is ", test2Average, " %"
put "The average for", test3Mark," /", test3Total," is ", test3Average, " %"
put "The average for", test4Mark, " /", test4Total, " is ", test4Average, " %"
put "The average for", test5Mark," /", test5Total," is ", test5Average," %"
put ""
put "Your overall average ", name,", is ", (test1Mark + test2Mark + test3Mark + test4Mark + test5Mark) / (test1Total + test2Total +
test3Total+ test4Total+ test5Total) * 100," %"



% The "Ch05-15a " Program
/*
Ask the user for a real number which expresses the area of a figure.
Assume that the figure was a circle.
Output the radius and then the circumference of the circle.
*/
var area, circumference, radius: real
const PI:= 3.14159
put "Enter the area of a circle:"..
get area
radius := sqrt (area / PI)
circumference := 2 * radius * PI
put "The radius of the circle is ", radius
put "The circumference of the circle is ", circumference



% The "Ch05-15b" Program
/*
Ask the user for a real number which expresses the area of a figure.
Assume that that the figure was a square.
Output the length and width and then the perimeter of the square.
*/
var area, widthLength, perimeter : real
put "Enter the area of the square "..
get area
widthLength := sqrt (area)
perimeter := widthLength * 2 + widthLength * 2
put "The width and length of the square is ", widthLength
put "The perimeter of the square is ", perimeter

Monday, October 09, 2006

 

Test on Turing, Chapter 5

The upcoming test will cover Turing, Chapter 5 (Variables and Constants). You will, of course, also have to know the basics you learned in Chapter 4, such as field sizes, decimal places, and so on. You will be writing 3-5 Turing programs in class. The questions will be very similar to any of (i) the programs you copied from the book while reading the chapter or (ii) the questions at the end of the chapter.

The day after the test, bring your Norton textbook to class.

Happy Thanksgiving!

Friday, October 06, 2006

 

Solutions to Chapter 5, p. 92, #3

Question #3 is the only question at the end of the chapter that has a twist or two. It reads:
"Write a program that inputs the starting time and finishing time of an automobile trip as well as the distance in kilometers traveled and outputs the average speed in km/hr. The times are to be given in two parts: the hours, then the minutes."


Begin by trying to deal with the simplest case - for example, a trip that starts at 8 a.m., ends at 10 a.m. and is a distance of 100 km. To begin with you only need two variables - let's call them startHour and endHour - to find how long the trip lasted. So endHour minus startHour gives you the trip in hours. You need another variable called, say, distance. Then to find the average speed in km per hour, divide the hours by the number of km. The Turing code will look like this.


var startHour, endHour :int
var distance : real
put "Enter hour when trip started: "
get startHour
put "Enter hour when trip ended: "
get endHour
put "Enter distance of trip: "
get distance
put "Average speed of trip was ", (endHour - startHour) / distance

But trips don't always begin and end exactly on the hour. How do we deal with minutes? Convert all the times into minutes, then subtract to give you the time of the trip in minutes. The textbook indicates this method by saying, "the times are to be given in two parts: the hours, then the minutes." Next, you want the result in km per hour. That means distance divided by time (km per hr). But since your time at this point is still in minutes, you divide distance by time then divide the result by 60 to get km per hour. Look carefully at the expression below, especially the brackets.

var startMin, startHour, endMin, endHour :int
var distance : real
put "Enter hour when trip started: "
get startHour
put "Enter minute when trip started: "
get startMin
put "Enter hour when trip ended: "
get endHour
put "Enter minute when trip ended: "
get endMin
put "Enter distance of trip: "
get distance
put "Average speed of trip was ", distance / (((endHour * 60 + endMin) - (startHour * 60 + startMin)) /60), " km / hr"

What if the trip starts in the morning, say 11 a.m., and ends later in the day, say, 4 p.m.? The number 11 is larger than 4. The way to get around this is to ask the user to enter hours using a 24-hour clock:

put "Enter hour when trip started (use a 24-hour clock): "
get startHour
. . .
put "Enter hour when trip ended (use a 24-hour clock): "
get endHour
. . .

The final twist to this problem is when the trip lasts beyond midnight, for example from 9 p.m. to 3 a.m. (that is 21 hours to 3 hours). Use an if construct as below. We won't be studying if constructs until Chapter 9, but some of you are already starting to get the idea. Don't worry if this part is confusing. You will learn about it later in the course.

. . .
get endHour
if endHour < startHour then
endHour := endHour + 24
end if
. . .


 

Solutions to Chapter 5, p. 92, #1, 2, 4, 5, 6, 8

Note: These are not the ONLY way of solving the problems. You may have found a way that is different but just as good.






% The "05-01 Solution" program
const factor := 2.54
% number of cm in 1 inch
var len : real
put "Enter the length of the desk in inches: " ..
get len
put "The length of the desk in centimeters is: ", len * factor, " cm."





% The "05-02 Solution" program
const currentYear := 2006
var birthYear : int
put "Enter the year you were born (e.g. 1981):" ..
get birthYear
put "In ", currentYear," you will be ", currentYear - birthYear, " years old"



OR - GET THE USER TO ENTER THE CURRENT YEAR, AS BELOW



var birthYear, thisYear : int
put "Enter the year you were born (e.g. 1981):" ..
get birthYear
put "Enter the current year :"
get thisYear
put "In ", thisYear," you will be ", thisYear - birthYear, " years old."






% The "05-04" Solution" program
var number1, number2, number3, number4 : int
put "Enter 4 numbers"
% Note that all 4 numbers can be entered on one line
get number1, number2, number3, number4
put "Here are the four numbers that you entered: " ..
put number1, ",", number2, ",", number3, ",", number4
% commas in quotation marks, and commas separating items






% The "05-05" Solution" program
const GREETING:= "Hello, "
const PUNCTUATION := "!"
var name : string
put "Enter your name, please"
get name
put GREETING,name,PUNCTUATION






% The "05-06 Solution" program
var number1, number2, number3, product: int
put "Enter 3 numbers"
get number1, number2, number3
product:= number1 * number2 * number3
% the variable product is not necessary but it
% shortens the multiplication expressions below
put "The product of ", number1, " * ", number2, " * ", number3, " = ", answer
put ""
put "The square of ", product, " is ", product**2






% The "Ch05_08" Program
% The two inputs show two methods
var firstName, lastName : string
put "Enter a first name: "
get firstName
% input one string per line
put "Enter a last name: "
get lastName
put lastName, ", ",firstName
put "Enter a first and last name: "
get firstName, lastName
% input two strings per line
put lastName, ", ",firstName







Friday, September 29, 2006

 

Turing, Ch. 5: Variables and Constants

The topic of variables and constants is not difficult, but it's important to learn it well in order to continue with programming.
  1. Become familiar with how to declare a variable using var. For example:
    var maxTempDay1 : real

  2. Know the three data types -- int, real, string.
  3. Try to think of a variable as a named memory location, that is, an area of RAM the computer gives a name and waits for it to be given a value.


Work on Chapter 5 the same way you worked on Chapter 4:
        • read the chapter carefully
        • make notes from the question sheet in the Pickup Folder
        • try the programs as you read
        • do the exercises at the end of the chapter

This page is powered by Blogger. Isn't yours?