SlideShare a Scribd company logo
2
Most read
8
Most read
23
Most read
XII- COMPUTER SCIENCE
CHAPTER 1
FUNCTION
INTRODUCTION
• The most important criteria in writing and
evaluating the algorithm is the time it takes to
complete a task.
• To have a meaningful comparison of algorithms,
the duration of computation time must be
independent of the programming language,
compiler, and computer used.
• If a bulk of statements to be repeated for many
numbers of times then subroutines are used to
finish the task.
SUBROUTINES
• Subroutines are the basic building blocks of
computer programs.
• Subroutines are small sections of code that
are used to perform a particular task that can
be used repeatedly.
• In Programming languages these subroutines
are called as Functions.
Function
• A function is a unit of code that is often
defined within a greater code structure.
• A function contains a set of code that works
on many kinds of inputs, like variants,
expressions and produces a concrete output.
Function Specification
• Let us consider the example a:= (24).
a:= (24) has an expression in it but (24) is not
itself an expression.
• Definitions bind values to names, in this case
the value 24 being bound to the name ‘a’.
• Definitions are not expressions, at the same
time expressions are also not treated as
definitions.
• Definitions are distinct syntactic blocks.
Parameters (and arguments)
• Parameters are the variables in a function
definition and arguments are the values which
are passed to a function definition.
• 1. Parameter without Type
• 2. Parameter with Type
Parameter without Type
Parameter
Postcondition
Precondition
No Data type
Parameter with Type
With Data type
Keyword
Recursive Function name
Syntax for function definitions
let rec fn a1 a2 ... an := k
‘fn’ function name.
The names ‘a1’ to ‘an’ are variables indicating the
identifiers used as parameters.
The keyword ‘rec’ is required if ‘fn’ is to be a
recursive function;
A function definition which call itself is called recursive
function.
Example to check whether the
entered number is even or odd
All functions are static
definitions. There is no
dynamic function
definitions.
Interface Vs Implementation
• An interface is a set of action that an object
can do.
• For example when you press a light switch, the
light goes on, you may not have cared how it
splashed the light.
• an Interface is a description of all functions
that a class
Key points
• A class declaration combines the external
interface (its local state) with an
implementation of that interface (the
code that carries out the behaviour).
• An object is an instance created from the
class.
• The interface defines an object’s visibility
to the outside world.
Interface Vs Implementation
Characteristics of interface
• The class template specifies the
interfaces to enable an object to be
created and operated properly.
• An object's attributes and behaviour is
controlled by sending functions to the
object.
Example
Pure functions
• Pure functions are functions which will give
exact result when the same arguments are
passed.
• For example the mathematical function sin (0)
always results 0.
•
Pure functions
• strlen (s) is called each time and strlen needs
to iterate over the whole of ‘s’.
• Evaluation of pure functions does not cause
any side effects to its output
Impure functions
• The variables used inside the function may
cause side effects though the functions which
are not passed with any arguments. In such
cases the function is called impure function.
• For example the mathematical function
random() will give different outputs for the
same function call.
XII  Computer Science- Chapter 1-Function
Chameleons of Chromeland problem
using function
• monochromatize (a, b, c)
6
XII  Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-Function

More Related Content

PPTX
Categories of computers and computer languages ppt
PPTX
Crop production ppt
PPT
13 Boolean Algebra
PPTX
Determiners - Types of Determiners
PPTX
PDF
99 Tamil Flowers
PPTX
Introduction to Distributed System
PPTX
Architecture of 8085 microprocessor
Categories of computers and computer languages ppt
Crop production ppt
13 Boolean Algebra
Determiners - Types of Determiners
99 Tamil Flowers
Introduction to Distributed System
Architecture of 8085 microprocessor

What's hot (20)

PPTX
FLOW OF CONTROL-INTRO PYTHON
PPT
Constants in C Programming
PPTX
PPTX
Functions in c language
PPTX
Data types in c++
PPTX
Input and Output In C Language
PPTX
Chapter 08 data file handling
PPTX
Functions in c++
PPTX
Character Arrays and strings in c language
PPTX
Inheritance in java
PPTX
Structure in C language
PPTX
C++ string
PPTX
Object Oriented Programming Using C++
PPTX
Recursive Function
PPTX
arrays and pointers
PDF
Constructors and destructors
PPTX
Function in C program
PPTX
Strings in c++
PPT
RECURSION IN C
FLOW OF CONTROL-INTRO PYTHON
Constants in C Programming
Functions in c language
Data types in c++
Input and Output In C Language
Chapter 08 data file handling
Functions in c++
Character Arrays and strings in c language
Inheritance in java
Structure in C language
C++ string
Object Oriented Programming Using C++
Recursive Function
arrays and pointers
Constructors and destructors
Function in C program
Strings in c++
RECURSION IN C
Ad

Similar to XII Computer Science- Chapter 1-Function (20)

