← Computer Studies / 3 Software development
3.6 Functions
Computer Studies · Grade 10 · 14 lessons in the design
What this covers
- Modular programming and its importance
- Built-in and user-defined functions
- The syntax of a function: name, parameters, body, return value
- Parameter passing: formal and actual parameters, return values
- The scope of variables: local and global
- The role of functions in programming
What you will be able to do
- discuss the types of function used in modular programming
- use built-in and user-defined functions to create a modular program
- discuss the scope of variables and parameter passing between functions
Key questions
“What are the roles of functions in programming?”
Lessons
The titles are open to everyone. Reading a lesson needs an account — sign in or create one.
-
Functions and modular programming
40 min · 1 practice tasks · quizWhat a function is, built-in versus user-defined, how to define and call one, and why breaking a program into functions is how all real software is built.
-
Parameter passing and variable scope
40 min · 1 practice tasks · quizHow functions communicate through parameters and return values, and how local and global scope keep the parts of a program from interfering.
-
Why modular programming
40 min · 1 practice tasks · quizA kiosk till as one tangled script versus named functions - why real software is built in pieces.
-
Built-in functions in practice
40 min · 1 practice tasks · quizprint, input, int, len, range, min, max, sum, type - ready-made tools, and why the language ships them.
-
Writing a function definition
40 min · 1 practice tasks · quizdef, a meaningful name, colon, indented body - define greet once, then call it.
-
Parameters: giving a function data
40 min · 1 practice tasks · quizZero, one or several parameters. Matched left to right. A VAT function that takes a price.
-
Return values: getting a result back
40 min · 1 practice tasks · quizreturn hands a value to the caller. print only shows a human. Catch the result in a variable.
-
Functions calling functions
40 min · 1 practice tasks · quizA final_bill that asks subtotal and add_vat to work - composition, and testing one piece at a time.
-
Formal and actual parameters
40 min · 1 practice tasks · quizlength and width are formal; 5 and 3 are actual. The signature is the contract the caller must keep.
-
Local variables in practice
40 min · 1 practice tasks · quizEach call gets a fresh private total. When the function ends, the local name is gone.
-
Global variables and constants
40 min · 1 practice tasks · quizA name outside every function is global. Use it sparingly, mainly for true constants such as VAT 0.16.
-
Value-returning and void functions
40 min · 1 practice tasks · quizSome functions compute a result; some only do a job such as printing a receipt. Know which you are writing.
-
Building a modular program
40 min · 1 practice tasks · quizA school-mark reporter from small functions: input, average, grade, report - the 3.6 outcome in one sitting.
-
The roles of functions
40 min · 1 practice tasks · quizReuse, simplicity, easier fixes, teamwork, readability - and abstraction as the idea underneath all five.