Vocab

Procedure - named group of programming instructions that may have parameters and return values.

Parameters - input values of a procedure.

Modularity - the practice of breaking a complex program into smaller, independent parts or modules that can be used and reused in different parts of the program.

Notes

  • If you have a set of statements and inside there is a procedure then when it reaches that procedure it will excute that procedure and then go back to the rest of the statments.
  • If you see a return statement you automatically end the procedure even if there is more statements
  • Two types of procedures, one that returns a value and one that executes a block of code.
  • The subdivision of a computer program into sepearate subprogrames is called modularity,

Hacks

3.12 part 1

1.1

  • This code would return an error because there is an unmatched curly brace and if the program did not have an error, the code would display "the minimum number is" because the minimum number is never displayed.

1.2

  • PROCEDURE calcAvgSpeed (distance, time) { DISPLAY (distance/time) }

1.3

  • False, program will return all caps; IM MAD

1.4

  • totalFootprint ← calcFlightFootprint(2451, 118) + calcFlightFootprint(3442, 252)

3.12 part 2

2.1

  • The first procedure would display the value 81*9 = 729

2.2

  • The second procedure would display 190

2.3

  • The third procedure equals 39.44

3.13

3.1

def replaceRByards(toprbyardspg, currentrbyards, totalGames):
    if ((toprbyardspg/totalGames) < (currentrbyards/totalGames)):
        toprbyardspg = currentrbyards
    print(toprbyardspg)

replaceRByards(100, 1260, 12)
1260

3.2

PROCEDURE goForwardThenTurn(X, dir){
    for i in range x {
        MOVE_FORWARD)
    }
    if dir = "right"{
         ROTATE_RIGHT()
         MOVE_FORWARD()
         ROTATE_LEFT()
    }
    else{
        ROTATE_LEFT()
         MOVE_FORWARD()
         ROTATE_RIGHT()
    }
}

PROCEDURE goForwardX(X){
    for i in range x {
        MOVE_FORWARD())
    }
}

goForwardX(1)
ROTATE_LEFT()
goForwardThenTurn(2, right)
goForwardThenTurn(2, left)
goForwardThenTurn(1, left)
goForwardThenTurn(2, right)
goForwardX(1)
ROTATE_RIGHT()
goForwardX(2)

3.3

  • B) procedure MyList ### 3.4
PROCEDURE BallToGreen{
Rotate_Left
Move_Forward
Rotate_Right 
Move_Forward( until count = 6)
break
Rotate_Left
Move_Forward (until count=2) 
break
}