Sunteți pe pagina 1din 7

Technological University of the Philippines

CQT Avenue Salawag, Dasmarias City, Cavite


Semi Detailed Lesson Plan
10:00 11:00am

I. Objectives:
At the end of the lesson, the student should be able to:
1. acquaint themselves with functions;
2. familiarize with the syntactical structure of function; and
3. construct a simple program.
II. Subject Matter:
a. Topic concepts
Major: Functions
Sub Topic: Function Construction
b. Values Integrated: Patience, Focus, Willingness to learn, Understanding,
Appreciation, Creativity, and Mastery of Skills
c. References:
Problem Solving with C++ The Object of Functions, by: Walter Savitch
www.cplusplus.com.ph
d. Materials:
Swish Max Presentation
Projector
Cartolina
Whiteboard

III. Learning Activities


A. Preparatory Activities
1. Daily routine / Drill
a. Greetings
b. Prayer
c. Checking of Attendance

d. Collecting of Assignment
e. Review

2. Motivation:
Students will play a game called Pinoy Henyo where one student
will guess the word and the other one will be the coach. This will be
played by 3 pairs of students.
B. Developmental Activities
1. Lesson Proper
Functions
Allow to structure programs in segments of code to perform individual
tasks. It was also a group of statements that is given a name, and which can be
called from some point of the program.

Types of C++ functions

Standard functions are groups in different libraries which can be

included in the C++ program.


User-defined functions are groups in which the user provides his
own way to define function.

Defining Function
To define a C++ function, there are two steps (preferably but not
mandatory)
Step #1 declare the function signature in either a header file (.h file) or
before the main function of the program
Step #2 Implement the function in either an implementation file (.cpp) or
after the main function

Syntax to define a function


In C++, a function is a group of statements that is given a name,
and which can be called from some point of the program. The most
common syntax to define a function is:

type name ( parameter1, parameter2, ...) { statements }

Where:

type is the type of the value returned by the function.


name is the identifier by which the function can be called.
parameters (as many as needed): Each parameter consists of a
type followed by an identifier, with each parameter being separated

from the next by a comma.


statements is the function's body. It is a block of statements
surrounded by braces { } that specify what the function actually
does.

Syntactical structure of function


A C++ function consists of two parts

The function header, and


The function body

The function header has the following syntax:


<return value> <name> (<parameter list>)
The function body is simply a C++ code enclosed between { }.
Void Function
A special type to represent the absence of value.

Syntax Structure:
type name ( ) { statements }

2. Application
The teacher will give an activity wherein the student(s) will make
the program run by means of debugging and of right use of syntactical
structure of function.

IV. Generalization
A function is an assignment or a task that must be performed to complement the
other part(s) of a program. There are two kinds of functions: those supplied to you and
those you will be writing. The functions that are supplied to you are usually in three
categories: those built-in the operating system, those written in C++ (they are part of
the C++ language), and those supplied with your programming environment. The use
of these functions is the same regardless of the means you get them; you should
know what a function looks like, how to create one, what functions are already
available, where they are located, and what a particular function does, how and when
to use it.

V. Evaluation

Multiple Choice: Write the letter (uppercase) of the correct answer after
each number.

1. Which of the following function declaration is/are incorrect?


A.

int Sum(int a, int b = 2, int c = 3);

B.

int Sum(int a = 5, int b);

C.

int Sum(int a = 0, int b, int c = 3);

D.

Both B and C are incorrect.

2. What is the return type of the function with prototype: "int func(char x, float v,
double t);"
A. Char
B. Int
C. Float
D. double
3. Which is not a proper prototype?
A. int funct(char x, char y);
B. double funct(char x)
C. void funct();
D. char x();
4. Which of the following function declaration is/are incorrect?
A.

int Sum(int a, int b = 2, int c = 3);

B.

int Sum(int a = 5, int b);

C.

int Sum(int a = 0, int b, int c = 3);

D.

Both B and C are incorrect.

5. Which of the following is a complete function?


A. int funct();

B. int funct(int x) {return x=x+1;}


C. void funct(int) {cout&tl;<"Hello"}
D. void funct(x) {cout<<"Hello"}

Answer Key:
1.
2.
3.
4.
5.

D
B
B
C
B

VI. Assignment

Follow-Up
Research or think of a possible program that may benefit you or the
society using Functions. Write your idea in sheet of yellow paper. Submission will be
on March 05, 2014.

Advance

Study about Defining and Using Global and Local Variables.


Reference: Problem Solving with C++ The Object of Functions, by: Walter
Savitch
www.cplusplus.com.ph

Prepared by:

LEGASPI, MICHELLE ANNE V.


Student Teacher

Checked by:

PROF. BRENDA MARCIAL


Cooperating Teacher

Approved by:

PROF. JESUSA G. MENDOZA


Supervising Teacher

S-ar putea să vă placă și