User defined procedures and functions presentation 2 variant (1)
Оценка 4.6

User defined procedures and functions presentation 2 variant (1)

Оценка 4.6
pptx
02.05.2020
User defined procedures and functions  presentation 2 variant (1)
User defined procedures and functions presentation 2 variant (1).pptx

User defined procedures and functions

User defined procedures and functions

User defined procedures and functions

Algorithmization and Programming

LEARNING OBJECTIVES write a code in the programming language using functions and procedures

LEARNING OBJECTIVES write a code in the programming language using functions and procedures

LEARNING OBJECTIVES

write a code in the programming language using functions and procedures

Lesson objectives 10.4.1.1 Write code in a programming language using functions and procedures

Lesson objectives 10.4.1.1 Write code in a programming language using functions and procedures

Lesson objectives

10.4.1.1 Write code in a programming language using functions and procedures

Success criteria
Describes the function / procedure parameters
Uses function / procedure when solving problems
Creates its own function / procedure to solve practical problems

The concepts of function and method

The concepts of function and method

The concepts of function and method

Function is a part of a program that has its own name. This name can be used in the program as a command (this command is called a function call). When a function is called, the commands of which it consists are executed. A function call can return a value (similar to an operation) and therefore can be used in an expression along with operations.
A method is a function that is part of a class that can perform operations on data of this class. In the Java language, the entire program consists only of classes and functions can be described only inside them. That is why all functions in the Java language are methods.

Concept of method Methods are always defined inside classes: minOfTwoNumbers - is the method we defined in the

Concept of method Methods are always defined inside classes: minOfTwoNumbers - is the method we defined in the

Concept of method

Methods are always defined inside classes:



minOfTwoNumbers - is the method we defined in the Main class, let's consider it.
public - access type (the method can be called from another class). There are other types of access, for example private (the method is available only inside the class) and protected.
static - means that the method is static, it belongs to the class Main, and not to a specific instance of the class Main. We can call this method from another class like this: Main.minOfTwoNumbers ().

Parsing programm code public class { public static (type parameter1, type parameter2) { } public static void main(String[] args) { //Your program code is here

Parsing programm code public class { public static (type parameter1, type parameter2) { } public static void main(String[] args) { //Your program code is here

Parsing programm code

public class {
public static (type parameter1, type parameter2) {
}
public static void main(String[] args) {
//Your program code is here.
}
}

Parsing program code in lines 3 through 11, the minOfTwoNumbers method is described

Parsing program code in lines 3 through 11, the minOfTwoNumbers method is described

Parsing program code

in lines 3 through 11, the minOfTwoNumbers method is described.
on lines 5-9, a and b are compared
on line 13, the method is called to determine the minimum of two numbers (4 and -6).

Functions (Subprograms) Self-contained routines that are identified by a name and have the same structure as main()

Functions (Subprograms) Self-contained routines that are identified by a name and have the same structure as main()

8

Functions (Subprograms)

Self-contained routines that are identified by a name and have the same structure as main().
They are executed when they are called (calling their names).
main() is also a function but a special one.

Procedures (void Functions) Functions return a value (see later)

Procedures (void Functions) Functions return a value (see later)

9

Procedures (void Functions)

Functions return a value (see later).
If a function is declared a void it does not return a value, and is called a procedure.
void is a special data-type.

void main()
{
………

}

int main()
{
………
return 0;
}

Top-Down Design #include using namespace std; //

Top-Down Design #include using namespace std; //

10

Top-Down Design

#include
using namespace std;
// Global declaration section
………

void One()
{
………
}

float Two(float x)
{
………
return ??;
}

void main()
{
………
}

Declaration section
and
function definition

Main
program

Include
libraries

Procedure structure void ( ) {

Procedure structure void ( ) {

11

Procedure structure

void ()
{

. . .

}

Example: #include using namespace std; void

Example: #include using namespace std; void

12

Example:

#include
using namespace std;

void Builder() {
cout << ” * ” << endl;
cout << ” * * ” << endl;
cout << ” * * ” << endl;
cout << ”*******” << endl;
cout << ”* *” << endl;
cout << ”* *” << endl;
cout << ”* *” << endl;
cout << ”*******” << endl;
cout << endl;
}

void Gardener() {
cout << ” * ” << endl;
cout << ” *** ” << endl;
cout << ” ***** ” << endl;
cout << ”*******” << endl;
cout << ” * ” << endl;
cout << ” * ” << endl;
cout << ” * ” << endl;
cout << endl;
}

void main() {
Builder();
Builder();
Gardener();
Gardener();
}

*
* *
* *
*******
* *
* *
* *
*******

*
* *
* *
*******
* *
* *
* *
*******

*
***
*****
*******
*
*
*

*
***
*****
*******
*
*
*

Executed when we call them

Tasks Create a method that defines a maximum of two numbers

Tasks Create a method that defines a maximum of two numbers

Tasks

Create a method that defines a maximum of two numbers.

System.out.println("max = "+maxOfTwoNumbers(0, -99));


Create a method to calculate the 3rd power of the number.
System.out.println("7*7*7 = "+Cube(7));

Материалы на данной страницы взяты из открытых истончиков либо размещены пользователем в соответствии с договором-офертой сайта. Вы можете сообщить о нарушении.
02.05.2020