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 use compound boolean expressions
return values
What is a return value in programming?
List 3 different types of return values in Python or C++.
When a value is returned from a function, is it passed by value or by reference?
For the following function in C++:
a) What is the name of the function?
b) How many parameters does it take?
c) State each parameter type.
d) What is the return type?
e) State what will occur by the following:
float userLength = 7;
float userWidth = 4;
float userArea = CalcArea(userLength, userWidth);
from the online book Computer Based Problem Solving by Patrick Coxall, read:
in Python there are 2 ways in which you can call a function
in C++, there is only 1 way to call a function
Function Definition in C++ - Example
order of arguments always matters in C++. Each argument must correspond to the parameter in order and type.
Function Definition in Python - Example
order of arguments does not matter in Python as long as you specify the parameter and its assigned argument
alternatively, you can call a function in Python the same way as in C++
Create a program called "Calculator" that has a function that accepts the operation as well as the two decimals
Name the function:
calculate(sign, first_number, second_number) in Python, and
calculate(char sign, float firstNumber, float SecondNumber) in C++
It asks for 3 parameters: the sign of the operation as a char and the two numbers as floats
It returns the result of doing the operation on the two numbers. (See program output below.)
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++