Notes

  • Procedure: named group of programming instructions that may have parameters and return values
  • Parameters: input values of procedures
  • Argurments: specifcy the values of the parameters when a procedure is called
  • Procedures always follow an order, from top to bottom, unless there are other conditions
  • 2 types of procedure: one that returns a statement, and one which just executes code
  • How to code Procedures: Make sure the name of a procedure has a clear purpose and some of it is capitalized
  • 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

Important Functions

  • MOVE_FORWARD(): makes the robot move forward
  • ROTATE_LEFT(): makes the robot rotate left
  • ROTATE_RIGHT(): makes the robot rotate right
  • CAN_MOVE(direction): checks if the robot can move in a particular direction

3.12 Part 1

    1. Answer: PROCEDURE calcAvgSpeed (distance, time) { DISPLAY (distance/time) }
      • This procedure defines the name, has both variables, and displays the correct formula.
    1. Answer: True, nothing will be displayed
      • The function does not have a display statement, so nothing will be printed.
    1. Answer: Answers 1 and 4
      • Both procedures individually calculate the carbon footprint of each flight and then add them together to get the total.

3.12 Part 2

    1. Answer: a is equal to 729.
      • This is because a is equal to 81 times 9(b times c).
    1. Answer: cost is equal to 190.3.
      • Cost is equal to 173 * 1.1(tax), which equals 190.3.
    1. Answer: The temperature is 39.44 degrees Celsius.
      • Temperature is 103-32, 71. 71 * 5/9 is 39.44.

3.13

  1. Necessary Parameters: toprbyardspg(100), currentrbyards(1260), totalGames(12)
    • PROCEDURE CheckTopRb(currentrbyards, totalGames, toprbyardspg) {
    • rbAvg <– currentrbyards/totalGames
    • IF rbAvg > toprbyardspg {
    • toprbyardspg <– rbAvg
    • }
    • DISPLAY (toprbyardspg) - }
  2. Move the A+ to the green
    • PROCEDURE moveAplus {
    • MOVE_FORWARD()
    • ROTATE_LEFT()
    • MOVE_FORWARD()
    • MOVE_FORWARD()
    • ROTATE_RIGHT()
    • MOVE_FORWARD()
    • MOVE_FORWARD()
    • MOVE_FORWARD()
    • ROTATE_LEFT()
    • MOVE_FORWARD()
    • MOVE_FORWARD()
    • ROTATE_LEFT()
    • MOVE_FORWARD()
    • MOVE_FORWARD()
    • ROTATE_RIGHT()
    • MOVE_FORWARD()
    • ROTATE_LEFT()
    • MOVE_FORWARD() - }
  3. Answer: B. PROCEDURE MyList Procedure needs to be completely capitalized, and some parts of the declared procedure should be capitalized.

  4. Move the Beachball to the Green Square
    • PROCEDURE moveBall {
    • ROTATE_LEFT()
    • MOVE_FORWARD()
    • ROTATE_RIGHT()
    • REPEAT 6 times {
      • MOVE_FORWARD()
    • }
    • ROTATE_LEFT()
    • REPEAT 2 times {
      • MOVE_FORWARD()
    • } - }

Reflection

This lesson provided great insight into how to create procedures and make robots. Procedures are important in many coding languages, and having efficient names for them will be key, especially when there is a long program. Procedures also have arguments which allow different arguments to be called. Moving robots can be challenging, as it can be hard to visualize and describe the specific rotations it would take. The nature of direction makes it much easier for us to do, but very hard for us to describe and instruct upon. I had some challenges with the robot moving problems, but with lots of practice, I can achieve mastery.