User functions 2

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

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

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

Иконка файла материала User functions 2.docx

Long term plan unit:

School:

Data:

Teacher’s name:

Class:

The number of attendees:

absentees:

Lesson theme

User functions and procedures

Learning objectives that are achieved in this lesson (Subject Programme ref)

write code in programming language using functions and procedures

Lesson objectives

programming using functions and procedures

Evaluation criteria

Know

          •function parameters

Understand

          •explain how to use function parameters

Application

          •Write code using functions

          •Write code using procedures

 

Language objectives

 

Student is able to describe the difference between function and procedure, making clear the way they are used.

For instance, procedure is void, while the function has a return type.

Also, student can justify the purpose of function and procedure

Vocabulary and terminology specific to the subject:

Void, ref, procedure, function, out, return value, parameter, reference value, argument passed by value

Useful expressions for dialogs and letters:

Well, there are cases when we use returning … .

For example, the IntelliSense is of considerable support when … .

Obviously, the functions and procedures are used to make  … .

 

Cultivating values

 

 

collaboration, mutual respect, academic honesty, perseverance, responsibility, lifelong learning

Cross curricular links

English, Math

Prior knowledge

 

Programming basics

During the classes

Planned stages of the lesson

Planned activities in the classroom

Resources

Beginning

4 min

 

 

1.      Greetings

2.      Starter

(C) solve a rebus with the word “Function”

    3. Announcement of topic and LO

   Students asked to think about Evaluation Criteria(EC) for LO to work it out (official EC is supplied)

 

4.Useful expressions for dialogs

 

 

 

Slides 1-4

Middle

 

 

     15 min

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5 min

 

 

 

 

 

12 min

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2 min

Task 1

Action: (P) reading and discussion

Purpose: understand the function parameters ref and out

Description:

Teacher’s activities:

Student’s activities:

Introduces the task. Spreads the handout with content

 

 

(P) One student in pair has material about ref parameter and another student has information about out parameter. They have to read and after realization have to explain each other and discuss their contents.

 

Then they type the codes for both parameters to see the results.

 

 

Evaluation:

Evaluation Criteria

Descriptors

Know function parameters

·         Tells what for the ref parameter is used

·         Tells what for the out parameter is used

Explain how to use function parameters

·         Describes the functioning of ref parameter

·         Describes the functioning of out parameter

 

Differentiation:  The students who finish earlier are instigated by teacher to develop the given programs

Feedback: Teacher makes comments or correction when necessary

 

Theory

Teacher explains the Recursion algorithm where the ref parameter is used. Students listen and write down.

 

Task 2

Action: analyze a program

Purpose: to get familiar with function using recursion and with the way to calculate the Factorial of given number.

Description:

Teacher’s activities:

Student’s activities:

Explains the task and spreads handouts with program that calculates the Factorial of given number using loop operator. Students in pair must rewrite programs part (function) to use Recursion.

 

Before starting the task, presents on slide and discusses with students the evaluation criteria

 

(2 min)

(P)  Analyze and discuss the code. Then writes the program

 

(10 min)

 

Evaluation:

Evaluation Criteria

Descriptors

Write code using functions

         

 

Programs using:

·         the ref parameter

·         the recursion

 

Analyze function code

Could explain each line of code

 

Differentiation:  The students who finish earlier are involved by teacher to support students who need that

Feedback: Teacher makes comments or correction when necessary

 

Summary

Questions:

 What is a function or procedure?

What parameters of function you know?

Why need recursion?

 

 

 

 

Slide 5

 

Appendix 1

Handout 1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Slide 6-9

 

 

 

Appendix 1

Handout 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Slide 10-11

 

 

 

 

Slide 12

End

2 min

Learners reflect at the end of the lesson:

- what I learned;

- what remained incomprehensible;

- where I should work more.

Slide 13

Differentiation - how do you plan to provide more support? What tasks do you plan to put before more able learners?

Evaluation - how do you plan to check the level of mastering the material by learners?

Health and safety practices


Дифференциация может быть выражена в подборе заданий, в ожидаемом результате от конкретного ученика, в оказании индивидуальной поддержки учащемуся, в подборе учебного материала и ресурсов с учетом индивидуальных способностей учащихся (Теория множественного интеллекта по Гарднеру).

Дифференциация может быть использована на любом этапе урока с учетом рационального использования времени.

Use this section to record the methods that you will use to assess what students have learned during the lesson.

Health-saving technologies.

Used body and physical exercises.

Points applied from the Safety Rules in this lesson.

Reflection on the lesson

 

Were the goals of lesson/ learning objectives realistic?

Have all the students reached the LO?

If not, why?

Is the differentiation done correctly in the lesson?

Were the time stages of the lesson sustained?

What were the deviations from the lesson plan and why?

Use this section to reflect on the lesson. Answer the most important questions about your lesson from the left column.

 

Overall assessment

 

 

What two aspects of the lesson went well (think about both teaching and learning)?

1:

 

2:

 

What could help improve the lesson (think about both teaching and learning)?

1:

 

2:

 

What I found during the lesson related to the class or the achievements / difficulties of individual students, what should I look for in subsequent lessons?

 

 

 

 

Appendix 1

 (handout 2)

Task 2. 

1.        using System;    

2.        namespace InterviewQuestionPart4    

