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

Day 1

Take midterm on Monday 5/8, Tuesday 5/9, or Wednesday 5/10.

Day 2

Take midterm on Monday 5/8, Tuesday 5/9, or Wednesday 5/10.

Day 3

Take midterm on Monday 5/8, Tuesday 5/9, or Wednesday 5/10.

Day 4

Online Activity Outline

Midterm

Must be taken by Wed. See discussion board for advice.

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 Subdirectory 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:

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.