There are ain - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

There are ain

Description:

Lecture 9. There are ain't no way to find out why a snorer. can't hear himself snore. Mark Twain, Western koan. Lecture 8 review. for-loops. nested for-loops ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 14
Provided by: Alexi79
Learn more at: https://cs.nyu.edu
Category:
Tags: ain | koan

less

Transcript and Presenter's Notes

Title: There are ain


1
Lecture 9
  • There are aint no way to find out why a snorer
  • cant 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!) _at_
  • 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 - ex
  • 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
Write a Comment
User Comments (0)
About PowerShow.com