Our brains run without being told to run' - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Our brains run without being told to run'

Description:

Lecture 3 'Our brains run without being told to run.' Douglas Hofstadter, Godel, Escher, Bach' ... Write Pascal program which computes and outputs the area of ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 21
Provided by: Alexi79
Learn more at: https://cs.nyu.edu
Category:
Tags: being | brains | escher | run | told | without

less

Transcript and Presenter's Notes

Title: Our brains run without being told to run'


1
Lecture 3
  • Our brains run without being told to run.
  • Douglas Hofstadter, Godel, Escher, Bach

2
Concepts from lecture 2
3
Concepts from lecture 2
  • reserved words
  • identifiers
  • variables
  • built in functions
  • program output
  • basic types

4
Quiz 1 (10 minutes )
  • Write Pascal program which computes and outputs
    the area of triangle given base and height.
  • Define algorithm
  • Who was Pascal?

5
String constants
  • Used them without noticing
  • Examples
  • Hello world
  • My name is
  • My salary is

6
Arithmetic operations
  • Absolutely need them
  • issue order of operations

7
Example for order of operations
  • PROGRAM LineEquation
  • VAR iX1, iY1, iX2, iY2 integer
  • VAR iSlope, iYIntersept integer
  • BEGIN
  • iX1 2
  • iY1 3
  • iX2 5
  • iY2 -4
  • iSlope ( iY2 - iY1 ) DIV ( iX2 - iX1 )
  • iYIntersept ( iY1iX2 - iX1iY2 ) DIV (
    iX2 - iX1 )
  • writeln( 'The equation of a line is ')
  • writeln( 'y ', iSlope, 'x ',
    iYIntersept )
  • END.

8
DIV and MOD
  • A BX C

9
Mixing types
  • PROGRAM MixingTypes
  • VAR iA, iB integer
  • VAR rX, rY real
  • BEGIN
  • iA 2
  • iB 3
  • rX 2.43
  • rY iA( iB DIV iA - rX )
  • writeln( 'y ', rY )
  • END.

10
What about input?
  • we need to be able to supply different data
  • input device is keyboard
  • built-in function readln

11
Readln example
  • PROGRAM InteractiveLineEquation
  • VAR rX1, rY1, rX2, rY2 real
  • VAR rSlope, rYIntersept real
  • BEGIN
  • write('Enter first known point ')
  • readln( rX1, rY1 )
  • write('Entee\r second known point ')
  • readln( rX2, rY2 )
  • rSlope ( rY2 - rY1 ) / ( rX2 - rX1 )
  • rYIntersept ( rY1rX2 - rX1rY2 ) / ( rX2
    - rX1 )
  • writeln( 'The equation of a line is ')
  • writeln( 'y ', rSlope, 'x ',
    rYIntersept )
  • END.

12
Constants
  • is really a constant not a variable
  • special reserved word CONST

13
Example of a constant
  • PROGRAM AreaOfCircleWithConstantPi
  • VAR rRadius, rArea, rCircumference real
  • CONST PI 3.14159
  • BEGIN
  • rRadius 5.0
  • rArea PI rRadius rRadius
  • rCircumference 2 PI rRadius
  • writeln( 'The area of a circle with radius
    ', rRadius52,
  • ' is equal to ',
    rArea63 )
  • writeln( 'and circumference is equal to ',
    rCircumference63 )
  • END.

14
Grade computation program
  • PROGRAM GradeComputation
  • VAR iHw1, iHw2, iHw3, iHw4, iHw5, iHw6, iHw7
    integer
  • VAR iMidterm1, iMidterm2, iFinal, iHwScore
    integer
  • VAR rHwAverage, rTotalScore, rTotalPercent
    real
  • CONST NUMBER_OF_HOMEWORKS 7 MAXIMUM_SCORE
    134
  • BEGIN
  • write('Enter your homework grades ')
  • readln( iHw1, iHw2, iHw3, iHw4, iHw5, iHw6,
    iHw7 )
  • write('Enter your midterm grades ')
  • readln( iMidterm1, iMidterm2 )
  • write('Enter your final grade ')
  • readln( iFinal )
  • iHwScore iHw1 iHw2 iHw3 iHw4 iHw5
    iHw6 iHw7
  • rHwAverage iHwScore / NUMBER_OF_HOMEWORKS
  • rTotalScore 0.2iHwScore0.4(iMidterm1iMi
    dterm2)0.4(iFinal)
  • rTotalPercent rTotalScore/MAXIMUM_SCORE100

15
Grade computation (part 1)
  • PROGRAM GradeComputation
  • VAR iHw1, iHw2, iHw3, iHw4, iHw5, iHw6, iHw7
    integer
  • VAR iMidterm1, iMidterm2, iFinal, iHwScore
    integer
  • VAR rHwAverage, rTotalScore, rTotalPercent
    real
  • CONST NUMBER_OF_HOMEWORKS 7 MAXIMUM_SCORE
    134
  • BEGIN
  • write('Enter your homework grades ')
  • readln( iHw1, iHw2, iHw3, iHw4, iHw5, iHw6,
    iHw7 )
  • write('Enter your midterm grades ')
  • readln( iMidterm1, iMidterm2 )
  • write('Enter your final grade ')
  • readln( iFinal )

16
Grade computation (part 2)
  • iHwScore iHw1 iHw2 iHw3 iHw4 iHw5
    iHw6 iHw7
  • rHwAverage iHwScore / NUMBER_OF_HOMEWORKS
  • rTotalScore 0.2iHwScore0.4(iMidterm1iMi
    dterm2)0.4(iFinal)
  • rTotalPercent rTotalScore/MAXIMUM_SCORE100
  • writeln( 'Homework score ', iHwScore )
  • writeln( 'Homework average ', rHwAverage63
    )
  • writeln( 'Total score ', rTotalScore63 )
  • writeln( 'Total percent ',
    rTotalPercent63, '' )
  • END.

17
String variables
  • collections of characters
  • sequential

18
String program
  • PROGRAM StringProgram
  • VAR sLast, sFirst string10
  • VAR cFirstChar char
  • BEGIN
  • sFirst 'Blaise'
  • sLast 'Pascal'
  • writeln( 'Pascal programming language is
    named' )
  • writeln( 'after French mathematician ',
    sFirst, ' ', sLast )
  • cFirstChar sLast 1
  • writeln( 'Look him under ''', cFirstChar,
    ''' in encyclopedia.' )
  • END.

19
Homework
  • Read Chapter 3
  • Problem 14, page 99
  • (TO BE HANDED IN) next Monday, October 4

20
Programs for this lecture
  • Linear equation
  • Mixing types
  • Interactive line equation
  • Constant Illustration
  • Grade computation
  • String program
Write a Comment
User Comments (0)
About PowerShow.com