Windows.  Viruses.  Laptops.  Internet.  Office.  Utilities.  Drivers

“Printer for printing plastic cards” - The ability to place twice as much information on one plastic card. Price. Printer for printing plastic cards. ZEBRA P110i/ P120i. Review model range. Economical full-color printers for printing plastic cards. High performance Wide range of optional encoding devices.

“PC peripherals” - Peripheral devices. Printers. Record. Digital cameras. Hierarchy of connection tools. Video adapters. Classification of PU. Universal serial bus. CD-R. Selection options. Built-in flash. Pioneers. Nature. Modem. Video terminal. Scanners. PC peripherals. Classification of mouse-shaped.

“Means for input and output of information” - Scanner. Plotter. CRT. Printers. Keyboard. Digital cameras and cameras. Functions. Universal input device. Information input and output devices. Graphics tablet. Mouse.

“Information output devices” - Computer device. The higher the resolution of the monitor, the higher the image quality. Flaws inkjet printers: High ink consumption; High cost of refilling. Flat-panel liquid crystal (LCD) monitors are compact and emission-free. Information output devices. The monitor is universal device information output.

"Printers" - Local. Thermoblock, stove, fuser - a unit in which toner is baked into paper. Laser. Matrix (needle-shaped). Over time, they lose their properties and must be regularly replaced by a specialist. Jet. Network. Changed by the user. Printer characteristics. Developer, carrier, developer - the smallest metal particles that transfer toner to the photo roll.

"I/O subsystem" - Breakpoint. Tables. Continuous placement. Attribute. File permissions. Linked list of indexes. Data. Physical organization. Direct memory access. Indexed-sequential file. Mounting. Interrupt driven I/O. Directory access permissions. Organization of parallel work.

There are a total of 27 presentations in the topic

The first operand - "expression1" - can be any expression whose result is a value of type bool . If the result is true , then the operator specified by the second operand, that is, "expression2", is executed.

If the first operand is equal to false , then the third operand is executed - “expression3”. The second and third operands, that is, "expression2" and "expression3", must return values ​​of the same type and must not be of type void . The result of executing a conditional statement is the result of "expression2" or the result of "expression3", depending on the result of "expression1".

Operator usage restrictions

The operator based on the value of "expression1" must return one of two values ​​- either "expression2" or "expression3". There are a number of restrictions on these expressions:

  1. You cannot mix a user-defined type with a simple type or enumeration. It is acceptable to use NULL for a pointer.
  2. If the value types are simple, then the type of the operator will be the maximum type (see Type Coercion).
  3. If one of the values ​​is an enumeration type and the second is a numeric type, then the enumeration is replaced by int and the second rule applies.
  4. If both values ​​are enum values, then their types must be the same, and the type of the operator will be an enumeration.

Limitations for custom types (classes or structures):

  1. the types must be the same or one must inherit from the other.
  2. if the types are not the same (inheritance), then the child is implicitly cast to the parent, that is, the type of the operator will be the type of the parent.
  3. You cannot mix object and pointer—either both expressions are objects or pointers. It is acceptable to use NULL for a pointer.

Note

Be careful when using a conditional operator as an argument to an overloaded function, since the type of the conditional operator's result is determined at the time the program is compiled. And this type is defined as the larger type of the types "expression2" and "expression3".

Example:

void func(double d) ( Print ("double argument: " ,d); )
void func(string s) ( Print ("string argument: " ,s); )

bool Expression1=true;
double Expression2=M_PI;
string Expression3= "3.1415926" ;

void OnStart()
{
func(Expression2);
func(Expression3);

func(Expression1?Expression2:Expression3);
func(!Expression1?Expression2:Expression3);// get a compiler warning about explicit casting to string type
}

// Result:
// double argument: 3.141592653589793

// string argument: 3.141592653589793
// string argument: 3.1415926

Operator is an element of language that specifies Full description action to be performed. Each operator is a complete phrase of a programming language and defines some completely completed stage of data processing. Operators can include function words, data, expressions, and other operators. IN English language this concept denoted by the word “statement”, which also means “proposal”.

Each operator in any programming language has a specific syntax And semantics. Under syntax operator is understood as a system of rules (grammar) that determines its recording using the elements of the alphabet of this language, which, along with various symbols, includes, for example, function words. Under semantics operator understand its meaning, i.e. those actions that correspond to the record of a particular operator. For example, record i:= i + 1 is an example of a syntactically correct notation assignment operator V Pascal language, whose semantics is in this case is as follows: extract the value of the memory cell corresponding to the variable i, add it with one, write the result 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, loop operators, a procedure call operator, and jump operators. Sometimes empty (no action) and compound operators are also distinguished. Many operators are a way of representing certain algorithmic constructs (see “ Algorithmic designs” ) in a programming language. Let's look at operator groups in more detail using the Pascal language syntax.

