# Lesson Notes By Weeks and Term - Senior Secondary 1

Introduction to BASIC programming I

Term: 2nd Term

Week: 11

Class: Senior Secondary School 1

Age: 16 years

Duration: 40 minutes of 2 periods each

Date:

Subject:      Computer studies and ICT

Topic:-       Introduction to BASIC programming I

SPECIFIC OBJECTIVES: At the end of the lesson, pupils should be able to

1. Define functions and state their types

INSTRUCTIONAL TECHNIQUES: Identification, explanation, questions and answers, demonstration, videos from source

INSTRUCTIONAL MATERIALS: Videos, loud speaker, pictures, Data Processing for senior Secondary Education by Hiit Plc, WAPB Computer Studies for Senior Secondary I by Adekunle et al, On-line Materials.

INSTRUCTIONAL PROCEDURES

PERIOD 1-2

 PRESENTATION TEACHER’S ACTIVITY STUDENT’S ACTIVITY STEP 1 INTRODUCTION The teacher reviews the previous lesson on BASIC programming language Students pay attention STEP 2 EXPLANATION He explains the meaning of function and states their types Students pay attention and participates STEP 3 DEMONSTRATION He identifies the advantages and disadvantages of each type of function Students pay attention and participate STEP 4 NOTE TAKING The teacher writes a summarized note on the board The students copy the note in their books

NOTE

INTRODUCTION TO BASIC PROGRAMMING

FUNCTION

A function is a type of procedure, routine or self-contained module of code that performs a specific task.

It combines many instructions into a single line of code.

Functions are designed to take in data, process it and return the result as a value.

Most programming languages come with built-in functions, while users can also write their own functions to perform Specialised tasks.

A function, whether built-in or written can be used several times repeatedly.

TYPES OF FUNCTIONS

1. Built-in Functions: These types of functions are built into an application and can be accessed by the end-users. E.g., most spreadsheet applications Support the built-in SUM function that adds up all cells in a row or column.

1. It is optimized to operate in the least amount of time no matter the input type and size.
2. It reduces coding time which consequently reduces overall development and project delivery time.
• It reduces debugging time. If same code is put in multiple places it becomes difficult to make debugging changes in all of those places, so the need to use functions.
2. It makes program maintenance easy.

1. It requires the programmer to be well versed in the programming language.
2. For any compiled programming language like C language, bugs in the code might not manifest themselves until well after the C function ends, making debugging difficult.
• There may not be any speed advantage due to debugging challenges.
1. It is less portable. C function means a new executable program must be made if the hardware platform changes.

1. User Defined Functions: Since one may not always find built-in functions that calculate the value of what is needed, programmers can define their own functions which must return a single value of a specific type. E.g. a function should be defined using the DEF statement thus:

DEF Sech(x) = 1/ Cosh(x) – This defines the hyperbolic secant function.

1. It solves tasks that are not available in built-in into simple subtask
2. The complexity of the entire program can be divided into simple subtask and functions and subprograms can be written for each subtasks.
• The subprograms are easier to write, understand, and debug.
1. A function can be shared by other programs by compiling this function separately and loading and linking them together.
2. Reduction in size of program due to program code of a function can be done
3. It allows for faster execution because it does not need to be re-optimized. It can be used again and again, by calling it.
• It can be used in a number of places without restrictions as compared to stored procedures.

1. It does not allow the use of temporary tables.
2. It does not allow the print command.
• It does not allow the use of the insert, update and delete commands, but can only be used on the table variable defined inside the function.
1. The stored procedure from inside the function cannot be called.
2. In Structure Query Language (SQL), performance of a SQL function is low as compared to a stored procedure.

RULES FOR NAMING FUNCTIONS

1. The name used for functions must be different from that used for variables.
2. The return value for a function may either be a number or a string
3. For string functions, the name must end with a dollar sign.

4.Before a function is used in a program, it must first be defined with a DEF statement or it must be named in a DECLARE DEF statement.

5.Parameters used for functions may be numeric variables, string variables, or names of arrays.

6.When function is invoked, the arguments provided must match the parameters named in the DEF statement, For example:

DEF abcdef (x, z\$, u)

LETn=abcdef (3.2,”dog”, y)

Here, the value 3,2 is assigned to x, “dog” is assigned to z\$, and the value of y is Assigned to u.

1. The name used for function should be self-explanatory. For example, a function getName() will tell the developer what it returns as well as setAddress(), isMale(),etc.
2. The names used for functions should be short, i.e., a function name must be as short as possible so that it is simple to type as well as easy to remember. E.g. using a long name like getNumberOfPagesln’TheBook() is not good for a function rather, a shorter name like getBookPageCount() is better.
3. Use of prefixes is allowed in naming functions as they aid better understanding. For example, getName(), setName(), hasHair(), isBlond(), etc.

EVALUATION:    1. Define function

1. State and explain the types of function