PPTX
Python Functions.pptxhgtyuhffdrthnvfdssu
PPTX
Chapter One Function.pptx
PPTX
Python Functions
PPTX
Funtions of c programming. the functions of c helps to clarify all the tops
PPTX
Functions and structure in programming c
PPTX
FUNCTIONengineeringtechnologyslidesh.pptx
PPTX
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
PPTX
Functions_new.pptx
PPTX
Function in C Programming
PPT
358 33 powerpoint-slides_2-functions_chapter-2
PPTX
2_3 Functions 5d.pptx2_3 Functions 5d.pptx
PPTX
Learn more about the concepts Functions of Python
PPTX
What Is Function, Function Types And Describe Function Prototype.pptx
DOCX
C++ question and answers
PDF
SENG 208 Week -5 Python Functions Presentation
PPT
Basics of cpp
PPT
arrays.ppt
PPTX
Technical trainning.pptx
PPTX
functions in the c programming and the examples
PDF
Python functions
Python Functions.pptxhgtyuhffdrthnvfdssu
Chapter One Function.pptx
Python Functions
Funtions of c programming. the functions of c helps to clarify all the tops
Functions and structure in programming c
FUNCTIONengineeringtechnologyslidesh.pptx
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
Functions_new.pptx
Function in C Programming
358 33 powerpoint-slides_2-functions_chapter-2
2_3 Functions 5d.pptx2_3 Functions 5d.pptx
Learn more about the concepts Functions of Python
What Is Function, Function Types And Describe Function Prototype.pptx
C++ question and answers
SENG 208 Week -5 Python Functions Presentation
Basics of cpp
arrays.ppt
Technical trainning.pptx
functions in the c programming and the examples
Python functions
Ad

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Cell Types and Its function , kingdom of life
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Presentation on HIE in infants and its manifestations
PPTX
master seminar digital applications in india
PPTX
Pharma ospi slides which help in ospi learning
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Computing-Curriculum for Schools in Ghana
STATICS OF THE RIGID BODIES Hibbelers.pdf
01-Introduction-to-Information-Management.pdf
GDM (1) (1).pptx small presentation for students
FourierSeries-QuestionsWithAnswers(Part-A).pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Cell Types and Its function , kingdom of life
202450812 BayCHI UCSC-SV 20250812 v17.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Institutional Correction lecture only . . .
Supply Chain Operations Speaking Notes -ICLT Program
Anesthesia in Laparoscopic Surgery in India
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Presentation on HIE in infants and its manifestations
master seminar digital applications in india
Pharma ospi slides which help in ospi learning
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial diseases, their pathogenesis and prophylaxis

XII Computer Science- Chapter 1-Function

  • 2. INTRODUCTION • The most important criteria in writing and evaluating the algorithm is the time it takes to complete a task. • To have a meaningful comparison of algorithms, the duration of computation time must be independent of the programming language, compiler, and computer used. • If a bulk of statements to be repeated for many numbers of times then subroutines are used to finish the task.
  • 3. SUBROUTINES • Subroutines are the basic building blocks of computer programs. • Subroutines are small sections of code that are used to perform a particular task that can be used repeatedly. • In Programming languages these subroutines are called as Functions.
  • 4. Function • A function is a unit of code that is often defined within a greater code structure. • A function contains a set of code that works on many kinds of inputs, like variants, expressions and produces a concrete output.
  • 5. Function Specification • Let us consider the example a:= (24). a:= (24) has an expression in it but (24) is not itself an expression. • Definitions bind values to names, in this case the value 24 being bound to the name ‘a’. • Definitions are not expressions, at the same time expressions are also not treated as definitions. • Definitions are distinct syntactic blocks.
  • 6. Parameters (and arguments) • Parameters are the variables in a function definition and arguments are the values which are passed to a function definition. • 1. Parameter without Type • 2. Parameter with Type
  • 8. Parameter with Type With Data type Keyword Recursive Function name
  • 9. Syntax for function definitions let rec fn a1 a2 ... an := k ‘fn’ function name. The names ‘a1’ to ‘an’ are variables indicating the identifiers used as parameters. The keyword ‘rec’ is required if ‘fn’ is to be a recursive function; A function definition which call itself is called recursive function.
  • 10. Example to check whether the entered number is even or odd All functions are static definitions. There is no dynamic function definitions.
  • 11. Interface Vs Implementation • An interface is a set of action that an object can do. • For example when you press a light switch, the light goes on, you may not have cared how it splashed the light. • an Interface is a description of all functions that a class
  • 12. Key points • A class declaration combines the external interface (its local state) with an implementation of that interface (the code that carries out the behaviour). • An object is an instance created from the class. • The interface defines an object’s visibility to the outside world.
  • 14. Characteristics of interface • The class template specifies the interfaces to enable an object to be created and operated properly. • An object's attributes and behaviour is controlled by sending functions to the object.
  • 16. Pure functions • Pure functions are functions which will give exact result when the same arguments are passed. • For example the mathematical function sin (0) always results 0. •
  • 17. Pure functions • strlen (s) is called each time and strlen needs to iterate over the whole of ‘s’. • Evaluation of pure functions does not cause any side effects to its output
  • 18. Impure functions • The variables used inside the function may cause side effects though the functions which are not passed with any arguments. In such cases the function is called impure function. • For example the mathematical function random() will give different outputs for the same function call.
  • 20. Chameleons of Chromeland problem using function • monochromatize (a, b, c) 6