Assignment operator

Assignment is a computer action as a result of which a variable receives the value of a calculated expression (it is placed in the memory cell corresponding to the variable). To describe such an action in programming languages, there is assignment operator.

IN general view The assignment operator is written like this:

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

For example, in Pascal the symbol combination is used as an assignment sign: =. In a number of other languages ​​it is an equals sign.

The result of executing the assignment operator is a change in the state of the data: all variables other than variable, located on the left side of the assignment operator, do not change their meaning, but the specified variable gets the value expressions, appearing on the right side of the assignment operator. In most cases it is required that the type expressions matched the type variable. If this is not the case, then the operator is either considered syntactically incorrect, or the type of the expression is converted to the type of the variable (see “ Data types” ).

Selection Operators

These operators are called differently conditional statements. Conditional statements are used to program algorithms that contain an algorithmic branching construct.

There are several types of conditional statements in programming languages. The full conditional statement corresponds to the algorithmic structure of full branching:

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

if B then S1 else S2

If the expression B, which is calculated at the beginning of the execution of the conditional statement, has the value “true”, then the statement will be executed S1, otherwise - operator S2. Operators S1 And S2 may be compound.

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

if B then S

Here B is a logical expression, and S- arbitrary operator. Operator S will be executed if expression B is true.

If a conditional operator implements only two choice branches (“yes” and “no”), then using variant operator (case-operator) you can program a multi-branch structure. The variant operator looks like:

case E of

Performed this operator like this: the meaning of the expression E searched among the values ​​listed in the operator record V1, V2, …, Vn, and if such a value is found, then the corresponding operator is executed S1, S2, …, Sn.

In different programming languages, the syntax and even semantics of the listed operators may differ, but the capabilities provided to the programmer by such constructions are approximately the same.

Example 1. In the article “ Algorithmic designs”2 an example of writing an algorithm for solving a generalized quadratic equation using branching constructions was given. Here is a fragment of a program in Pascal that implements the same algorithm:

if a = 0 then

if b = 0 then

if c = 0 then writeln("x - any")

else writeln("no roots")

else writeln(-c/b)

else begin

D:= b*b - 4*a*c;

if D< 0 then writeln("no roots")

else begin

x1:= -b + sqrt(D);

x2:= -b - sqrt(D);

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

Loop statements

Loop operators implement cyclic algorithmic structures; they are used for actions that are repeated many times. In many programming languages, there are three types of loop operators: “with precondition”, “with postcondition”, “with parameter”.

A necessary and sufficient algorithmic structure for programming loops is a loop “with a precondition,” so it can be called the main type of loop. The loop operator with a precondition looks like:

while B do S

Operator S, for which a loop is created for repeated execution is called body of the loop. Execution of a loop operator is reduced to repeated execution of the loop body until the value of the logical expression B true (until it becomes false). In fact, similar loop statements implement repeated execution of conditional statements if B then S, while the condition is true B.

Example 2. Consider the use of such a loop operator to calculate the sum of the digits of a natural number N:

while N>0 do begin

S:= S + N mod 10;

N:=N div 10

In a loop with a postcondition, the body of the loop precedes condition B. Unlike a loop with a precondition, here B is the condition for ending the loop. The loop operator with postcondition in Pascal has the form:

repeat S until B

With this organization of the cycle, the body of the cycle S must be executed at least once.

In almost all procedural languages ​​there is loop operator with parameter. It can be represented schematically like this:

for< variable > E1 to E2 step E3 do S

Here's the meaning variable(cycle parameter) changes from the value of the expression E1 to E2 in steps of E3. For each such value of a loop parameter, the operator S is executed. In the Pascal language, the concept of a step is absent in the description of this operator, and the step itself for an integer loop parameter can be equal to either 1 or –1. The “loop with parameter” operator is used to program loops with a specified number of repetitions. It is not suitable for programming iterative loops (the number of repetitions of which is unknown in advance).

Procedure call operator

In the article “ Subroutines” describes in detail this type of subroutine, such as procedures. Standard programming language routines that are included in one of the routine libraries, as well as user routines described inside this block, are called using the operator procedure call:

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

Here E1,E2,…,En are variables or expressions that represent actual parameters access to the procedure. The most commonly used standard routines are the input and output routines (read and write in Pascal).

