Programming Fundamentals/Functions

From Wikiversity
Jump to navigation Jump to search
Flowchart calling subroutines

This lesson introduces functions. In different programming languages, a function may be called a subroutine, a procedure, a routine, a method, or a subprogram. The generic term callable unit is sometimes used.[1]

Objectives and Skills[edit]

Objectives and skills for this lesson include:

  • Understand the benefits of modular programming
  • Understand subroutines, passed parameters, and return values
  • Understand variable scope
  • Use subroutines/functions/methods to implement program functionality
  • Use local variables, passed parameters, and return values


  1. Rebus: Programming Fundamentals
  2. Wikipedia: Modular programming
  3. Wikipedia: Subroutine
  4. Wikipedia: Parameter (computer programming)
  5. Wikipedia: Scope (computer science)
  6. Wikipedia: Naming convention (programming)


  1. YouTube: Understanding Structure
  2. YouTube: The advantages of modularization
  3. YouTube: Modularizing a program
  4. YouTube: Programming For Beginners - Functions
  5. YouTube: Introduction to Programming - Functions
  6. YouTube: Programming Basics #21 Functions
  7. YouTube: Programming Basics #22 Parameters and Arguments
  8. YouTube: Programming Basics #23 Variable Scope
  9. YouTube: Naming Convention With Programming Languages



Complete the following activities using a flowchart tool, pseudocode, or your selected programming language. Use separate functions for input, processing, and output. Avoid global variables by passing parameters and returning results.

  1. Create a program to prompt the user for hours and rate per hour and then compute gross pay (hours * rate).[2]
  2. Create a program that asks the user how old they are in years, and then calculate and display their approximate age in months, days, hours, and seconds.
  3. Review MathsIsFun: US Standard Lengths. Create a program that asks the user for a distance in miles, and then calculate and display the distance in yards, feet, and inches, or ask the user for a distance in miles, and then calculate and display the distance in kilometers, meters, and centimeters.
  4. Review MathsIsFun: Area of Plane Shapes. Create a program that asks the user for the dimensions of different shapes and then calculate and display the area of the shapes.
  5. Review Wikipedia: Zeller's congruence. Create a program that asks the user for their birthday (year, month, and day) and then calculate and display the day of the week on which they were born.

Lesson Summary[edit]

  • Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.[3]

Key Terms[edit]

Arguments are passed to the subroutine by direct reference, typically using the argument's address.[4]
Arguments are evaluated and a copy of the value is passed to the subroutine.[5]
return value
A sequence of program instructions that perform a specific task, packaged as a unit.[6]


See Also[edit]