Menu
Is free
check in
home  /  Problems / What is the result of the execution of the operator. Writing a program code using procedures

What is the result of the execution of the operator. Writing a program code using procedures

The program code is shown in Fig. 4.3-9.

Option Strict On Option Explicit On Imports System.math Public Class Form1 "Input Function in TextBox Function VVod (Byval T As TextBox) AS Single Return CSNG (VAL (T.Text)) END FUNCTION" Output procedure in TextBox Sub Vivod (Byval Z As Single, Byval T As TextBox) T.Text \u003d CSTR (z) End Sub "Function for calculating the length of the length of the segment coordinates of two PUBLIC FUNCTION COVERTICS (BYVAL X1 AS SINGLE, _ BYVAL Y1 AS SINGLE, BYVAL X2 AS SINGLE, _ BYVAL Y2 AS SINGLE) AS SINGLE RETURN CSNG (SQRT (X2 - X1) ^ 2 + (Y2 - Y1) ^ 2)) END FUNCTION "Calculation procedure Perimeter and triangle area Sub PS (Byval X1 AS Single, ByVal Y1 AS Single, _ Byval X2 As Single, ByVal Y2 As Single, ByVal Y3 As Single, _ byref P as Single, BYREF S SINGLE) DIM A, B, C, PP AS SINGLE A \u003d FLOWLEDGE (X1 , Y1, X2, Y2) "Calling the F-│ Valley for Vott. B \u003d Location (X2, Y2, X3, Y3) C \u003d Flat cutting (x3, y3, x1, y1) p \u003d (a + b + C): pp \u003d p / 2 s \u003d csng ( SQRT (pp * (pp - a) * (pp - b) * (PP - C))) END Sub "Procedure for processing the event event button on the Button1 PRIVATE sub Button1_Click (Byval Sender As System.Object, _ ByVal E AS System. Eventargs) Handles Button1.Click Dim X1 As Single, X2 As Single, X3 As Single Dim Y1 As Single, Y2 As Single, Y3 As Single Dim AS Single Point, Poin AS Single X1 \u003d Vvod (TextBox1): x2 \u003d vvod (TextBox2 ): x3 \u003d vvod (TextBox3) y1 \u003d vvod (textbox6): y2 \u003d vvod (textbox7): y3 \u003d vvod (textbox8) PS (x1, y1, x2, y2, x3, y3, x2, x3, y3, lane) vivod TextBox4): vivod (PoE, TextBox5) End Sub Private Sub Button2_Click (Byval Sender As System.Object, _ ByVal E As System.EventArgs) Handles Button2.Click End Sub End Class

Execution of the application and obtaining results

The result is shown in Fig. 4.3-10.

Proof of the correctness of the result

A \u003d.
\u003d 2.82843 B \u003d
= 2

C \u003d \u003d 2 p \u003d a + B + C \u003d 6.828427; Pp \u003d p / 2 \u003d 3.414213 s \u003d \u003d 2


Control questions on the topic

"The structure of VB programs, modules and procedures.

Programming means of linear structure algorithms "

1. What is a mathematical model?

2. What are the main stages of solving tasks on a computer?

3. What stages of computer solutions are carried out without computer participation?

4. What do they call the mathematical model of an object or phenomenon?

5. What consecutive action is the process of developing the program?

6. What is called algorithm?

7. What basic properties should the algorithm have?

8. What are the ways to describe algorithms?

9. What graphic symbols are customized in the schemes of the algorithm?

10. How does the interpreter work?

11. How does the compiler work?

12. What algorithm is called linear?

13. What algorithm is called cyclic?

14. What algorithm is called branching?

15. What is the difference between the transmission of the results of functions and procedures?

16. Is it proves to obtain a plausible result correctness of the program?

17. What errors may not be detected if you do not check (view, scrolling)?

18. How does the program testing differ from its debugging?

19. Is it possible to prove the correctness of the program by testing?

20. At what stage of work on the program are the reference test results?

21. Name the main stages of the testing process.

22. What is the difference in syntactic errors from semantic?

23. What does the lack of messages of the machine on syntactic errors?