3.        {    

4.            class Program    

5.            {    

6.                static void Main(string[] args)    

7.                {    

8.                    Console.WriteLine("Please Enter a Number");    

9.            

10.                 //read number from user    

11.                 int number =Convert.ToInt32(Console.ReadLine());    

12.         

13.                 //invoke the static method    

14.                 double factorial = Factorial(number);    

15.         

16.                 //print the factorial result    

17.                 Console.WriteLine("factorial of"+number+"="+factorial.ToString());    

18.         

19.             }    

20.             public static double Factorial(int number)    

21.             {    

22.                 if (number == 0)    

23.                     return 1;    

24.         

25.                 double factorial = 1;    

26.                 for (int i = number; i >= 1;i-- )    

27.                 {    

28.                     factorial = factorial * i;    

29.                 }    

30.                 return factorial;    

31.             }    

32.         }    

33.     }   

 

1.      Analyze the code of program: tell about the way Factorial of number is calculated.  Type the code in C# and run to check your idea.

 

2.      Now for how to convert this function into a recursive function, for example if we want to calculate the factorial of 4, there are two methods like.

recursive function

So we will calculate the factorial like this:

4!=4x(4-1)x(4-2)x(4-3)=24.  
Change the program using this way.

 

1.        using System;    

2.            

3.        namespace InterviewQuestionPart4    

4.        {    

5.            class Program    

6.            {    

7.                static void Main(string[] args)    

8.                {    

9.                    Console.WriteLine("Please Enter a Number");    

10.         

11.                 //read number from user    

12.                 int number =Convert.ToInt32(Console.ReadLine());    

13.         

14.                 //invoke the static method    

15.                 double factorial = Factorial(number);    

16.         

17.                 //print the factorial result    

18.                 Console.WriteLine("factorial of"+number+"="+factorial.ToString());    

19.         

20.             }    

21.             public static double Factorial(int number)    

22.             {    

23.                 if (number == 0)    

24.                     return 1;    

25.                 return number * Factorial(number-1);//Recursive call    

26.         

27.             }    

28.         }    

29.     }    

 

 

 

Handout 1

Student 1 (in pair)

Function parameters

The first thing that we will take a look at, is the out and ref modifiers. C#, and other languages as well, differ between two parameters: "by value" and "by reference". The default in C# is "by value", which basically means that when you pass on a variable to a function call, you are actually sending a copy of the object, instead of a reference to it. This also means that you can make changes to the parameter from inside the function, without affecting the original object you passed as a parameter.

With the ref and the out keyword, we can change this behavior, so we pass along a reference to the object instead of its value.

The ref modifier

Consider the following example:

static void Main(string[] args)
{
    int number = 20;
    AddFive(number);
    Console.WriteLine(number);
    Console.ReadKey();
}

static void AddFive(int number)
{
    number = number + 5;
}

We create an integer, assign the number 20 to it, and then we use the AddFive() method, which should add 5 to the number. But does it? No. The value we assign to number inside the function, is never carried out of the function, because we have passed a copy of the number value instead of a reference to it. This is simply how C# works, and in a lot of cases, it's the preferred result. However, in this case, we actually wish to modify the number inside our function. Enter the ref keyword:

static void Main(string[] args)
{
    int number = 20;
    AddFive(ref number);
    Console.WriteLine(number);
    Console.ReadKey();
}

static void AddFive(ref int number)
{
    number = number + 5;
}

As you can see, all we've done is added the ref keyword to the function declaration as well as to the call function. If you run the program now, you will see that the value of number has now changed, once we return from the function call.

 

Student 2 (in pair)

Function parameters

The first thing that we will take a look at, is the out and ref modifiers. C#, and other languages as well, differ between two parameters: "by value" and "by reference". The default in C# is "by value", which basically means that when you pass on a variable to a function call, you are actually sending a copy of the object, instead of a reference to it. This also means that you can make changes to the parameter from inside the function, without affecting the original object you passed as a parameter.

With the ref and the out keyword, we can change this behavior, so we pass along a reference to the object instead of its value.

The out modifier

The out modifier works pretty much like the ref modifier. They both ensure that the parameter is passed by reference instead of by value, but they do come with two important differences: A value passed to a ref modifier has to be initialized before calling the method - this is not true for the out modifier, where you can use un-initialized values. On the other hand, you can't leave a function call with an out parameter, without assigning a value to it. Since you can pass in un-initialized values as an out parameter, you are not able to actually use an out parameter inside a function - you can only assign a new value to it.

Whether to use out or ref really depends on the situation, as you will realize once you start using them. Both are typically used to work around the issue of only being able to return one value from a function, with C#.

Example Code

1.   public static string GetNextNameByOut(out int id)  

2.   {  

3.       id = 1;  

4.       string returnText = "Next-" + id.ToString();  

5.       return returnText;   

6.   }  

7.   static void Main(string[] args)  

8.   {  

9.       int i = 0;  

10.     Console.WriteLine("Previous value of integer i:" + i.ToString());  

11.     string test = GetNextNameByOut(out i);  

12.     Console.WriteLine("Current value of integer i:" + i.ToString());  

13. }  

Output

 

Out in C# 

 

 

Appendix 2

 

 

 

 

Links:

1.      https://www.c-sharpcorner.com/uploadfile/955025/c-sharp-interview-questions-part4what-is-a-recursive-function-in/

 

2.      https://www.dotnetperls.com/recursion

 

3.      https://csharp.net-tutorials.com/basics/function-parameters/

 

4.      https://www.c-sharpcorner.com/UploadFile/ff2f08/ref-vs-out-keywords-in-C-Sharp/

5.       

 

 

 

 

 

 

 


 

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