At the end of this lesson, you will be able to:
understand and use compound boolean expressions
What is a default value in programming?
Where is the default value located in the list of parameters in a function definition?
What is the default value set to in Python?
What is the default value set to in C++?
Write the code for a function in Python called print_name that will display the full name of a person in CAPS). The person may or may not give a middle initial.
The function call look as follows:
print_name (u_fname, u_lname, u_minitial)
There are the 2 possibilities of what could be displayed:
SOPHIE A. STUDENT
SOPHIE STUDENT
Write the code for a function in C++ called DisplayInfo that will display the name of a person in CAPS. The person may or may not give their age.
The function call look as follows:
DisplayInfo (uName, uAge);
There are the 2 possibilities of what could be displayed:
LEROY JAMES
LEROY JAMES, 24
default values
from the online book Computer Based Problem Solving by Patrick Coxall, read:
Pass By Value:
passes a copy of the argument. Therefore, the original can never be modified.
Pass By Reference:
passes the address of the argument. Therefore, the original CAN be modified.
Note: the Python language does NEITHER pass by value nor pass by reference. Instead it does "Pass by Object Reference".
In order to achieve the behaviour of pass by reference, we pass a list so that we can then modify its contents.
use the syntax to reference the address of the variable: some_variable[0]
use the syntax &someVariable in the function definition to reference its address
Create a program called “Rounding Program” that accepts numbers with decimals and rounds them according to a given number of decimal places.
Name the function: “round_decimal()” in Python and “RoundDecimal()” in C++.
The function will accept 2 parameters: the decimal number passed by reference and the number of decimal places to round
The function will not return anything
You CANNOT use any built-in rounding function.
Look at these steps to round the decimal:
Multiply the decimal number by 10 to the power of the number of decimal places to round
Add 0.5
Convert the decimal to an integer. Hint: Try casting.
Move the decimal point back to its original position by doing the opposite in step a.
For Python you cannot pass a primitive type (i.e. a float) by reference so you will have ot pass the variable in a list.
Number_var = []
Number_var.append(number)
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++
NOTE: you will most likely get the following error while doing style checking about pointers. That topic is well beyond this course. Just include it in your style check for now:
vocstartsoft:~/environment/temp $ cpplint main.cpp
main.cpp:11: Is this a non-const reference? If so, make const or use a pointer: float &number [runtime/references] [2]
Done processing main.cpp
Total errors found: 2