CSCI 103L Lecture Notes - Lecture 6: Procedural Programming
Document Summary
Also called procedures or methods depending on the language. Takes 0 or more inputs (parameters or arguments) Can de ne once and then call in multiple places. Actual parameters: the actual values that are input into the function by the caller, ex: max(6,4); Ex: double avg(int n1, int n2) : double sum = n1 + n2, return sum/2. 0 } Functions don"t have to return anything: to do this initialize with void, ex: void print() { cout << words << endl; } The only way to get things out of a function are to have a return statement. C is a procedural language: main unit of code organization is problem decomposition and abstraction, i. e. making functions . C++ is considered an object-oriented language: main unit of organization is an object (collection of code and associated data) To decompose a function into functions look for verbs or tasks: ex: in poker deal(), shuf e(), etc.