Algorithmic programming language is a formal language used to write, implement, and study algorithms. Unlike most programming languages, algorithmic language is not tied to the architecture of the computer, does not contain details related to the device of the machine.

To study the basics of algorithmization, the so-called Russian algorithmic language(school algorithmic language), using words understandable to the student in Russian.

An Algol-like algorithmic language with Russian syntax was introduced by Academician A.P. Ershov in the mid-1980s as the basis for a "machineless" computer science course.

The main service words of the algorithmic language

Description of the algorithm

  • alg(algorithm)
  • arg(argument)
  • cut(result)
  • early(beginning) - the beginning of the algorithm
  • con(end) - end of the algorithm
  • given- initial data in any form
  • necessary is the goal of the algorithm

Data types:

  • whole(whole)
  • thing(real)
  • Sim(character)
  • litas(literal) - string
  • log(logical)
  • tab(table) - to designate an array
  • lengths(length) — number of array elements

Condition notation

  • if
  • otherwise
  • choice
  • value

Cycle designation

  • nc(start of cycle)
  • kts(end of cycle)
  • bye

Boolean functions and values ​​for making expressions

Input Output

  • input
  • conclusion

General view of the algorithm

1
2
3
4
5
6

alg name of the algorithm (arguments and results)
| given algorithm applicability conditions
| necessary goal of the algorithm
early description of intermediate values
| command sequence (algorithm body)
con

Part of the algorithm from the word alg to the word early is called the heading, and the part enclosed between the words early and con- the body of the algorithm.

In a sentence alg after the name of the algorithm, the characteristics are indicated in parentheses ( arg, cut) and value type ( whole, thing, Sim, litas or log) all input (arguments) and output (results) variables. When describing arrays (tables), a service word is used tab, padded with boundary pairs for each array element index.

In the algorithm entry keywords are usually underlined or in bold. Indentation is used to highlight logical blocks, and the pair words of the beginning and end of the block are connected by a vertical bar.

Basic Algorithmic Structures

A detailed description of the main algorithmic structures is given in this article. Below are templates for compiling these structures in an algorithmic language.
incomplete fork

| if condition
| | then actions
| all

Full fork

1
2
3
4
5

| if condition
| | then actions 1
| | otherwise action 2
| all

branching

1
2
3
4
5
6
7
8

| choice parameter
| | at value value 1
| | | actions 1
| | at value value 2
| | | action 2
| | otherwise
| | | default actions
| all

Loop with precondition

| nts bye condition
| | actions
| kts

Loop with postcondition

Writing an algorithm in an algorithmic (formal) language is called a program. Sometimes the very concept of an algorithm is identified with its notation, so that the words "algorithm" and "program" are almost synonymous. A slight difference lies in the fact that when mentioning an algorithm, as a rule, they mean the main idea of ​​its construction, which is common to all algorithmic languages. The program is always associated with writing the algorithm in a particular formal language.

When presenting the idea of ​​an algorithm, for example, when publishing it in a scientific article, it is not always advisable to use any particular programming language so as not to clutter up the presentation with irrelevant details. In such cases informal algorithmic language is used as close to natural as possible. This type of language is called pseudocode. It is not difficult for a specialist to rewrite a program from pseudocode into any particular programming language. Writing an algorithm in pseudocode is often clearer and more illustrative; it allows you to freely choose the level of detail, starting from a description in the most general terms and ending with a detailed presentation.

Pseudo codes are semi-formalized descriptions of algorithms in conditional algorithmic language, including both programming language elements and natural language phrases, common mathematical notation, and more.

Pseudocode is a system of notation and rules designed to uniformly write algorithms.

Pseudocode occupies an intermediate position between natural language and programming languages. On the one hand, it is close to a normal, natural language, so algorithms can be written and read in it like plain text. On the other hand, some formal constructions and mathematical symbolism are used in pseudocode, which brings the notation of the algorithm closer to the generally accepted mathematical notation.

Pseudocode usually contains some constructs that are native to programming languages. This facilitates the transition from writing in pseudocode to writing the algorithm in a programming language for a particular computer. In particular, in pseudocode, as well as in programming languages, there are auxiliary words, the meaning of which is determined once and for all. They are bolded in printed text and underlined in handwritten text.

General view of the algorithm:

alg name of the algorithm (arguments and results)

given algorithm applicability conditions