Calling a procedure is semantically equivalent to executing the block described as the body of the procedure, after passing into it the initial values ​​of some variables (value parameters) or replacing the names of some variables (variable parameters) with the names of the actual variables specified when calling the procedure.

Example 3. Let us describe procedure abc:

procedure abc(a,b:integer; var c: integer);

Calling this procedure abc(2,3,x) is equivalent to an action block:

Jump Operators

The most famous operator in this group of operators is the unconditional jump operator goto. If you add to all or some of the existing program statements tags, then in the program it becomes possible to use a transition operator of the form:

goto<метка>

The label in this case corresponds to the beginning of the statement from which program execution should continue. This operator allows you to write algorithms in a programming language that have an arbitrarily complex structure. But often the use of unconditional transition is unjustified, because leads to a confusing, hard to read program. Almost the only meaningful use of the operator goto is an exit from several nested loops at once, for example, when processing two-dimensional arrays.

Example 4. Suppose we need to determine whether there is two-dimensional array a element equal to 0:

for i:= 1 to N do

for j:= 1 to N do

if a = 0 then begin

1: if b then write("is") else write("no");

A program developed according to the rules of structured programming should not contain unconditional jump operators. The above program without using the operator goto can be rewritten as follows:

while not b and(i< N) do begin

while not b and(j< N) do begin

if a = 0 then b:= true;

if b then write("is") else write("no");

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

Other jump operators may be defined in programming languages. For example, in Pascal: break(early interruption of the loop, transition to a statement that must be executed after the end of the loop), continue(early completion of the current loop iteration and transition to the next one), exit(early interruption of the subroutine, exit from it), halt(early interruption of the program, transition to its end). Similar operators exist in the languages ​​C, C++, and Java.

Compound operator

A compound statement is a group of statements enclosed in operator brackets (in Pascal - beginend; in C, C++ - (…)).

The compound operator was introduced into programming languages ​​to facilitate the description of language constructs. For example, in Pascal, the executable part of each block (program, procedure, function) is one compound statement. In exactly the same way, the body of any loop operator consists of only one operator, perhaps a compound one. An alternative to a compound operator can be a function word indicating the end of a particular operator, for example, END IF in Basic language.

The topic “Programming Language Operators” is usually studied only in the context of a specific programming language. When considering it, it is important to show the connection between basic algorithmic constructions and operators: algorithmic constructions are written in a programming language using the corresponding operators. The exception, in a sense, is the sequential design; it determines the linear order of actions. Actions in strict linear program are implemented only by assignment operators and procedure call operators.

On initial stage Schoolchildren have many problems learning programming. The first psychological barrier they have to overcome is when learning the assignment operator. One of the main tasks that you need to solve together with your students is swapping the values ​​of two variables. You can ask schoolchildren to mentally solve the problem of how to swap the contents of two drawers, for example, a desk. Typically, at this stage of the discussion, students realize that a third box (variable) is needed to solve the problem. However, when writing this algorithm, they often confuse which part of the assignment operator (left or right) a particular variable should appear in.

Errors in writing arithmetic and logical expressions arise due to ignorance of the precedence of operations that are used in the expression. At the same time, operations mean not only arithmetic, but also comparison operations and logical connectives, and in the C language the assignment operation, 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 correspondence between the types of the variable and the expression on the left and right sides of the assignment operator (see “ Data types”).

When mastering selection operators, it is useful to have students program an algorithm containing a multi-branch structure, both using a combination of conditional statements and using a selection operator.

Example. To an integer variable N Enter the person's age in years. Type the phrase “ I'm K years old”, replacing the word years on year or of the year depending on the number K. Here are two solutions to this problem:

if(k mod 100) in

then writeln("I am ",k," years old")

case k mod 10 of

0,5..9:writeln("I am ",k," years old");

1:writeln("I'm ",k," year old");

2..4:writeln("I'm ",k," years old");

var k, n: integer;

readln(k); n:= k mod 10;

if(k mod 100) in

then writeln("I am ",k," years old") else

if n=1 then writeln("I'm ",k," year old")

if(n >=) and(n<= 4)

then writeln("I'm ",k," years old")

else writeln("I am ",k," years old")

When considering loop operators, it is useful to suggest programming the same task in three different ways using three loop operators, and vice versa, based on the conditions of the problem, learn to determine which loop operator is most suitable in a particular case.

The procedure call operator is simple at first glance. Here it is important to explain the rules for passing parameters to procedures and functions, the difference between variable parameters and value parameters (in the latter case, we can pass not only the variable name, but also a constant or even an expression of the corresponding type). Formal and actual parameters must correspond in type, but not in name, which is far from obvious to students.

