At the end of this lesson, you will be able to:
understand and use default values for a function
True or False: In Python there is only 1 way to call a function.
Given the calculate function in Python, write all the ways of calling the function to:
a) add 8 and 7 and assign it to the variable sum
b) subtract 6 from 10 and assign the answer to the variable difference
3. Given the Calculate function in C++, write all the ways of calling the function to:
a) add 8 and 7 and assign it to the variable sum
b) subtract 6 from 10 and assign the answer to the variable difference
functions with different type parameters
from the online book Computer Based Problem Solving by Patrick Coxall, read:
a default value can also be thought of as an optional parameter.
it is the last parameter of the list
in Python, we set the parameter to be None
in C++, we set the parameter to be 0 or "" for an empty string
Default value MUST be declared as the LAST PARAMETER in the list.
Default value MUST be declared as the LAST PARAMETER in the list.
NOTE: See the Extra at the bottom of this page for more information on how to convert to CAPS in C++.
Create a program called “AddressProgram” that has a function that accepts an address and then prints it again but formatted nicely. Refer to today’s page for example output in both Python and C++.
Name the function: “format_address() in Python” and “FormatAddress()” in C++
The function will have 1 default parameter, the apartment number, which will be “” (null or empty)
Not every address has an apartment number, so it might not have this value
The function will accept only Canadian addresses:
Addressee
Apartment number (optional)
Street number
Street name
City
Province
Postal Code
The function should return a single string that looks like a mailing address from Canada Post.
You are returning a single string, but with multiple lines!
Use “\n” to include a carriage return in the string
Notice that all the text is upper case.
In Python, to make a string all upper case use the built-in function upper()
For example:
some_text = "abc" # some_text = "abc"
some_text_caps = some_text.upper() # some_text_caps = "ABC"
The function should use named parameters.
Ensure that you call the function from main() at least twice:
Once without the optional parameter
Once with the optional parameter
Don't worry about catching invalid data for today's assignment.
Note: The top-down design should be for the entire program. There should be a flowchart for each 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++
to read more than 1 word per line, use getline
to convert a string in C++ to upper case, you need to move it to an array of characters and then change each character to upper case
stringUpper += std::toupper(char_array[counter], loc);
see this Replit