necessary goal of the algorithm

early description of intermediate values

command sequence(algorithm body)

Part of the algorithm from the word alg to the word early is called the heading, and the part enclosed between the words early and con - the body of the algorithm.

In a sentence alg after the name of the algorithm, in parentheses, the characteristics (arg, res) and value type (integer, real, sim, lit, or log) of all input (arguments) and output (results) variables are indicated. When describing arrays (tables), a service word is used tab, padded with boundary pairs for each array element index.

Sentence examples alg :

alg Volume and area of ​​the cylinder (arg w R, H, res w V, S)

alg KvUr Roots ( arg thing a, b, c, cut item x1, x2, res lit t)

alg Exclude element ( arg integer N, arg cut item tab A)

alg Diagonal ( arg integer N, arg whole tab A, cut lit. Answer)

Offers given and necessary not required. They are recommended to write statements that describe the state of the environment of the algorithm executor, for example:

alg Replacement(arg lit Str1, Str2, arg res lit Text)

given | the lengths of the substrings Str1 and Str2 are the same

need | everywhere in the line Text the substring Str1 is replaced by Str2

alg Number of maxima (arg integer N, arg real tab A, res integer K)

given | N>0

need | K - the number of maximum elements in table A

alg Resistance (arg real R1, R2, arg integer N, res real R)

given | N>5, R1>0, R2>0

need | R - circuit resistance

Here in the proposals given and necessary after the sign "|" comments are recorded. Comments can be placed at the end of any line. They are not processed by the translator, but they make it much easier to understand the algorithm.

The main service words of the algorithmic language:

alg (algorithm) sim (symbolic) given for yes

arg (argument) lit (literal) must from no

res(result) log(boolean) if to at

start (start) tab(table) then value select

end (end) nts (cycle start) otherwise and enter

integer (integer) kts (end of loop) all or output

real (real) length (length) not yet approved

Basic commands:

1. Assignment command. Used to evaluate expressions and assign their values ​​to variables. General form: A:= B, where the sign ":=" means a command to replace the previous value of the variable on the left side with the calculated value of the expression on the right side.

For example: a:= (b+c) * sin(Pi/4); i:= i+1.

Input and output commands.

input variable names (keyboard input)

conclusion variable names, expressions, texts. (data output to the screen)

Branch commands.

These commands provide, depending on the result of checking the condition (yes or no), the choice of one of the alternative ways of the algorithm. Each path leads to a common exit, so the algorithm will continue regardless of which path is chosen.

The branching structure exists in four main variants:

1. Team if - then;

if condition

then actions

2. Team if - then - otherwise;

if condition

then actions 1

otherwise action 2

3. Team choice;

Choice

at condition 1: actions 1

at condition 2: actions 2

. . . . . . . . . . . .

at condition N: actions N

4. Team choice is different.

Choice

at condition 1: actions 1

at condition 2: actions 2

. . . . . . . . . . . .

at condition N: actions N

otherwise N+1 actions

Cycle commands.

Provides repeated execution of a certain set of actions, which is called the loop body.

There are two commands for looping:

1. Cycle type Bye - Instructs to execute the body of the loop until the condition written after the word is met bye.

nc bye condition

loop body

(sequencing)

kts

2. Cycle type For - Instructs to execute the loop body for all values ​​of some variable (loop parameter) in the specified range.

nc for i from i1 before i2

loop body

(sequencing)

kts

PROGRAMMING LANGUAGES

Currently, there are several hundred actually used programming languages ​​in the world. Each has its own area of ​​application.

Any algorithm, as we know, is a sequence of instructions, after which it is possible to pass from the initial data to the result in a finite number of steps. Depending on the level of detail of the prescriptions, the level of the programming language is usually determined - the less detail, the higher the level of the language.

Programming language(algorithmic language) - a set of rules that determine which character sequences make up a program (syntactic rules) and which computations the program describes (semantic rules).

Programming languages ​​have the following characteristics:

  • Language level - is characterized by the complexity of the tasks solved with the help of this language.
  • The power of language - characterized by the number and variety of tasks, the algorithms for solving which can be written using this language.
  • Reliability - the language should provide a minimum of errors when writing programs. Moreover, the language must be wrong programs it was difficult to write.
  • Readability b - ease of perception of programs by a person. This characteristic is important in team work, when several people work with the same program texts.
  • completeness - characterizes the ability to describe a class of problems in a certain subject area.
  • Flexibility - characterizes the ease of expressing the necessary actions.

