Most often, instructions are written in the form of a record in an algorithmic language. It is necessary for the exact prescriptions of all steps and their execution. There are obvious differences between the school algorithmic language and programming languages. As a rule, not only a computer acts as an executor in the first version, but also another device that is capable of performing work. Any program written in an algorithmic language does not have to be done by technology. The implementation of all instructions in practice is a purely separate issue. The description of the algorithm in the algorithmic language will also be considered below. It will help to understand the device of this system.

Studying at school

Often in schools, an algorithmic language, most commonly known as a learning language, is taught. It has received large-scale distribution due to the fact that it uses the words that are most understandable to any student. A similar language with syntax in Russian was introduced long ago, namely in the mid-1980s. It was used to give a foundation to schoolchildren and teach them a computer science course without a computer. This language was published in 1985 in one of the textbooks. It was also reprinted several times for special books that were intended for teaching in grades 9 and 10. The total circulation of the publication amounted to 7 million copies.

Algorithm writing sequence

First of all, you need to write down the letter combination ALG. The name of the algorithm follows. Then, after START, you need to describe a series of commands. The KOH operator means the end of the program.

Description of the algorithm in algorithmic language:

ALG Company

START

rotate 90 degrees to the left

KOH

When writing keywords must be underlined or bold. Indentation should be used to indicate logical blocks, and if there are pairs of start and end words, use vertical bar, which denotes a connection.

Drawing up algorithms

Old records can be used to write new instructions. Such instructions are called auxiliary. Such an algorithm can be any of all described, compiled earlier. There is also a possibility that this system will use an additional algorithm, which itself has received a reference to auxiliary systems.

Often, when creating an instruction, there is a need to use only one algorithm as an additional one. That is why records can often be complex and cumbersome. But it is worth noting that the ability to make a referral is easier than rewriting the same records several times.

That is why in practice a standard auxiliary algorithm is often used, which is constantly subordinate to the user. An instruction can have a reference, both to itself and to any other. Algorithmic language commands are designed for such actions. Such instructions are called recursive.

The bind-to-self command resides within the system itself. Such recursion is direct. An indirect one is one where the algorithm is called in any other auxiliary instruction.

Algorithms that have a certain sequence of commands can constantly change depending on the results of executing special parts of the program. Such systems are called branching. In order to create them, you must use a special branch command. It has an abbreviated and complete spelling scheme. Often there are cyclic algorithms that execute special instructions several times.

E-workshop

In order to improve the study of the theory of grammatical language, the professionals of the Mekhmat of Moscow State University in 1985 created a special compiler. It was called "E-workshop". With it, it was possible to enter, modify and execute programs. A certain set of performers was released the following year. We are talking about "Robot", "Drafter", "Two-legged", "ATV". This allowed simple and easy implementation of the algorithms. This compiler has become very popular and has been used on some computers. Enough for a long time This programming language has been improved and changed. In 1990, a later version of it appeared in a textbook.

Idol

Now the school algorithmic language is experiencing its second birth, after a special package "Kumir" was developed for Windows and Linux. The system operates with several performers. Classic among them are "Robot", "Drafter". The same package is included in the installation linux file"School". This system was developed specifically by order of the Russian Academy of Sciences. It is distributed free and freely. Over the past few years, the described language has been actively proposed to be used in the USE as one of the

Language Assignment

Algorithmic language used to solve a fairly wide range of problems. It is suitable for mastering both mathematical and exercises in other subjects. It should be noted that it is also used to make it easier for students to study similar topics.

Differences between machine and algorithmic languages

The most famous representative of machine-dependent languages ​​is "Assembler". During programming on it, a person must clearly indicate to the translator, thanks to special operators, which memory cells should be filled or transferred. Since the syntax of "Assembler" is as close as possible to the computer form of writing, it is rather difficult to study it. That is why the algorithmic language is taught at school, as well as at the beginning of programming in the first year of higher education.

Standard Features

The algorithmic language has special standard functions that have received the status of "built-in". It is thanks to them that you can easily write many operations with numbers and expressions without performing routine entries. The program in algorithmic language is quite simple. Regular functions can allow you to calculate the square root, logarithms, modulus, and so on. The most popular built-in methods are the following:

  • absolute module abs(X);
  • square root sqrt(X);
  • natural and ln(X), lg(X);
  • minimum and maximum min (X,Y), max (X, Y);
  • trigonometric functions sin(X), cos(X), tg(X), ctg(X).

Thanks to this, any programmer or just a person who is learning how to work with an algorithmic language will be able to easily write a mathematical problem without resorting to inventing a bicycle. Thus, it should be noted that this language is quite convenient. It is easy to understand and also very easy to understand. No wonder it was included in the school curriculum. Students enjoy learning it.

An algorithm is an exact and understandable order for the performer to perform a sequence of actions aimed at solving the problem.