24. What types of errors The translator is not able to detect?

25. What is a program?

26. At what stage is the search and elimination of errors in the program?

27. What is a programming system?

28. What is the procedure?

29. What advantages has a program that has procedures?

30. What means of procedural programming are in VB?

31. How does data exchange between individual program procedures?

32. What are actual and formal parameters?

33. How to transfer as a parameter: constant, variable, expression?

34. How are global variables are used?

35. How are local variables used?

36. What is called formal parameters?

37. What is called actual parameters?

38. What happens when calling a procedure?

39. How can the parameters be transmitted to the procedure?

40. What parameters are transmitted by value?

41. What parameters are transmitted to?

42. What belongs to the means of procedural programming?

43. What is the result of the execution of the function?

44. How should I declare individual variables to inside the function they were local?

45. What operator is used for early exit from the function?

46. What is controlled when calling functions and procedures?

47. How needs to be declared formal parameters to transfer the parameter-variable by value?

48. How to declare formal parameters to transfer the variable parameter to?

49. How does the function procedure be called from the caller?

50. What could be the result of the procedure?

51. What operator is used for early exit from the procedure?

52. Where can there be descriptions of functions and procedures?

53. Where will the variable declared using the Public Operator?

54. Where can PRIVATE operator?

55. What is the comment and the rules of his record?

56. What values \u200b\u200bare variables at the beginning of the program?

57. Why are described (defined) procedures and functions?

58. How is the challenge procedures?

59. How is the feature call?


Similar information.


Operator - this is a language element asking full description The actions that must be executed. Each operator is a finished phrase of the programming language and defines some completely complete data processing phase. Operators may include service words, data, expressions and other operators. AT english language this concept denoted by the word "statement", meaning also "offer".

Each operator in any programming language has a certain syntax and semantic. Under syntaxis The operator is understood as the rules system (grammar), which defines its recording using the elements of the alphabet of this language, in which, along with various symbols, includes, for example, and official words. Under semantic The operator understand its meaning, i.e. Those actions that correspond to the recording of a particular operator. For example, writing i: \u003d i + 1is an example of a syntactically correct entry operator assignmentin the Pascal language, the semantics of which in this case is such: to extract the value of the memory cell corresponding to the variable i, fold it with one, the result is written to the same memory cell.

In most procedural programming languages, the set of operators is almost the same and consists of an assignment operator, selection operators, cycle operators, a procedure call operator, transition operators. Sometimes it is also isolated empty (no action) and composite operators. Many operators are a way of representing certain algorithmic structures (see " Algorithmic structures") In programming language. Consider groups of operators in more detail using the Pascal language syntax.

Application operator

Assignment is a computer action, as a result of which the variable receives the value of the calculated expression (it is placed in the corresponding variable memory cell). To describe such actions in programming languages \u200b\u200bexists application operator.

AT general The assignment operator is written as follows:

<переменная> <знак присваивания> <выражение>

For example, a combination of symbols is used in Pascal as an assignment sign: \u003d. In a number of other languages \u200b\u200b- a sign of equality.