According to this criterion, the following levels of programming languages ​​can be distinguished:

  • machine;
  • machine-oriented (assemblers);
  • machine-independent (high-level languages).

Machine languages ​​and machine-oriented languages ​​are low-level languages ​​that require you to specify the fine details of the data processing process. High-level languages, on the other hand, mimic natural languages ​​using some spoken language words and common mathematical symbols. These languages ​​are more human-friendly.

High-level languages ​​are divided into:

  • procedural (algorithmic)(Basic, Pascal, C, etc.), which are intended for the unambiguous description of algorithms; to solve a problem, procedural languages ​​require explicitly writing down the procedure for solving it in one form or another;
  • brain teaser ( Prolog, Lisp, etc. ) , which are focused not on the development of an algorithm for solving the problem, but on a systematic and formalized description of the problem so that the solution follows from the compiled description;
  • object-oriented(Object Pascal, C++, Java, etc.), which are based on the concept of an object that combines data and actions on us. A program in an object-oriented language, solving a certain problem, essentially describes the part of the world related to this problem. The description of reality in the form of a system of interacting objects is more natural than in the form of interacting procedures.

The creation of a computer program includes the following stages:

§ analysis;

§ design;

§ programming;

§ testing and debugging;

§ exploitation.

To date, there are six generations of programming languages. Each of the subsequent generations in its functional capacity is qualitatively different from the previous one.

  • First generation: Machine languages. Appeared in the mid-40s of the XX century.
  • Second generation: Assemblers. In fact, these are the same machine languages, but more beautifully "wrapped". Appeared in the late 1950s
  • Third generation: procedural languages. Appeared in the early 1960s. This generation includes universal high-level languages ​​that can be used to solve problems from any area (for example, Algol-60).
  • Fourth generation: Languages ​​supporting complex data structures(e.g. SQL). Appeared in the late 60s of the XX century.
  • Fifth generation: Artificial intelligence languages(e.g. Prolog). Appeared in the early 70s of the XX century.
  • Sixth generation: Neural Network Languages(self-learning languages). Research work in this area began in the mid-1980s.

CONCLUSION

In order for a computer to perform a task, it must perform certain program. The program must be written according to strict rules, in a form accessible for processing on a computer. Such a set of rules is called a programming language or an algorithmic language. Knowing general principle building and writing programs on a computer, it is possible to solve almost any tasks necessary in the work on information processing of data.

Ministry of Education Russian Federation Perm State Technical University

department information technologies and automated systems

Vikentyeva O. L.

Abstract of lectures on the course "Algorithmic languages ​​and programming" (Fundamentals of the C ++ language, I semester)

Introduction

The first semester deals with the basic constructions of the C language and basic programming technology (structured programming).

Structured programming is a technology for creating programs that, by following certain rules, reduces development time and the number of errors, as well as facilitates the possibility of modifying a program.

1.1. Algorithm and program

An algorithm is an exact prescription that defines a computational process that goes from changing initial data to the final result, i.e. it is a recipe for achieving some goal.

A set of tools and rules for presenting an algorithm in a form suitable for execution computer is called a programming language, an algorithm written in this language is called a program.

First, an action algorithm is always developed, and then it is written in one of the programming languages. The text of the program is processed by special service programs - translators. Programming languages ​​are artificial languages. They differ from natural languages ​​in a limited number of "words" and very strict rules for writing commands (operators). The totality of these requirements forms the syntax of the programming language, and the meaning of each construction is its semantics.

1.2 Properties of the algorithm

1. Mass character: the algorithm should be applied not to one problem, but to a whole class of similar problems (an algorithm for solving a quadratic equation should solve not one equation, but all quadratic equations).

2. Efficiency: the algorithm should lead to a result in a specific number of steps (when dividing 1 by 3, a periodic fraction 0.3333(3) is obtained, to achieve the final result, it is necessary to specify the accuracy of obtaining this fraction, for example, up to 4 decimal places).

3. Definiteness (determinism) - each action of the algorithm should be clear to its performer (instruction for a household appliance in Japanese for a person who does not speak Japanese is not an algorithm, because it does not have the property of determinism).

4. Discreteness - the process must be described using indivisible