The name "algorithm" comes from the Latin form of the name of the Central Asian mathematician al-Khwarizmi - Algorithmi. Algorithm is one of the basic concepts of computer science and mathematics.

An algorithm executor is some abstract or real (technical, biological or biotechnical) system capable of performing the actions prescribed by the algorithm.

The performer is characterized by:

elementary actions;

command system;

The environment (or setting) is the "habitat" of the performer. For example, for the performer Robot from a school textbook, the environment is an infinite cellular field. Walls and shaded cells are also part of the environment. And their location and the position of the Robot itself determine the specific state of the environment.

Each executor can execute commands only from some strictly specified list - the executor's command system. For each command, applicability conditions must be specified (in which environment states the command can be executed) and the results of command execution are described. For example, the "up" command of the Robot can be executed if there is no wall above the Robot. Its result is the displacement of the Robot by one cell up.

After calling the command, the executor performs the corresponding elementary action.

Executor failures occur if a command is called when the environment state is invalid for it.

Usually, the performer knows nothing about the purpose of the algorithm. It executes all received commands without asking "why" and "why" questions.

In computer science, the universal executor of algorithms is the computer.

The main properties of the algorithms are as follows:

Understandability for the performer -- i.e. The executor of the algorithm must know how to execute it.

Discreteness (discontinuity, separation) - i.e. the algorithm should represent the process of solving the problem as a sequential execution of simple (or previously defined) steps (stages).

Certainty -- i.e. each rule of the algorithm must be clear, unambiguous and leave no room for arbitrariness. Due to this property, the execution of the algorithm is mechanical in nature and does not require any additional instructions or information about the problem being solved.

Efficiency (or finiteness). This property is that the algorithm must lead to the solution of the problem in a finite number of steps.

Mass character. This means that the algorithm for solving the problem is developed in a general form, i.e. it should be applicable to a certain class of problems that differ only in the initial data. In this case, the initial data can be selected from a certain area, which is called the area of ​​applicability of the algorithm.

In practice, the following forms of representation of algorithms are most common:

verbal (records in natural language);

graphic (images from graphic symbols);

pseudocodes (semi-formalized descriptions of algorithms in a conditional algorithmic language, including both programming language elements and natural language phrases, generally accepted mathematical notation, etc.);

programmatic (texts in programming languages).

The verbal way of writing algorithms is a description of the successive stages of data processing. The algorithm is given in an arbitrary presentation in natural language.

For example. Write down an algorithm for finding the greatest common divisor (GCD) of two natural numbers.

The algorithm may be as follows:

set two numbers;

if the numbers are equal, then take any of them as an answer and stop, otherwise continue the algorithm;

determine the largest of the numbers;

replace the larger of the numbers with the difference between the larger and smaller of the numbers;

repeat the algorithm from step 2.

The described algorithm is applicable to any natural numbers and should lead to the solution of the problem. See for yourself by using this algorithm to determine the greatest common divisor of 125 and 75.

The verbal method is not widely used for the following reasons:

such descriptions are not strictly formalizable;

suffer from verbosity of records;

allow ambiguous interpretation of individual prescriptions.

The graphical way of presenting algorithms is more compact and visual than the verbal way.

In a graphical representation, the algorithm is depicted as a sequence of interconnected functional blocks, each of which corresponds to the execution of one or more actions.

Such graphic representation is called a flowchart or flowchart.

In the flowchart, each type of action (inputting initial data, calculating expression values, checking conditions, controlling the repetition of actions, finishing processing, etc.) corresponds to a geometric figure represented as a block symbol. Block symbols are connected by transition lines that determine the order in which actions are performed.

Table 1 lists the most commonly used characters.

The "process" block is used to designate an action or sequence of actions that changes the value, form of presentation or placement of data. To improve the visibility of the diagram, several separate processing blocks can be combined into one block. The presentation of individual operations is quite free.

The "decision" block is used to designate control transitions by condition. Each "decision" block must specify the question, condition, or comparison that it defines.

The "modification" block is used to organize cyclic structures. (The word modification means modification, transformation). Inside the block, a cycle parameter is written, for which its initial value, boundary condition, and step of changing the parameter value for each repetition are indicated.

The "predefined process" block is used to indicate calls to auxiliary algorithms that exist autonomously in the form of some independent modules, and for calls to library routines.

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

It occupies an intermediate position between natural and formal languages.

On the one hand, it is close to ordinary 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 does not adopt strict syntactic rules for writing commands inherent in formal languages, which makes it easier to write an algorithm at the design stage and makes it possible to use a wider set of commands designed for an abstract executor. However, in pseudocode, there are usually some constructs that are inherent in formal languages, which facilitates the transition from writing in pseudocode to writing an algorithm in a formal language. In particular, in pseudocode, just like in formal 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. There is no single or formal definition of pseudocode, so various pseudocodes are possible, differing in the set of service words and basic (basic) structures.