The result of the execution of the assignment statement is to change the status of the data: all variables other than variablestanding in the left side of the assignment operator, do not change its value, and the specified variable Gets the value expressionsstanding in the right side of the assignment operator. In most cases, the type is required to expressions coincided with the type variable. If this is not the case, the operator is either considered syntactically incorrect, or a transformation of the type of expression to the type of variable is made (see " Data types” ).

Choice operators

In a different way, these operators call conditional operators. Conditional operators are used to program algorithms containing algorithmic construct branching.

There are several types of conditional operators in programming languages. A complete conditional operator corresponds to the algorithmic structure of full branch:

In the programming language, the corresponding conditional operator has the form:

iF B. then.S1. eLSE.S2.

If expression B.which is calculated at the beginning of the execution of the conditional operator, is "truth", the operator will be executed S1., otherwise, the operator S2.. Operators S1. and S2. Can be composite.

The algorithmic structure of incomplete branch is implemented using an incomplete conditional operator, which has the form:

iF B. then.S.

Here B. - logical expression, and S. - arbitrary operator. Operator S. It will be performed if the expression B is true.

If the conditional operator implements only two branches of choice ("yes" and "no"), then with operator option (case- Operator) You can program a multi-line structure. Option operator has the form:

case E. of.

Performed this operator So: the value of the expression E. It is searched for among the values \u200b\u200bof the operator listed V1, V2, ..., VNand if such a value is located, then the corresponding operator is performed S1, S2, ..., SN.

In different language programming languages, the syntax and even the semantics of the listed operators may differ, but the capabilities provided by the programmer with similar structures are about the same.

Example 1.In the article " Algorithmic structures"2 An example of writing an algorithm for solving a generalized square equation using branching structures was given. We give a fragment of the Pascal program, implementing the same algorithm:

if.a \u003d 0. then.

if.b \u003d 0. then.

iF C \u003d 0 then.writeln ("X - Any")

ELSE.writeln ("No roots")

ELSE.writeln (-C / B)

else Begin.

D: \u003d b * b - 4 * a * c;

if.D.< 0 then.writeln ("No roots")

Else Begin.

x1: \u003d -B + SQRT (D);

x2: \u003d -b - SQRT (D);

writeln (x1: 0: 2, "", x2: 0: 2)

Cycle operators

Cycle operators implement cyclic algorithmic structuresThey are used for action repeating repeatedly. In many programming languages \u200b\u200bthere are three types of cycle operators: "C above", "c post", "with the parameter".

The required and sufficient algorithmic structure for programming cycles is a cycle "with a precondition", so it can be called the main type of cycle. The operator of the cycle with the precondition has the form:

while B. do.S.

Operator S., for multiple execution of which the cycle is created, called body cycle. The execution of the operator of the cycle is reduced to the re-execution of the cycle body while the value of the logical expression B. True (as long as it is not false). In fact, such cycle operators implement the re-execution of conditional operators if.B. then.S, while truly condition B..

Example 2. Consider the use of such a cycle operator for counting the amount of numbers of natural number N.:

whileN\u003e 0 do Begin.

S: \u003d S + N mod.10;

N: \u003d N div10

In the cycle with the traffic police, the cycle body precedes the condition B. Unlike the cycle with the provantal herein, this is the condition of the end of the cycle. The operator of the cycle with the Pascal Pascal has the form:

repeat S. until. B.

With this organization cycle cycle cycle S. At least once will be completed.

Almost in all procedural languages \u200b\u200bexists cycle operator with parameter. It can be imagined schematically:

for< variable > E1. to.E2. step.E3. do.S.

Here is the value variable (Cycle parameter) varies from the value of E1 expression to E2 with E3 pitch. For each such value of the cycle parameter, the operator S. In the Pascal language, the concept of step in the description of this operator is absent, and the step itself for an integer cycle parameter can be equal to either 1 or -1. The operator "Cycle with the parameter" is used to program cycles with a predetermined number of repetitions. For programming iterative cycles (the number of repetitions of which is unknown in advance), it is not suitable.

Call Operator Procedure

In the article " Subrogram"It is described in detail about this form of subroutines as procedures. Standard Programming Language Subprograms, which are part of the subroutine libraries, as well as user subroutines described inside this unit are called using the operator. call procedure:

<имя процедуры>(E1, E2, ..., EN)

Here e1, e2, ..., en - variables or expressions actual parameters Appeals to the procedure. The most frequently used standard procedures are the input and output procedures (Read and Write in Pascal).

The procedure call is semantically equivalent to the execution of the block described as the body of the procedure, after transmitting the initial values \u200b\u200bof some variables (parameters) or replacing the names of some variables (parameters-variables) to the names of the actual variables specified when calling the procedure.

Example 3. Let us describe the ABC procedure:

procedure ABC (A, B: Integer; var.c: Integer);

Calling this procedure ABC (2.3, X) is equivalent to the actions block:

Transition operators

The most famous operator in this group is the unconditional transition operator goto.. If all or some existing operators of the program add tagsThe program becomes possible to use the transition operator:

goto.<метка>

The label in this case corresponds to the beginning of the operator from which the program must continue. Such an operator allows you to record algorithms in the programming language that have an arbitrarily complex structure. But often the use of unconditional transition is unnecessarily, because leads to a confusing, poorly read program. Practically the only meaningful application of the operator goto. It is a way out of several nested cycles, for example, when processing two-dimensional arrays.

Example 4. Let us need to determine whether in a two-dimensional array A element equal to 0:

fori: \u003d 1 to.N. do.

for j: \u003d 1 to. N. do.

iF a \u003d 0 then Begin.

1: if.b. then.write ("Have") eLSE.write (no);

The program developed by the rules of structural programming should not contain unconditional transition operators. The above program without using the operator goto. You can rewrite as follows:

while Not.b. And. (I.< N) do Begin.

while Not.b. And. (J.< N) do Begin.

if. a \u003d 0. then.b: \u003d True;

if.b. then.write ("Have") eLSE.write (no);

In this case, the structural program is less visual than the program with goto..

In programming languages, other transition operators can be identified. For example, in Pascal language: break(early interruption of the cycle, the transition to the operator to be performed after the cycle is completed), Continue.(early completion of the current iteration of the cycle and the transition to the next), eXIT(early interruption of the subroutine, output from it), halt.(early interrupt program, transition to its end). Similar operators exist in languages \u200b\u200bC, C ++, Java.

Composite operator

The composite operator is a group of operators enclosed in operator brackets (in Pascal - begin.end.; In C, C ++ - (...)).

The composite operator is entered in programming languages \u200b\u200bto facilitate the description of the design structures. For example, in the Pascal, the executable part of each block (program, procedure, function) is one composite operator. Exactly the body of any cycle operator consists of only one operator, perhaps composite. An alternative to the composite operator may be a service word denoting the end of a operator, for example, End if In the language of Basic.

The topic "Programming Language Operators" is usually studied only in the context of consideration of a specific programming language. If it is considered, it is important to show the connection of basic algorithmic structures and operators: algorithmic structures are recorded in the programming language using the appropriate operators. The exception in a sense is a consistent design, it determines the linear procedure for performing actions. Actions in a strictly linear program are implemented only by assignment operators and procedure call operators.

At the initial stage of training, schoolchildren have many problems. The first psychological barrier has to be overcome when studying the assignment operator. One of the main tasks that must be solved along with students is the exchange of two variable values. You can offer to schoolchildren to mentally solve the task, how to change the contents of two boxes, such as the desktop. Usually on this stage Discussions of the student guess that the third box (variable) is required to solve the problem. Nevertheless, when recording this algorithm, they are often confused, in which part of the assignment operator (left or right) should be the same variable.

Errors in the recording of arithmetic and logical expressions arise due to ignorance of the seniority of operations, which are used in the expression. At the same time, under operations are not only the arithmetic, but also the comparison operations and logical ligaments, and in the C language and the operation of the assignment, which is very unusual for schoolchildren. The situation is complicated by the fact that in different programming languages, the same operations have different relative priorities. You should also pay attention to the conformity of variable and expression types in the left and right parts of the assignment operator (see " Data types”).

When mastering selection operators, it is useful to offer schoolchildren to program the algorithm containing a multi-step structure, both using a combination of conditional operators and using the selection operator.

Example. In an integer variable N. The age of a person in years is introduced. Print phrase " I'm k years", Replacing the word years old on the year or of the year depending on the number K.. We give two solutions to this problem:

if. (K. mod.100) iN.

then. Writeln ("Me", k, "years")

case K. mod. 10 of.

0.5..9: Writeln ("Me", k, "years");

1: writeln ("me", k, "year");

2..4: Writeln ("Me", k, "year");

vAR K, N: Integer;

readln (k); N: \u003d K MOD 10;

if. (K. mod.100) iN.

then. Writeln ("Me", k, "years") eLSE.

if. N \u003d 1. then.writeln ("Me", k, "year")

if. (n\u003e \u003d) and.(N.<= 4)

then.writeln ("Me", k, "year")

eLSE. Writeln ("Me", k, "years")

When considering the cycle operators, it is useful to propose the same task to program three different ways using three cycle operators, and vice versa, under the task condition, learn how to determine exactly which operator of the cycle is the most suitable in one way or another.

The procedure call operator only at first glance is simple. It is important to explain the rules for transmitting parameters into procedures and functions, the difference between variables and parameters and parameters values \u200b\u200b(in the latter case, we can transmit not only the name of the variable, but also a constant or even the expression of the appropriate type). Formal and actual parameters must match the types, but not by name, which is far from obvious to students.

The study of the conditional and especially composite operator is a good reason to talk to students about writing programs. For the Pascal language, there are several common ways to write structured programs, but they all contain indents for the placement of nested structures. Important to record programs and comments.

In the previous paragraph, we met with the structure of the program in Pascal, learned to describe the data, considered the assignment operator. This is enough to record the data conversion program. But the result of these transformations will not be visible.

To display data from RAM on the monitor screen, the WRITE output operator is used:

Here in parentheses the output list is placed - the list of expressions whose values \u200b\u200bare displayed. It may be numeric, symbolic and logical expressions, including variables and constants.

An arbitrary set of characters enclosed in apostrophes is considered a string constant. The row constant may contain any characters dialed on the keyboard.

Example. The WRITE operator ("S \u003d", S) is performed as follows:

  1. symbols enclosed in apostrophes are displayed on the screen: S \u003d
  2. the value of the variable stored in the range of RAM is displayed on the screen named s.

If the value of the variable S is equal to 15 and it has an integer type, then the screen will appear: S \u003d 15.

If the value of the variable S is 15, but it has a real type, then the screen will appear: S \u003d L.5E + 01.

When executing the output statement, all elements of the output list are printed directly after each other. Thus, as a result of the work of the WRITE operator (1, 20, 300), the sequence of 120300 will be displayed on the screen, which will be perceived by us as the number of 120300, and not as three separate numerical constants. Make output data more accessible to perception in different ways:

Output format - This is the integer indicated after a colon defining how many positions on the screen should take the output value. If the numbers are among less than the positions reserved below the screen, then the free positions are complemented by spaces to the left of the number. If the number specified in the output format is less than necessary, it will automatically be increased to the minimum necessary.

For the output of a real number in a fixed-semicolon format in the output list, two parameters are specified for each expression:

  1. total number of positions assigned to the number;
  2. the number of positions in the fractional part of the number.

When executing a new WRITE operator, the output continues in the same line. To transition to a new line, the Writeln operator is used. There are no other differences between Write and Writeln operators.

4.2.2. First program in Pascal

Taking advantage of the considered operators, we will make a program that calculates the length of the circle and the area of \u200b\u200bthe radius circle of 5.4 cm.

The source data in this problem is the radius: R - 5.4 cm. The result of the program must be the value of the C - the length of the circle and S - the area of \u200b\u200bthe circle. C, S and R - the values \u200b\u200bof the real type.

The initial data and results are associated with relations known from the math rate: C \u003d 2πr, S \u003d πr +. The program implementing calculations on these formulas will look:

This program is true and solves the task. By running it on execution, you will receive the following result:

Nevertheless, the program compiled by us has a significant drawback: it finds the length of the circle and the area of \u200b\u200bthe circle for the only radius value (5.4 cm).

In order to calculate the circle length and the circle area for another radius value, you will need to make changes directly to the text of the program, namely to change the assignment statement. Amendments to an existing program at least not always convenient (for example, when a big and assignment program is a lot). Below you will get acquainted with the operator that allows you to enter the source data during the program, without resorting to changing the text of the program.

4.2.3. Entering data from keyboard

To enter the variable memory variables, the READ input operator is used:

When executing the READ operator, the computer enters the data standby mode: the user must enter the data from the keyboard and press the ENTER key. Several values \u200b\u200bof variable numeric types can be entered through a space or a comma. When entering symbolic variables, the space and comma are perceived as symbols, so it is impossible to put them.

The first user-entered value of the variable is placed in a memory cell, the name of which is located first in the input list, etc. Therefore, the types of entered values \u200b\u200b(input flow) must match the types of variables specified in the variable descriptions section.

Example. Let

vAR I, J: Integer; x: Real; A: CHAR;

We assign variables i, j, x, and values \u200b\u200b1, 0, 2.5 and "a". To do this, we use the READ (I, J, X, X, A) operator and organize the input stream in one of the following ways:

Here we not only used various separators (space, comma), but the input stream was represented in the form of one, two and four lines.

To enter data from the keyboard, you can also use the READLN statement, which differs from the READ statement only in that after its execution, the cursor goes to a new string.

Improve the N_1 program by organizing data entry in it using the READ operator. And so that the user knows what the program is intended for, and I understood what exactly the computer expects from it, we will withdraw the appropriate text messages using the Writeln operator:

The result of the improved program:

Now our program can calculate the circumference length and the area of \u200b\u200bthe circle for any value r. In other words, it solves a non-a single task, but a whole class of tasks. In addition, the source data and the output of the results obtained are clearly organized in the program. This provides user interface friendly.

The most important thing

To enter the variable values \u200b\u200bof variables, the READ and READLN entry operators are used.

To display data from RAM on the monitor screen, the Write and Writeln output operators are used.

Entering the source data and output of the results must be organized clear and convenient; This provides user interface friendly.

Questions and tasks

  1. Write down the operator, providing during the program to enter the value of the Summa variable.
  2. An integer variable I, y, K must be assigned a value of 10, 20 and 30, respectively. Write the input operator corresponding to the input stream:
      a) 20 10 30
      b) 30 20 10
      c) 10 30 20
  3. Describe the variables required to calculate the triangle area along its three to the parties, and record the operator that provides the input of the necessary source data.
  4. What is the result of the execution of the operator?
      a) write (a)
      b) Write (1 A ")
      c) Write (1 A \u003d 1, a)
  5. What type has a variable F if, after executing the WRITE (F) operator, the next number was displayed on the screen?
      a) 125.
      b) 1.25e + 2
  6. How can you display a real number in a fixed-semicolon format?
  7. Record the operators input two numbers and output them in the reverse order.
  8. Dan fragment program:

    read (a); Read (b); C: \u003d A + B; Write (A, B); Write (C)

    Simplify it by reducing the number of input and output operators.

  9. Dan fragment program:

    a: \u003d 10; B: \u003d a + l: a: \u003d b-a; Write (a, b)

    What numbers will be displayed on the computer screen?

  10. Write a program that calculates the area and the perimeter of the rectangle along its two sides.