operations performed in each step (i.e. steps cannot be divided into smaller steps).

Algorithms can be represented in the following forms:

1) verbal description of the algorithm.

2) graphical description of the algorithm.

3) using an algorithmic programming language

1.2. Compilers and interpreters

FROM using a programming language, a text is created that describes a previously compiled algorithm. To get a working program, you need to translate this text into a sequence of processor instructions, which is done using special programs, which are called translators. There are two types of translators: compilers and interpreters. The compiler translates the text of a source module into machine code, which is called an object module, in one continuous process. At the same time, he first looks at the source code of the program in search of syntax errors. The interpreter executes the source module of the program in the mode operator by operator, according to

the course of work, translating each statement into machine language.

1.3 Programming languages

Different types of processors have different instruction sets. If a programming language is focused on a specific type of processor and takes into account its features, then it is called a low-level programming language. The lowest level language is assembly language, which simply represents each machine code instruction in the form of special symbols called mnemonics. With the help of low-level languages, very efficient and compact programs are created, because the developer gets access to all the capabilities of the processor. Because instruction sets for different models processors are also different, then each processor model has its own assembly language, and the program written in it can only be used in this environment. Such languages ​​are used to write small system applications, device drivers, and so on.

High-level programming languages ​​do not take into account the peculiarities of specific computer architectures, therefore created programs at the source level are easily transferred to other platforms if appropriate translators are created for them. Developing programs in high-level languages ​​is much easier than in machine languages.

The high level languages ​​are:

1. Fortran is the first compiled language created in 50s of the 20th century. It implemented a number of important programming concepts. For this language was created great amount libraries ranging from statistical suites to satellite management, so it continues to be used in many organizations.

2. COBOL - Compiled Language for Economic Calculations and Solutions business tasks developed in the early 60s. Cobol has implemented very powerful tools for working with large amounts of data stored on external media.

3. Pascal - created at the end 70s by the Swiss mathematician Niklaus Wirth specifically for teaching programming. It allows you to develop algorithmic thinking, build a short, well readable program, demonstrate the basic techniques of algorithmization, it is also well suited for the implementation of large projects.

4. BASIC - created in 60s also for teaching programming. There are compilers and interpreters for it, it is one of the most popular programming languages.

5. C - was created in the 70s was not initially considered as a mass programming language. It was planned to replace assembler in order to be able to create the same efficient and short programs, but not depend on a particular processor. It is similar to Pascal in many ways and has additional features to work with memory. It contains many applied and system programs, as well as operating system Unix.

6. C++ is an object-oriented extension of the C language created by Bjarne Stroustrup in 1980.

7. Java is a language that was created by Sun at the beginning 90s based on C++. It is designed to simplify the development of applications in C++ by eliminating low-level features from it. main feature language is that it is not compiled into machine code, but into platform-independent bytecode (each command occupies one byte). This code can be executed using an interpreter, the Java Virtual Machine (JVM).

2. The structure of the program in C++

A C program has the following structure: #preprocessor directives

. . . . . . . . .

# preprocessor directives function a ()

function operators in ()

operators

void main () //function with which program execution begins operators

descriptions

assignments

empty statement function

composite

transition

Preprocessor directives - control the transformation of program text before compiling it. The original program prepared in SI in the form text file, goes through 3 stages of processing:

1) preprocessor text conversion;

2) compilation;

3) layout (link editing or assembly).

After these three stages, the executable code of the program is formed. The task of prepro-

cessor - transformation of the text of the program before its compilation. Preprocessing rules are defined by the programmer using preprocessor directives. The directive starts with #. For example,

1) #define - indicates the replacement rules in the text. #define ZERO 0.0

Means that each use of the name ZERO in the program will be replaced by

2) #include< имя заголовочного файла>- is intended for inclusion in the program text of the text from the "Header files" catalog supplied with the standard libraries. Each C library function has a corresponding description in one of the header files. The list of header files is defined by the language standard. The use of the include directive does not include the corresponding standard bib.

library, but only allow you to insert descriptions from the specified header file into the text of the program. Library codes are connected at the link stage, i.e. after compilation. Although in header files contains all descriptions of standard functions, only those functions that are used in the program are included in the program code.

After preprocessing, no preprocessor directives remain in the program text.

