Step 4

In Step 1 – 3 we have already used functions, standard functions from C++ built-in libraries as well as some user-defined functions. The latter have been of a simpler model (often called procedures), like void-declared functions (= without return value). Step 4 will do a thorough review of the function concept, introducing options and conditions for data-transfer between functions and programs. The step includes theory of the course book’s chapter 7: Functions, Part One: The Fundamentals (p. 127-156) and chapter 8: Functions, Part Two: References, overloading, and Default Arguments (p. 157-179).

Study

Sid. 128-141 provides important basic knowledge of the functions to be mastered.
The sections argc and argv: Arguments to main () and Passing Numeric Command Line Arguments (141-144) can be studied briefly.
Pages 145-153 are also important function terms to know, while it is enough to get an overview of the section Recursion (153-156).
Pages 158-163 deals with value parameters and reference parameters, which is of great importance for you to understand, to fully master the concept of functions.
The sections on special cases of reference management, from Returning References to A Few Restrictions … (164-169) is optional reading.
Pages 170-179 introduces Overlapping functions and functions with default values, which is important for the later Object oriented advanced course in C++, so read this section carefully.

Objectives

After Step 4, you should understand how to use features for structuring large programs in a logical and clear manner. You will, by use of functions, be able to divide your assignments into smaller independent parts, in order to use the code in an efficient manner. Thus, you should also know the conditions under which data transfer takes place between applications and functions, primarily through return values.

You shall show a varied use of function parameters, such as different types of variables, arrays, strings, structures and pointers, and understand the essential differences between value parameters and reference parameters. In this context, rules for global and local variables should be applied. The latter includes knowledge about how scope and declaration range controls data transferring to and from functions or within different blocks in a function. Finally, you will have a basic knowledge of how overloaded functions and default parameters can be used to provide a flexible program code.

Content

Concepts that are covered:

  • Development model
    • the functions’ significance for structured programming
  • Declaration area and scope
    • local variables – global variables
  • Basic function concepts
    • function declaration – function definition – return value alt.  void functions
  • Parameters
    • value parameters – reference parameters – default-parameters
  • Overloaded functions

Practical applications

The step has 12 laboratory assignments, among which you make appropriate choices to achieve 6 points, which is the minimum requirement for passing the laboratory assignments for this step. Please note that assignment 1 is mandatory.

Welcome to CoursePress

en utav Linnéuniversitets lärplattformar. Som inloggad student kan du kommunicera, hålla koll på dina kurser och mycket mer. Du som är gäst kan nå de flesta kurser och dess innehåll utan att logga in.

Läs mer lärplattformar vid Linnéuniversitetet

Student account

To log in you need a student account at Linnaeus University.

Read more about collecting your account

Log in LNU