User defined procedures and functions method instruction 2 variant

  • doc
  • 02.05.2020
Публикация на сайте для учителей

Публикация педагогических разработок

Бесплатное участие. Свидетельство автора сразу.
Мгновенные 10 документов в портфолио.

Иконка файла материала User defined procedures and functions method instruction 2 variant.doc

Methodological Instructions

Theme: User defined procedures and functions  2 lesson 2 variant

Objective: 10.4.1.1 write a code in the programming language using functions and procedures

Assessment criteria

·                    Students understand and distinguish the definitions of functions and procedures in programming.

·                    Students can solve problems using functions and procedures

·                    Knows and can determine the clock speed

Basic Level:

From a grade 7–9 course, students have knowledge and programming skills.

Key words and phrases:

Subprogram, function, procedure, formal and actual parameters, global and local variables

Function - part of the program that has ...

Method is a function that is ...

Function is used for…

Procedure is used for...

I.                   Practice

1.      Write a procedure called “Display” that will prompt the user to enter two integer numbers n and m, and will display all the numbers from n until m. i.e.

If  n = 4, m = 9  it will display:  4  5  6  7  8  9

Also, write the main program to name the procedure “Display”.

Draw the flowchart of the above program.

2.       Write a procedure called “Sum” that will prompt the user to enter two integer numbers n and m, and will display the sum of all the numbers from n until m. i.e.

If n = 2, m = 6  it will display:  20

since   2 + 3 + 4 + 5 + 6 = 20

3.      Write a program to ask for the price of a product and display the discount. The discount which is 15% will be calculated and displayed in the procedure “Discount” that will take the price as a value formal parameter.

Draw the flowchart of the above program.

4.      Write a program that will ask the user to enter the base and height of a right-angle triangle and will display its area. The area will be calculated and displayed in the procedure “Area” that will take the base and height as value formal parameters.

Area = (base * height) / 2

Draw the flowchart of the above program.

5.      Write a procedure called “Even” that will take two integer numbers n and m, and will display all the even numbers from n until m. i.e.

Even(4,13)    will display:   4  6  8  10  12

Also, write a program that will ask the user to enter the two numbers and call the procedure “Even”.

6.      Draw the flowchart of the above program.

Write a procedure called “Sum” that will take two integer numbers n and m, and will display the sum of all the numbers from n until m. i.e.

Sum(2,6)    will display:   20

since   2 + 3 + 4 + 5 + 6 = 20.

Draw the flowchart of the above program.

 

П. Tests and Assignments for Self-assessment.

1.      What is the difference between a procedure and a function?

a)    There is no difference

b)    A procedure performs a task whereas a function produces information

c)    A procedure produces information whereas a function performs a task

2.      What is a module?

a)     A module is a small section of a program

b)     A module allows you to pass information into a function

c)     A module is the name for a value passed into a function

3.      What is a parameter?

a)     Parameters are the values that are passed into a function or procedure

b)     Parameters are the names of the information that is used in a function or procedure

c)     A parameter is a small section of program

4.      What is an argument?

a)     An argument is a value that is passed into a function or procedure

b)     An argument is a small section of program

c)     An argument is the name of the information that is used in a function or procedure

5.      What is the difference between a local and a global variable?

a)     A global variable is declared so it can be used in any part of the program and a local variable is only available in a specific function

b)     A local variable is declared so it can be used in any part of the program and a global variable is only available in a specific function

c)     Both local and global variables can be used in any part of a program

6.      What is a module-scoped variable?

a)     A variable that is available in any part of the program

b)     A variable that can only be used once

c)     A variable that is only available in a single file or module

7.      What is meant by 'executing' a function?

a)     Deleting the function

b)     Changing the function

c)     Asking a function to run

8.      Which of the following can be given an identifier?

a)     Functions and procedures

b)     Functions, procedures, parameters, arguments, variables and constants

c)     Variables and constants

9.      In the statement 'for x in range (1,5)' what type of variable is 'x'?

a)     Local variable

b)     Global variable

c)     Module-scoped variable

10.  Which of the following is a function?

a)     Algorithm to draw a circle

b)     Algorithm to calculate VAT on a product

c)     Algorithm to create a cake

 

Visual Aids and Materials.

1.    Slides

2.    http://physics.herzen.spb.ru/library/03/01/pp/TPHelp/subroutines.htm

3.    https://en.wikibooks.org/wiki/A-level_Computing/AQA/Paper_1/Fundamentals_of_programming/Subroutines_(functions_and_procedures)

4.    Procedures and functions of working with strings: http://pas1.ru/stringfunction

5.    http://purecodecpp.com/archives/920

6.    https://www.bbc.com/bitesize/guides/z9hykqt/revision/1

7.    https://www.advanced-ict.info/programming/functions.html

8.    https://www.bbc.com/bitesize/guides/z9hykqt/test

9.    https://www.youtube.com/watch?v=T3pP5jMV69M


10.       Скачано с www.znanio.ru