Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 9 There are ain’t no way to find out why a snorer can’t hear himself snore Mark Twain, Western koan.

Similar presentations


Presentation on theme: "Lecture 9 There are ain’t no way to find out why a snorer can’t hear himself snore Mark Twain, Western koan."— Presentation transcript:

1 Lecture 9 There are ain’t no way to find out why a snorer can’t hear himself snore Mark Twain, Western koan

2 Lecture 8 review for-loops nested for-loops

3 Can the for-loops be even cooler? Hmm…. What about looping over characters… What if we want to go through alphabet and do something?

4 Ordinal types Ordinal types are the ones which are countable For example integers, characters, boolean but not reals.

5 Ordinal types Orinal types have concept of successor and predecessor succ( ‘A’ ) is (major wow) ‘B’ pred( ‘A’ ) is (major MOM!) ‘@’ Lets see more detailed example

6 Ordinal types succ( pred( ‘A’ ) ) chr( ord( ‘A’ ) ) succ( TRUE ) pred( TRUE )

7 Characters as loop counter! Running through the alphabet: for cMyChar := ‘a’ to ‘z’ do Lets see examples

8 You can have as many loops as you want in any program

9 Standard Pascal functions We need to be able to do basic math sqr- squares a number sqrt- takes square root of a number abs- absolute value of a number exp- e^x ln- natural logarithm (base e) cos- cosine sin- sine * for sin & cos argument is considered to be in radians

10 Turbo Pascal built in functions upcase - gets upper case version of a character frac - gets fractional part of a real int - gets integer part of a real random - gets random number in the range [ 0, 1 ] random(N) - gets random number in the range [ 0, N-1 ]

11 Why do we need random??? A lot of different applications Lets look at some (fun) examples

12 Homework Read the rest of the Chapter 5 Program 3 Page 204 #15 a,b due Monday, October 19th

13 Programs from this lecture Ordinal types Alphabet 1 letter at a time GenX Standard Pascal functions TP functions Random stars Dice game


Download ppt "Lecture 9 There are ain’t no way to find out why a snorer can’t hear himself snore Mark Twain, Western koan."

Similar presentations


Ads by Google