"Printer for printing plastic cards" - the ability to place twice as many information on one plastic card. Cost. Printer for printing plastic cards. Zebra P110i / P120i. Overview of the model range. Economical full-color printers for printing plastic cards. High performance Wide selection of additional coding devices.

"PC peripheral devices" are peripheral devices. Printers. Record. Digital cameras. Hierarchy of means of connection. Video adapters. Classification PU. Universal sequential tire. CD-R. Selection options. Built-in flash. Pioneer. Nature. Modem. VideoTerminal. Scanners. PC peripheral devices. Classification of muscular.

"Input and informance tools" - scanner. Plotter. CRT. Printers. Keyboard. Digital cameras and cameras. Functions. Universal input device. Information input and information output. Graphics tablet. Mouse.

"Information output devices" is a computer device. The greater the resolution of the monitor, the higher the image quality. Disadvantages of inkjet printers: high ink consumption; High cost of refueling. Flat monitors on liquid crystals (LCD) are compact and do not have radiation. Information output devices. The monitor is a universal information output device.

"Printers" are local. Thermoblock, stove, fuser - a knot in which the toner came into the paper. Laser. Matrix (needle). Over time, they lose their properties and are subject to regular replacement by a specialist. Inkjet. Network. Changes by the user. Printer features. Developer, Media, Developer - the smallest metal particles carrying toner on the photoman.

"I / O subsystem" is an interrupt point. Tables. Continuous placement. Attribute. Permissions to access files. Hosted list of indexes. Data. Physical organization. Direct memory access. Index-serial file. Mounting. Input-output controlled by interrupts. Permissions to access catalogs. Organization of parallel work.

Total in the subject of 27 presentations