Unit 3 Lesson 12-13
Unit 3 Lesson 12-13
Unit 3 Lesson 12-13
Notes
A procedure is a named group of programming instructions that may have parameters and return values.
Procedures can be reffered to as method or function depending on the programing language.
A procedrure call interrupts an execution of statements and makes the program execute the statements in the procedure.
Parameters are input values of a procedure.
Argurments specifcy the values of the parameters when a procedure is called.
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
Procedures are that a catch-all term for codes used to identify what was done to or given to a patient
If you have a set of statements in a procedure the statement will go thought the top of the procedure to the bottom in order.
Procedure: is a named group of programming instructions that serves a purpose
Parameter: are input values of a procedur
There are two types of procedures, one that returns a value or some type of data and on that just executes a block of statements
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
3.12 Part 1 Hacks
Problem 1
PROCEDURE calcAvgSpeed (distance, time) { DISPLAY (time/distance) }
Problem 2
True==
Problem 3
totalFootprint ← calcFlightFootprint(2451, 118) + calcFlightFootprint(3442, 252)
totalFootprint ← calcFlightFootprint((2451, 118) + (3442, 252))
3.12 Part 2 Hacks
PROCEDURE find a ()
{ c – 9
b <– 9 * 9
a <– b * c
Print (a)
}
What is a?
a= 729
cost ⟵ 173 tax - 10%
PROCEDURE applytax (cost, cpercentDiscounted) { temp <– 100 + percentTaxed
temp <– temp / 100
cost <– cost x temp
Print(cost)}
What is the cost?
cost= $190.30
Tempature - 103 Degrees
PROCEDURE convet Fahrenheit (tempature)
{
Celsius <– tempature - 32
Celsius <– Celsius x 5/9
Print (Celsius)}
temperature: 39.4 degrees Celsius
3.13 Hacks
#1 Create a procedure that is meant to replace the top running backs yards per game in one season if the current running back has more yards per game
Necessary Parameters: toprbyardspg(100), currentrbyards(1260), totalGames(12)
PROCEDURE Replace the top running backs yards per game in one season if the current running back has more yards per game
If (currentRbYards(1260) > toprbyardspg(100)
toprbyardspg <– currentRbYards
#2 Write a procedure that will allow the A+ to get to the 1, while avoiding the black boxes
PROCEDURE GetA+to1
MOVE_RIGHT()
MOVE_RIGHT()
MOVE_FORWARD()
MOVE_RIGHT()
MOVE_RIGHT()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_LEFT()
MOVE_LEFT()
MOVE_LEFT()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_LEFT()
#3 Which Is the Correct Way to define the Name of a Procedure?
A. PROCEDURE MYLIST
B. PROCEDURE MyList
C. procedure mylist
#4 Write A Procedure That gets the BeachBall To the Green Square
PROCEDURE Getballtosquare
MOVE_LEFT()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_FORWARD()
MOVE_LEFT()
MOVE_LEFT()
Reflection
These lessons were a bit challenging at first but with perserverance I was able to understand the concepts which allowed me to perform the hacks well. The presentation was great and I learned a lot from it.