The program is a set of descriptions and definitions, and consists of a set of functions. Among these functions, there must always be a function named main. Without it, the program cannot run. The function name is preceded by information about the type of the value returned by the function (the type of the result). If the function does not return anything, then the void type is specified: void main(). Each function, including main, must have a set of parameters, it can be empty, then (void) is indicated in brackets.

The function body follows the function header. The body of a function is a sequence of definitions, declarations, and executable statements enclosed in braces. Each definition, description, or statement ends with a semicolon.

Definitions - introduce objects (an object is a named memory area, a special case of an object is a variable) necessary to represent the data being processed in the program. An example is

int y = 10 ; //named constant float x ; //variable

Descriptions - notify the compiler about the properties and names of objects and functions described in other parts of the program.

Operators - define the actions of the program at each step of its execution

Example C program:

#include //preprocessor directive

test questions

1. What are the parts of a C++ program?

2. How is a definition different from a declaration?

3. List the stages of creating an executable program in C++.

4. What is a preprocessor?

5. What is a preprocessor directive? Give examples of preprocessor directives.

6. Write a program that prints the text "My first C++ program"

2. Basic facilities of the C++ language 2.1. The composition of the language

In the text in any natural language, four main elements can be distinguished: symbols, words, phrases and sentences. The algorithmic language also contains such elements, only words are called lexemes (elementary constructions), phrases - expressions, sentences - operators. Tokens are formed from symbols, expressions from lexemes and symbols, operators from symbols of expressions and lexemes (Fig. 1.1)

Rice. 1.1. Composition of the algorithmic language Thus, the elements of the algorithmic language are:

Identifiers are the names of C-program objects. Latin letters, numbers and underscores can be used in the identifier. Uppercase and lowercase letters are distinguished, for example PROG1, prog1 and Prog1 are three different identifiers. The first character must be a letter or underscore (not a number). Spaces in identifiers are not allowed.

Key (reserved) words are words that have a special meaning for the compiler. They cannot be used as identifiers.

- Operation signs are one or more symbols that define an operation on operands. Operations are divided into unary, binary and ternary according to the number of operands involved in this operation.

Constants are immutable values. There are integer, real, character and string constants. The compiler distinguishes a constant as a token (elementary construct) and assigns it to one of the types according to its appearance.

Separators - brackets, dot, comma, space characters.

2.1.1. Constants in C++

A constant is a token that represents a representation of a fixed numeric, string, or character value.

Constants are divided into 5 groups:

whole;

- real (floating point);

enumerated;

Symbolic;

String.

The compiler selects a lexeme and assigns it to one group or another, and then internally

three groups to a certain type according to its form of writing in the text of the program and according to the numerical value.

Integer constants can be decimal, octal, and hexadecimal. A decimal constant is defined as a sequence of decimal digits that does not start at 0 unless that number is 0 (examples: 8, 0, 192345). An octal constant is a constant that always starts with 0. The 0 is followed by octal digits (examples: 016 - decimal value 14, 01). Hexadecimal constants are a sequence of hexadecimal digits preceded by the characters 0x or 0X (examples: 0xA, 0X00F).

AT depending on the value of an integer constant compiler present it differently

in computer memory (i.e., the compiler will attribute the appropriate data type to the constant).

Real constants have a different form of internal representation in computer memory. The compiler recognizes such constants by their form. Real constants can be represented in two forms: fixed-point and floating-point. Fixed-point constant type: [digits].[digits] (examples: 5.7, .0001, 41.).Floating-point constant type: [digits][.][digits]E|e[+|-][digits ] (examples: 0.5e5, .11e-5, 5E3). In the notation of real constants, either an integer or a fractional part, or a decimal point, or a sign of an exponent with an exponent can be omitted.

Enumerated constants are introduced using the enum keyword. These are ordinary integer constants, which are assigned unique and easy-to-use notation. Examples: enum ( one=1, two=2, three=3,four=4);

enum (zero,one,two,three) - if you omit the signs = and numeric values ​​in the definition of enumerated constants, then the values ​​will be assigned by default. In this case, the leftmost identifier will receive the value 0, and each subsequent one will increase by 1.

enum( ten=10, three=3, four, five, six);