An example of pseudocode is the school algorithmic language in Russian notation (school AL), described in the textbook by A.G. Kushnirenko et al. "Fundamentals of Informatics and Computer Engineering", 1991. This language will be referred to simply as "algorithmic language".

Basic service words

General view of the algorithm:

alg algorithm name (arguments and results)

given the conditions for the applicability of the algorithm

need the goal of the algorithm

start description of intermediate values

| command sequence (algorithm body)

The part of the algorithm from the word alg to the word start is called the heading, and the part enclosed between the words start and end is called the body of the algorithm.

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

Examples of alg sentences:

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

alg Roots QvUr(arg w, b, c, res w x1, x2, res lit t)

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

alg Diagonal(arg integer N, arg integer tab A, res lit Otvet)

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

arg substitution(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 sentences it is given and it is 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.

Algorithms can be represented as some structures consisting of separate basic (i.e. main) elements.

Naturally, with such an approach to algorithms, the study of the basic principles of their construction should begin with the study of these basic elements.

To describe them, we will use the language of algorithm schemes and the school algorithmic language.

The logical structure of any algorithm can be represented by a combination of three basic structures:

following,

branching,

A characteristic feature of basic structures is that they have one input and one output.

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

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

Algorithmic language - it is a system of notation and rules for uniformly and accurately recording algorithms and their execution. An algorithmic language is a means for writing algorithms in an analytical form, intermediate between writing an algorithm in a natural (human) language and writing in a computer language (programming language).

There is a difference between the concepts of "algorithmic language" and "programming languages". First of all, a program written in an algorithmic language is not necessarily intended for a computer. The practical implementation of an algorithmic language is a separate issue in each specific case.

Like every language, an algorithmic language has its own vocabulary. The basis of this dictionary is the words used to record the commands included in the command system of the executor of a particular algorithm. Such commands are called simple commands. In an algorithmic language, words are used whose meaning and method of use are set once and for all. These words are called official. The use of service words makes the recording of the algorithm more visual, and the form of presentation of various algorithms is uniform.

An algorithm written in an algorithmic language must have a name. It is desirable to choose the name so that it is clear which solution the given algorithm describes. To highlight the name of the algorithm, the service word ALG (ALGORITHM) is written in front of it. Behind the name of the algorithm (usually with newline) record his commands. To indicate the beginning and end of the algorithm, its commands are enclosed in a pair of service words BEGIN (START) and KON (END). Commands are written sequentially.

ALG - the name of the algorithm

a series of algorithm instructions

For example, an algorithm that determines the movement of a robot performer may look like this:

ALG - to_warehouse

When constructing new algorithms, algorithms compiled earlier can be used. Algorithms that are entirely used as part of other algorithms are called auxiliary algorithms. Auxiliary can be any algorithm from among the previously compiled. It is also not excluded that an auxiliary algorithm in a certain situation may be an algorithm that itself contains a link to auxiliary algorithms.

Very often, when compiling algorithms, it becomes necessary to use the same algorithm as an auxiliary one, which, moreover, can be very complex and cumbersome. It would be irrational, starting work, to compose and memorize such an algorithm each time for its subsequent use. Therefore, in practice, the so-called built-in (or standard) auxiliary algorithms are widely used, i.e. such algorithms that are constantly available to the performer. The appeal to such algorithms is carried out in the same way as to the "ordinary" auxiliary algorithms. A robot performer can have a built-in auxiliary algorithm moving to a warehouse from anywhere in the working field; for the BASIC programming language executor, this is, for example, the built-in "SIN" algorithm.

An algorithm may refer to itself as a helper, in which case it is called recursive. If the command to call the algorithm to itself is in the algorithm itself, then such recursion is called straight. There are cases when the recursive call of this algorithm comes from auxiliary algorithm, which is accessed in this algorithm. This kind of recursion is called indirect. Direct recursion example:

ALG - movement

traffic

Algorithms, during the execution of which the sequence of commands is determined depending on the results of checking certain conditions, are called branching. To describe them in an algorithmic language, a special compound command is used - the command branching. With regard to the robot performer, the condition may be to check if the robot is at the edge of the working field (edge ​​/ not_edge); checking for the presence of an object in the current cell (yes/no) and some others:

IF condition IF condition IF edge

TO series1 TO series TO right

ELSE series2 EVERYTHING ELSE forward

The following is an algorithmic language entry for the select command, which is a development of the branch command:

AT Condition 1: Series 1

AT Condition 2: Series 2

AT N condition: N series

ELSE Series N+1

Algorithms, during the execution of which individual instructions or a series of instructions are executed repeatedly, are called cyclic. To organize cyclic algorithms in an algorithmic language, a special compound cycle command is used. It corresponds to flowcharts of the “iteration” type and can take the following form:

BYA condition NC

series BEFORE condition