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. Must be finished by 11:59PM Tuesday.

Day 2

  • Functions Basics
  • Read Ch 6.1-6.5
  • Function Basics CPPLab

Day 3

Day 4

  • Global & Static
  • Reference Parameters
  • Read Ch 6.11-13
  • Functions 2 CPPLab

Online Activity Outline

Midterm

Must be taken by Tuesday 11:59PM. 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 CPPLab

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:

Do the CPPLab Functions 2 and the assignment.

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.