Week 6 - Defining and Using Functions
Learning objectives
Upon finishing this learning module, you should be able to:
- Identify the parameters and return type of functions
- Describe the difference between value and reference parameters
- Trace code involving function calls
- Write programs utilizing functions to decompose a problem
Schedule
Day 1
- Functions Basics
- Function Basics CPP Lab
Day 2
Day 3
Day 4
- Function Odds & Ends
- Function Design
- Function 2 CPP Lab
Function Basics
Read Ch 6.1-6.5 and watch these videos. The first talks through the basics of writing functions. The second demonstrates how code keeps track of the different variables for each function and how to use the debugger to walk through a series of function calls.
The tool used in that video to animate how the call stack works is pythontutor.com/cpp.html. You won't want to use it for real development, but it can be a helpful way to watch small code samples run.
Do the Functions Basics CPP Lab
Unit Testing
This video introduces the ideas behind unit testing:
Once you have the general concept down, you can read through the UnitTesting Guide for a practical "how to". Stop when you get to Combo Projects; we will tackle them next week.
This video recaps the highlights:
Function Commenting & Doxygen Style
Watch this video on using writing comments for functions in the Doxygen format:
Details of Scope and Reference Parameters
Read 6.11 about global and static variables. Neither one is something you should use very often (if ever). This video hits the highlights:
Read 6.12-6.13 about reference parameters and watch this video:
Function 2 CPPLab focuses on reference parameters. It isn't due until next week, but you are 100% ready to do it now.
Wrap up functions
Read 6.7 & 6.9 - they cover some other techniques that can be used while defining functions. This video recaps the material:
FunctionDesign
Watch this video that covers what makes for a good function:
Optional: More on Unit Testing
- This stack overflow thread has nice concise descriptions of what unit testing is and why it is good. Read the first three responses to the question.