Studying the conditional and especially the compound statement is a good opportunity to talk to students about program writing style. There are several common ways to write structured programs in Pascal, but they all include indentation to accommodate nested structures. Important for recording programs and comments.

Data output
Outputting data from random access memory on the monitor screen:
write
(<выражение 1> ,< выражение 2> , ...,< выражение N>)
output list
Expressions - symbolic, numeric, logical,
including variables and constants
Example:
write("s=", s).
For s=15 the screen will show: s=15.
Information in quotation marks is displayed on the screen
without changes

Output organization options
Option
organization of withdrawal
No separators
Inference operator
write(1, 20, 300).
Result
120300
Add delimiters write (1, ’,’ , 20,
– commas
’, ’, 300)
1, 20, 300
Add delimiters write (1, ‘ ‘, 2, ‘ ‘, 3)
– spaces
1 20 300

Output Format
The output format allows you to set the number of positions
on the screen occupied by the displayed value.
write(s:x:y)
x - the total number of positions allocated for the number;
y - the number of positions in the fractional part of the number.
Inference operator
Execution result
operator
write(‘s=‘, s:2:0);
s=15
write(‘s=‘, s:3:1);
s=15.0
write(‘s=‘, s:5:1);
s=
writeln
15.0
- output from a new line!

First program
program n_1;
const pi=3.14;
var r, c, s: real;
begin
r:=5.4;
c:=2*pi*r;
Result of the program:
s:=pi*r*r;
writeln("c="", c:6:4);
writeln("s=", s:6:4)
Turbo Pascal
Version 7.0
end.
c =33.9120
s =91.5624

Keyboard input
Entering variable values ​​into RAM:
read
(<имя переменной1>, …, <имя переменной N>)
input list
Executing the read statement:
1) the computer goes into data standby mode:
2) the user enters data from the keyboard:
multiple variable values
numeric types can be entered
separated by space or comma;
when entering character variables
Spaces and commas cannot be used;
3) the user presses the Enter key.

Keyboard input
!
The input value types must match
variable types specified in the description section
variables.
var i, j: integer;x: real;a: char;
read(i, j, x, a);
options for organizing the input stream:
1 0 2.5 A 1,0 1
2.5, A 0
2.5
A
After the readln statement is executed, the cursor moves to
new line.

Improved program
program n_1;
const pi=3.14;
var r, c, s: real;
begin
writeln("Calculate the circumference and area of ​​a circle");
write("Enter r>>");
readln(r);
c:=2*pi*r;
Result of the program:
s:=pi*r*r;
writeln("c="", c:6:4);
Pascal Version 7.0
writeln("s=", s:6:4) Turbo
Calculating the circumference and area of ​​a circle
Enter r >> 8.5
end.
c =53.3800
s =226.8650

The most important
To enter variable values ​​into RAM
operators are used input read and readln.
To display data from RAM on the screen
The monitor uses the write and writeln output operators.
Input of initial data and output of results must
be organized clearly and conveniently; this ensures
user-friendliness of the user interface.

Questions and tasks
1) Given a program fragment:
a:=10; b:=a+1: a:=b–a; write (a, b)
What numbers will be displayed on the computer screen?
2) Describe the variables needed for the calculation
the area of ​​a triangle along its three sides, and
write a statement providing input
necessary initial data.
3) What is the result of executing the statement?
a) write (a)
b) write("a")
c) write("a=", a)
4) Integer variables i, j, k need to be assigned
respectively, the values ​​are 10, 20 and 30.
Write down the input statement corresponding to the input
stream:
a) 20 10 30
b) 30 20 10
c) 10,30,20

In the previous paragraph, we got acquainted with the structure of a program in Pascal, learned how to describe data, and looked at the assignment operator. This is enough to write a data conversion program. But the result of these transformations will not be visible to us.

To output data from RAM to the monitor screen, use the write output operator:

Here, in parentheses, an output list is placed - a list of expressions whose values ​​are printed. These can be numeric, symbolic and logical expressions, including variables and constants.

An arbitrary set of characters enclosed in apostrophes is considered a string constant. A string constant can contain any characters typed on the keyboard.

Example. The write ("s=" , s) statement is executed like this:

  1. Symbols enclosed in apostrophes are displayed on the screen: s=
  2. The value of the variable stored in a RAM cell named s is displayed on the screen.

If the value of the variable s is 15 and it is of integer type, then the screen will display: s=15.

If the value of the variable s is 15, but it is of real type, then the following will appear on the screen: s=l.5E+01.

