At the end of this lesson, you will be able to:
A3.2 write subprograms (e.g., functions, procedures) that use parameter passing and appropriate variable scope (e.g., local, global), to perform tasks within programs.
understand and create your own functions with parameters
What is the purpose of a function in programming?
What are 2 built-in functions in functions in Python that you know of?
Create a function called calc_area() in Python that asks the user for the length and width of a rectangle, as decimals. It then calculates and displays the area. Don't worry about error checking.
Do the above question in C++.
functions without parameters
from the online book Computer Based Problem Solving by Patrick Coxall, read:
Parameter:
a variable or value that is passed to a function so it can use it to perform a specific task
when writing a function, you have to tell it what the parameters are
parameters are written in brackets after the function name
Argument:
the variable that is passed to the function in the function call
it is important that the argument name is different than the parameter name!
Pass by Value:
a copy of the data is made and the copy is passed to the function
since the data is a copy, any changes to it are not reflected in the original variable
the original variable CANNOT be modified
Create a program called "Area of Triangle" that has a function that calculates the area of a triangle.
Name the function "calc_area()" in Python and "CalcArea()" in C++
It will accept 2 parameters, base and height (cm), as decimals
It will calculate the area, as a decimal, and print out the results
Ensure the main() function catches any "bad" user input so that only "valid" input is passed to the function.
in groups of 2, do the following on the board for today's daily assignment:
Top-Down Design
Flow Chart
Pseudocode
Test Cases
complete the Daily Assignment section in Hãpara Workspace for this day
if Hãpara is not working, make a copy of this document
move it to your IMH-ICS folder for this course
recreate the same program in C++