enum (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Satur-

Character constants are one or two characters enclosed in apostrophes. Character constants consisting of one character are of type char and occupy one byte in memory, character constants consisting of two characters are of type int and occupy two bytes. Sequences that begin with the \ sign are called escape sequences, they are used:

- To represent characters that do not have a graphical display, for example:

\a - sound signal,

\b - return one step, \n - line feed,

\t - horizontal tab.

- To represent characters: \ , ’ , ? , ” (\\, \’ ,\? ,\”).

- To represent characters using hexadecimal or octal codes (\073, \0xF5).

A string constant is a sequence of characters enclosed in quotes.

Control characters can also be used within strings. For example: "\nNew line",

“\n\”High-level algorithmic programming languages ​​\”” .

2.2. Data types in C++

The data displays the world around in the program. The purpose of the program is to process data. Data various types stored and processed differently. The data type defines:

1) internal representation of data in computer memory;

2) the set of values ​​that values ​​of this type can take;

3) operations and functions that can be applied to data of this type.

AT Depending on the requirements of the task, the programmer chooses a type for program objects. C++ types can be divided into simple and compound types. Simple types are types that are characterized by a single value. C++ defines 6 simple data types:

int (integer)

char (character)

wchar_t (wide character) bool (boolean) float (real)

double (double-precision real)

There are 4 type specifiers specifying the internal representation and range of standard types

short (short) long (long) signed (signed)

unsigned

2.2.1. type int

Values ​​of this type are integers.

The size of the int type is not defined by the standard, but depends on the computer and the compiler. For a 16-bit processor, 2 bytes are allocated for it, for a 32-bit processor, 4 bytes.

If there is a short specifier before int, then 2 bytes are allocated for the number, and if the specifier is long, then 4 bytes. The set depends on the amount of memory allocated for the object. allowed values, which the object can accept:

short int - occupies 2 bytes, hence has a range of -32768 ..+32767;

long int - occupies 4 bytes, hence has a range of -2 147 483 648..+2 147 483 647

The int type is the same as the short int type on 16-bit PCs and the long int type on 32-bit PCs.

The signed and unsigned modifiers also affect the set of valid values ​​an object can take:

unsigned short int - occupies 2 bytes, hence has a range of 0 ..65536; unsigned long int - occupies 4 bytes, therefore, has a range of 0..+4 294 967

2.2.2. type char

Values ​​of this type are elements of a finite ordered set of characters. Each character is assigned a number, which is called the character code. Under value character type 1 byte is allocated. The char type can be used with the signed and unsigned specifiers. Signed char data can store values ​​in the range -128 to 127. Unsigned char can store values ​​in the range 0 to 255. The encoding uses ASCII (American Standard Code foe International Interchange). Symbols with codes from 0 to 31 are service symbols and have independent meaning only in I/O statements.

Values ​​of type char are also used to store numbers from the specified ranges.

2.2.3. wchar_t type

Designed to work with a set of characters for which encoding is not enough 1 byte, such as Unicode. The size of this type, as a rule, corresponds to the short type. String constants of this type are written with an L prefix: L"String #1".

2.2.4. type bool

The bool type is called boolean. Its values ​​can take the values ​​true and false. The internal representation of false is 0, any other value is interpreted as true.

2.2.5. floating point types.

Internal representation real number consists of 2 parts: mantissa and exponent. In IBM-compatible PCs, float values ​​occupy 4 bytes, of which one bit is allocated for the sign of the mantissa, 8 bits for the exponent, and 24 for the mantissa.

Values ​​of double type occupy 8 bytes, 11 and 52 digits are allocated for the order and mantissa, respectively. The length of the mantissa determines the precision of the number, while the length of the exponent determines its range.

If the double type name is preceded by the long specifier, then bytes are allocated for the value.

2.2.6. void type

To the main types also include the void type. The set of values ​​of this type is empty.

2.3. Variables

A variable in C++ is a named area of ​​memory that stores data of a particular type. A variable has a name and a value. The name is used to refer to the area of ​​memory where the value is stored. Any variable must be declared before use. Examples:

General view of the description operator:

[memory class] type name [initializer];

The storage class can take on the following values: auto, extern, static, register. The storage class defines the lifetime and scope of the variable. If the storage class is not explicitly specified, then the compiler determines it based on the context of the declaration. The lifetime can be constant - during the execution of the program, or temporary - during the block. Scope is the part of the program text from which normal access to a variable is allowed. Usually scope is the same as scope. Except when there is a variable with the same name in the inner block.

Const - indicates that this variable cannot be changed (named constant). When describing, you can assign an initial value to a variable (initialization). Memory classes:

auto is an automatic local variable. The auto specifier can only be specified when defining block objects, for example, in the body of a function. Memory is allocated to these variables when the block is entered and freed when the block is exited. Outside the block, such variables do not exist.

extern is a global variable, it is located elsewhere in the program (in another file or later in the text). Used to create variables that are available in all program files.

static is a static variable, it exists only within the file where the variable is defined.

register - similar to auto, but the memory for them is allocated in the processor registers. If this is not possible, then the variables are treated as auto.

int a; //global variable void main()(

int b;//local variable

extern int x;//variable x is defined elsewhere static int c;//local static variable a=1;//assignment to global variable

int a;//local variable a

a=2;//assignment to local variable::a=3;//assignment to global variable

int x=4;//define and initialize x

In the example, the variable a is defined outside of all blocks. The scope of the variable a is the entire program, except for those lines where the local variable a is used. Variables b and c are local, their scope is block. The lifetime is different: the memory under b is allocated when entering the block (because the default memory class is auto), it is freed when it exits. The variable with (static) exists while the program is running.

If variables are not explicitly initialized when they are defined, the compiler sets global and static variables to zero. Automatic variables are not initialized..

The variable name must be unique within its scope.

A variable declaration can be done either as a declaration or as a definition. The declaration contains information about the storage class and type of the variable, and the definition, together with this information, instructs to allocate storage. In the example extern int x; - declaration, and the rest - definitions.

2.4. Signs of operations in C++

Operation signs provide the formation of expressions. Expressions consist of operands, operator signs, and parentheses. Each operand is, in turn, an expression or a special case of an expression - a constant or a variable.

Unary operations

& get address of operand

* Referencing an address (dereference)

- unary minus, changes the sign of the arithmetic operand

++ Unit increase:

prefix operation - increments the operand before it is used

postfix operation increments an operand after it has been used

int a=(m++)+n; // a=4,m=2,n=2

int b=m+(++n);//a=3,m=1,n=3

decrease by one:

prefix operation - reduces the operand to its use

postfix operation decrements an operand after it has been used

calculation of the size (in bytes) for an object of the type that

has an operand

has two forms

sizeof expression

sizeof(float)//4

sizeof(1.0)//8 since real constants are default

An educational algorithmic language is a means for writing algorithms in a form intermediate between writing an algorithm in a natural (human) language and writing in a computer language (programming language).

The advantages of the educational algorithmic language include its simplicity, as well as the fact that the algorithm is written in Russian using a certain limited number of words, the meaning and method of use of which are strictly defined. These words are called function words.

In order to distinguish service words from other words of the language, they are underlined when writing.

An algorithm entry in a learning algorithmic language consists of a heading and an algorithm body. The body of the algorithm is enclosed between the keywords early and con and is a sequence of algorithm commands. The title includes the name of the algorithm, reflecting its content, lists of input data (arguments) and results.

The attribute of the header of the algorithm is the keyword alg.

So, the algorithm written in the educational algorithmic language has the following form:

alg algorithm name

arg list of initial data

cut result list

algorithm command sequence

It is advisable to start studying the school algorithmic language with the assignment command, it is one of the main commands.

It is written like this:

<переменная> := <выражение>

The sign ": =" is read "assign".

In the case when the value to which the value is assigned is included in the right side of the command, the following happens:

1) the value of the expression written on the right side of the assignment command is calculated using the current values ​​of all the values ​​included in this expression;

2) the variable is assigned a new calculated current value. In this case, the previous value of the variable is destroyed.

Therefore, the command b: = a + b means that the value of the variable a is added to the previous current value of b, and the result obtained becomes the new current value of b.

This example illustrates the three main properties of an assignment:

1) while the variable is not assigned a value, it remains undefined;

2) the value assigned to the variable is stored in it until the next assignment of a new value to this variable;

3) a new value assigned to a variable replaces its previous value.

Now let's get acquainted with the basic structures, let's start with such an operation as "follow". It is formed by a sequence of actions following one after another:

act 1

act 2

. . . . . . . . .

action n

Next, consider the basic "branch" structure. It provides, depending on the result of checking the condition (yes or no), the choice of one of the alternative ways of the algorithm. Each path leads to a common exit, so the algorithm will continue regardless of which path is chosen. The branching structure exists in four main variants:



1. if-then;

if condition

then actions

2. if-then-else;

if condition

then actions 1

otherwise action 2

choice

atcondition 1: actions 1

atcondition 2: actions 2

. . . . . . . . . . . .

at condition N: actions N

{otherwiseN+1 actions}

And finally, the basic structure of the cycle using the school algorithmic language will look like this.

In schools, to study the basics of algorithmization, the so-called. school algorithmic language (educational algorithmic language), using words understandable to the student in Russian. Unlike most programming languages, an algorithmic language is not tied to the architecture of a computer, does not contain details related to the device of a machine.

Examples

The algorithm in the algorithmic language in general terms is written in the form:

alg name of the algorithm (arguments and results) given algorithm applicability conditions necessary goal of the algorithm early description of intermediate values ​​| command sequence (algorithm body) con

In the writing of the algorithm, the keywords were usually underlined or highlighted in bold. Indents were used to highlight logical blocks, and the pair words of the beginning and end of the block were connected by a vertical bar.

An example of calculating the sum of squares:

alg Sum of squares ( arg whole n, cut whole S) given| n > 0 necessary| S = 1*1 + 2*2 + 3*3 + … + n*n early whole i | input n; S:=0 | nc for i from 1 to n | | S:= S + i * i | kts | conclusion"S=", S con

E-workshop

To reinforce the theoretical study of programming in an algorithmic language, in 1985, specialists from the Mekhmat of Moscow State University created an editor-compiler "E-workshop"("E" - in honor of Ershov), which allows you to enter, edit and execute programs in an algorithmic language.

In 1986, a set of training worlds (performers) was released for the "E-practice": "Robot", "Drafter", "Two-legged", "All-terrain vehicle", which allow you to simply introduce the concepts of the algorithm. "E-workshop" was implemented on computers: Yamaha, Corvette, UKNC and was widely used.

This programming language has been constantly improved and a description of a later version of the "E-workshop" appeared in a 1990 textbook. The programming system "KuMir" ("Set of Educational Worlds"), which supports this textbook, was released by the InfoMir enterprise in 1990. The language of this system is also called "KuMir".

In 1995, "KuMir" was recommended by the Ministry of Education of the Russian Federation as the main educational material for the course "Fundamentals of Informatics and Computer Engineering" based on the textbook by A. G. Kushnirenko, G. V. Lebedev and R. A. Svorenya. .

Criticism

However, it should be noted that the algorithmic language, in the absence of details linking it directly to the computer architecture, nevertheless, refers to Algolo -like languages, implicitly teaches students to rely on the von Neumann architecture of machines. (Von Neumann architecture is a practical implementation of an earlier idea called Turing Machine. There are other ideas besides Turing's idea. The most popular of them is called Lambda Calculus: Alonzo Church worked on it. Lisp Machine is an architecture that is based on Lambda - calculus.)

Links

  • A. P. Ershov. Algorithmic language in the school course of the basics of informatics and computer technology. 05/07/1985
  • Forum on Russian programming languages ​​and development tools

Wikimedia Foundation. 2010 .

See what "Russian algorithmic language" is in other dictionaries:

    An algorithmic language is a formal language used to write, implement, or study algorithms. Every programming language is an algorithmic language, but not every algorithmic language is suitable for use as a language ... ... Wikipedia

    This term has other meanings, see Dragon (meanings). An example of a block diagram of an algorithm in the DRAKON language dragon of the DRAKON scheme (Friendly Russian Algorithmic Language That Provides Visibility) visual ... ... Wikipedia

    This term has other meanings, see Algorithmic language. A learning algorithmic language is a formal language used to write, implement, and learn algorithms. Unlike most programming languages, it is not tied to ... Wikipedia

    Algorithmic language (also Russian algorithmic language, RAYA) is a programming language used to write and study algorithms. When studying computer science in schools, to study the basics of algorithmization, the so-called. school algorithmic ... ... Wikipedia

    Educational programming language is a programming language designed to teach programming to specialists. Such a language must meet the main requirement: simplicity. The simpler it is, the faster a beginner will master it. The possibilities of such ... ... Wikipedia

    An example of a block diagram of an algorithm in the DRAKON language dragon diagrams DRAKON (Friendly Russian Algorithmic Language That Provides Visibility) is a visual algorithmic language created within the framework of the Buran space program. Development given language... Wikipedia