When the output statement is executed, all elements of the output list are printed immediately after each other. Thus, as a result of the write (1, 20, 300) operator, the sequence of numbers 120300 will be displayed on the screen, which will be perceived by us as the number 120300, and not as three separate numeric constants. You can make the output data more accessible to perception in different ways:

Output Format is an integer indicated after the colon that determines how many positions on the screen the displayed value should occupy. If there are fewer digits in a number than the positions reserved for it on the screen, then the free positions are supplemented with spaces to the left of the number. If the number specified in the output format after the colon is less than necessary, it will automatically be increased to the minimum required.

To output a real number in fixed-point format, two parameters are specified in the output list for each expression:

  1. the total number of positions allocated for the number;
  2. the number of positions in the fractional part of the number.

When a new write statement is executed, the output continues on the same line. To jump to a new line, use the writeln operator. There are no other differences between the write and writeln statements.

4.2.2. First program in Pascal language

Using the operators discussed above, we will create a program that calculates the circumference and area of ​​a circle with a radius of 5.4 cm.

The initial data in this problem is the radius: r - 5.4 cm. The result of the program should be the values ​​C - the circumference and S - the area of ​​the circle. C, S and r are quantities of real type.

The initial data and results are related by relations known from the mathematics course: C = 2πr, S = πr +. A program that implements calculations using these formulas will look like:

This program is correct and solves the problem. When you run it, you will get the following result:

Still, the program we compiled has a significant drawback: it finds the circumference and area of ​​a circle for a single radius value (5.4 cm).

In order to calculate the circumference and area of ​​a circle for a different radius value, you will need to make changes directly to the program text, namely, change the assignment operator. Making changes to existing program, at least, is not always convenient (for example, when the program is large and there are many assignment operators). Below you will get acquainted with an operator that allows you to enter initial data while the program is running, without changing the program text.

4.2.3. Keyboard input

To enter variable values ​​into RAM, use the read input operator:

When the read statement is executed, the computer enters data-waiting mode: the user must enter data from the keyboard and press the Enter key. Multiple values ​​for numeric type variables can be entered separated by spaces or commas. When entering character variables, spaces and commas are treated as characters, so they cannot be entered.

The first variable value entered by the user is placed in the memory location whose name is located first in the input list, etc. Therefore, the types of input values ​​(input stream) must correspond to the types of variables specified in the variable description section.

Example. Let

var i, j: integer; x: real; a:char;

Let's assign the variables i, j, x, and the values ​​1, 0, 2.5 and "A". To do this, we will use the read (i, j, x, a) operator and organize the input stream in one of the following ways:

Here we not only used various delimiters (space, comma), but also represented the input stream as one, two and four lines.

You can also use the readln operator to enter data from the keyboard, which differs from the read operator only in that after it is executed, the cursor moves to a new line.

Let's improve program n_1 by organizing data entry in it using the read operator. And so that the user knows what the program is intended for and understands exactly what action the computer expects from him, we will display the corresponding text messages using the writeln operator:

The result of the improved program:

Now our program can calculate the circumference and area of ​​a circle for any value of r. In other words, it solves not a single problem, but a whole class of problems. In addition, the program clearly and conveniently organizes the input of initial data and the output of the results obtained. This ensures a friendly user interface.

The most important

To enter variable values ​​into RAM, the read and readln input operators are used.

To output data from RAM to the monitor screen, the write and writeln output operators are used.

Input of initial data and output of results should be organized clearly and conveniently; this ensures a friendly user interface.

Questions and tasks

  1. Write a statement that allows you to enter the value of the summa variable while the program is running.
  2. The integer variables i, y, k need to be assigned the values ​​10, 20 and 30, respectively. Write down the input statement corresponding to the input stream:
      a) 20 10 30
      b) 30 20 10
      c) 10 30 20
  3. Describe the variables needed to calculate the area of ​​a triangle based on its three sides, and write a statement that provides the required input data.
  4. What is the result of executing the statement?
      a) write (a)
      b) write (1 a ")
      c) write (1 a=1, a)
  5. What type is the variable f if, after executing the write (f) statement, the following number was displayed on the screen?
      a) 125
      b) 1.25E+2
  6. How can I display a real number in fixed point format?
  7. Write down the operators for entering two numbers and outputting them in reverse order.
  8. Here is a fragment of the program:

    read(a); read(b); c:=a+b; write(a, b); write (c)

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

  9. Here is a fragment of the program:

    a:=10; b:=a+l: a:=b-a; write (a, b)

    What numbers will be displayed on the computer screen?

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

If you notice an error, select a piece of text and press Ctrl+Enter
SHARE: