Basic mathematical functions in algorithmic language. An algorithmic language is a formal language used to write, implement, or learn algorithms. The main function words of the algorithmic language. The pseudocode is a system designated

School algorithmic language

Algorithmic language (also russian algorithmic language, PARADISE) is a programming language used for writing and learning algorithms. When studying computer science in schools, the so-called. school algorithmic language (educational algorithmic language), using words in Russian understandable to the student. Unlike most programming languages, the algorithmic language is not tied to the architecture of the computer, does not contain details related to the structure of the machine.

Examples of

An algorithm in an algorithmic language is generally written in the form:

alg algorithm name (arguments and results) given algorithm applicability conditions need the purpose of the algorithm early description of intermediate values \u200b\u200b| sequence of commands (algorithm body) con

In the notation of the algorithm, keywords were usually underlined or in bold. To highlight logical blocks, indents were used, and the paired words of the beginning and end of the block were connected with a vertical line.

An example of calculating the sum of squares:

alg Sum of squares ( arg intact n, cut intact S) given | n\u003e 0 need | S \u003d 1 * 1 + 2 * 2 + 3 * 3 + ... + n * n early intact i | input n; S: \u003d 0 | nts for i from 1 to n | | S: \u003d S + i * i | kts | conclusion "S \u003d", S con

E-workshop

To support the theoretical study of programming in an algorithmic language, the specialists of the Faculty of Mechanics and Mathematics of Moscow State University in 1985 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 educational worlds (performers) was released for the "E-workshop": "Robot", "Draftsman", "Two-leg", "All-terrain vehicle", which allow you to simply introduce the concepts of the algorithm. "E-workshop" was implemented on computers: Yamaha, Corvette, UKNTs and became widespread.

This programming language was constantly being refined and a description of a later version of the "E-workshop" appeared in the 1990 textbook. The programming system "Kumir" ("Set of Educational Worlds"), which supports this textbook, was published 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 teaching material for the course "Fundamentals of Informatics and Computer Engineering" based on the textbooks by A. G. Kushnirenko, G. V. Lebedev and R. A. Svoren. ...

Criticism

However, it should be noted that an algorithmic language, in the absence of details connecting it with the architecture of a computer directly, nevertheless, referring to Algol-like languages, implicitly teaches schoolchildren to rely on the von Neumann architecture of machines. (The von Neumann architecture is practical implementation an earlier idea called the Turing Machine. Besides Turing's idea, there are other ideas. The most popular of them is called Lambda calculus: Alonzo Church worked on it. A 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 computer science and computer technology. 05/07/1985
  • Forum on Russian programming languages \u200b\u200band development tools

Wikimedia Foundation. 2010.

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

    Algorithmic language is a formal language used to write, implement, or learn 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 Algorithmic language. Educational algorithmic language is a formal language used for writing, implementing and learning algorithms. Unlike most programming languages, it is not tied to ... Wikipedia

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

    Learning programming language A programming language designed for teaching. As such, languages \u200b\u200bsuch as BASIC and Pascal were developed. Developed for learning, ABC grew out of Python. Popular language, ... ... Wikipedia

    This article is being proposed for deletion. You can find an explanation of the reasons and the corresponding discussion on the Wikipedia page: To be deleted / September 28, 2012. While the discussion process is not completed, the article can ... Wikipedia

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

    This term has other meanings, see Idol. Kumir ... Wikipedia

    Edumandriva ... Wikipedia

    - (A set of educational Worlds or Mira Kushnirenko) a programming system designed to support the initial courses of computer science and programming in secondary and high schools. Based on a methodology developed in the second half of the 1980s ... ... Wikipedia

Books

  • Programming in the algorithmic language Kumir, edited by AG Kushnirenko, Anelikova L., Gusev O .. This manual is intended for teachers and students to support the initial courses of computer science and programming in secondary, high and high school. ... It covers the main steps and ...


Algorithm. School algorithmic language.

Algorithm - an accurate and understandable instruction to the performer to perform a sequence of actions aimed at solving the task.

  • 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.


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:

  • wednesday;

  • elementary actions;

  • command system;

  • refusals.

  • Wednesday (or setting) is the "habitat" of the performer.

  • Command system... Each executor can execute commands only from a certain strictly specified list - the executor's command system. For each command, applicability conditions must be specified (in what states of the environment the command can be executed) and the results of command execution must be described.

  • After calling the command, the executor performs the appropriate elementary action.

  • Refusals executor occur if a command is invoked when the environment state is invalid for it.


The main properties of the algorithms are as follows:

  • Intelligibility 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 should 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.

  • Effectiveness (or limb). 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 for a certain class of problems that differ only in the initial data. In this case, the initial data can be selected from a certain region, which is called the region of applicability of the algorithm.


Algorithm presentation forms:

  • 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.);

  • software (texts in programming languages).


Verbal way Algorithm records are a description of the sequential stages of data processing. The algorithm is set in free form in natural language.

  • For example. Write down the algorithm for finding greatest common divisor (gcd) two natural numbers. The algorithm can 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 larger of the numbers;

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

  • repeat the algorithm from step 2.


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

  • This graphical representation is called an algorithm diagram or block diagram.


Pseudocode is a system of notation and rules designed for a uniform notation of algorithms.

    The pseudocode does not accept the 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, pseudocode usually has some constructs inherent in formal languages, which makes it easier to move from writing in pseudocode to writing an algorithm in a formal language. In particular, in pseudocode, just as in formal languages, there are function words, the meaning of which is determined once and for all. They are highlighted in bold in printed text and underlined in handwritten text. There is no single or formal definition of pseudocode, therefore, various pseudocodes are possible, differing in the set of service words and basic (basic) constructions.

  • An example of pseudocode is a school algorithmic language in Russian notation (school AY),


Basic service words


General view of the algorithm:

  • alg algorithm name (arguments and results)

  • given algorithm applicability conditions

  • need the purpose of the algorithm

  • early description of intermediate values

  • command sequence (body

  • algorithm)


Part of the algorithm from the word alg to the word early called heading early and con - body algorithm.

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

  • In a sentence alg after the name of the algorithm, in parentheses are indicated specifications (arg, res) and value type (int, thing, sim, litor log) of all input (arguments) and weekend (results) variables... When describing arrays (tables), a special word is used tabsupplemented boundary pairs for each index of the array elements.


School AY teams

  • Assignment operator... Serves for evaluating expressions and assigning their values \u200b\u200bto variables. General form: A: \u003d B, where the ": \u003d" sign means the command replace the previous value of the variable on the left, by the calculated value of the expression on the right side.

  • For example, a: \u003d (b + c) * sin (Pi / 4); i: \u003d i + 1.

  • For data input and output use commands

  • input variable names

  • conclusion variable names, expressions, texts.

  • For branching apply commands if and choice, for organizing cycles - teams for and until


An example of recording an algorithm on a school language

  • alg Sum of squares ( arg intact n, cut intact S)

  • given | n\u003e 0

  • need | S \u003d 1 * 1 + 2 * 2 + 3 * 3 + ... + n * n

  • intact i

  • input n; S: \u003d 0

  • nts for i from 1 before n S: \u003d S + i * i

  • conclusion "S \u003d", S


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

  • 1. Basic structure following .


2. Basic structure branching .

  • Structure branching exists in four main variants:

  • if something;

  • if-then-otherwise;

  • choice;

  • choice is different.


2. Basic structure branching .


2. Basic structure branching .


3. Basic structure cycle.

  • Provides multiple execution some set of actions, which is called body of the cycle.


What concepts are used by algorithmic languages

  • Language concept defined in interaction syntactic and semantic rules. Syntactic rules show how a given concept is formed from other concepts and letters of the alphabet, and semantic rules define the properties of a given concept


The basic concepts in algorithmic languages \u200b\u200bare usually as follows.

  • Names (identifiers) - are used to denote program objects(variables, arrays, functions, etc.).

  • Operations ... Types of operations:

  • arithmetic operations +, -, *, / and others. ;

  • brain teaser operations and, or, not;

  • operations relations , = , = , ;

  • operation couplings (otherwise, "concatenation", "concatenation") character values \u200b\u200bof each other with the formation of one long string; represented by a "+" sign.

  • Data - values \u200b\u200bprocessed by the program... There are three main types of data: constants, variables and arrays.

  • Constants is data that is fixed in the text of the program and does not change during its execution.

  • Examples of constants:

    • numeric 7.5, 12;
    • brain teaser yes(true) , no(Lying);
    • symbolic "A", "+";
    • literary "abcde", "computer science", "" (empty string).
  • Transfers are designated by names and can change their values \u200b\u200bduring the execution of the program. Transfers are integers, real, logical, symbolic and literal.

  • Arrays are sequences of elements of the same type, the number of which is fixed and assigned the same name. The position of an element in the array is uniquely determined by its indices (one, in the case of a one-dimensional array, or several, if the array is multidimensional). Arrays are sometimes called tables.


Expressions

  • Expressions - are intended for performing the necessary calculations, they consist of constants, variables, function pointers (for example, exp (x)), united by operation signs.

  • Expressions are written as linear character sequences(without subscript and superscript characters, "multi-level" fractions, etc.), which allows you to enter them into the computer by sequentially pressing the corresponding keys on the keyboard.

  • Distinguish between expressions arithmetic, logical and string.

  • Arithmetic expressions are used to define a single numeric value... For example, (1 + sin (x)) / 2. The value of this expression at x \u003d 0 is 0.5, and at x \u003d p / 2 - one.

  • Boolean expressions describe some conditions that may or may not be met.... Thus, a boolean expression can only take two values \u200b\u200b- "true" or " lying" (yes or no). Consider as an example the logical expression x * x + y * y "true", and for x \u003d 2, y \u003d 2, r \u003d 1 - "Lying".

  • The values \u200b\u200bof string (literal) expressions - texts... They can include literal constants, literal variables and literal functions, separated by the concatenation operation sign. For example, A + B means appending line B to the end of line A. If A \u003d "bush", and B \u003d "green", then the meaning of the expression A + B is " green bush ".

  • Operators (commands). An operator is the largest and most meaningful concept of the language: each operator is a complete phrase of the language and defines some completely complete stage of data processing. The composition of the operators includes:

  • keywords;

  • data;

  • expressions, etc.

  • Operators are subdivided into executable and non-executable. Non-executable operators are used to describe data and program structure, and executable - to perform various actions (for example, an assignment operator, input and output operators, conditional operator, loop operators, procedure operator, etc.).


Calculations of frequently used functions are performed through subroutines called standard functions, which are preprogrammed and built into the language translator.


Table of standard functions of school algorithmic language


  • You can use constants, variables and expressions as arguments to functions. For example: sin (3.05) min (a, 5)

  • sin (x) min (a, b)

  • sin (2 * y + t / 2) min (a + b, a * b)

  • sin ((exp (x) +1) ** 2)

  • min (min (a, b),

  • min (c, d))


Arithmetic expressions are written according to the following rules:

  • You cannot omit the multiplication sign between factors and put two operation signs next to each other.

  • Array element indices are written in square (school AY, Pascal) or round (Basic) brackets.

  • The letters of the Latin alphabet are used to designate variables.

  • Operations are performed in order of precedence: first the calculation of functions, then raising to a power, then multiplication and division, and last of all addition and subtraction.

  • Operations of one seniority are performed from left to right... For example, a / b * c matches a / b * c. However, in school AY there is one an exception from this rule: exponentiation operations are performed from right to left. So, the expression 2 ** (3 ** 2) in school AY is calculated as 2 ** (3 ** 2) \u003d 512. In the QBasic language, the analogous expression 2 ^ 3 ^ 2 is calculated as (2 ^ 3) ^ 2 \u003d 64. And in the language Pascal the exponentiation operation is not provided at all, in Pascal x ^ y is written as exp (y * ln (x)), and x ^ y ^ z as exp (exp (z * ln (y)) * ln (x)).


Examples of writing arithmetic expressions


Typical errors in writing expressions:

  • a + sin x

  • (a + b) / c ** 3



Examples of writing logical expressions that are true when the specified conditions are met.


Write down according to the rules of the algorithmic language of expressions:


  • a + b / c + 1;

  • a ** b ** c / 2;

  • a / b / c / d * p * q;

  • 4/3 * 3.14 * r ** 3;

  • d * c / 2 / R + a ** 3;


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

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

An algorithm-like algorithmic language with Russian syntax was introduced into use by Academician A. P. Ershov in the mid-1980s, as the basis for a "machine-less" computer science course.

Basic function words of the algorithmic language

Algorithm Description

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

Data types:

  • intact (whole)
  • things (real)
  • sim (character)
  • litas (literal) - string
  • log (logical)
  • tab(table) - to denote an array
  • lengths (length) - number of array elements

Condition designation

  • if
  • otherwise
  • choice
  • meaning

Cycle notation

  • nts (start of cycle)
  • kts (end of cycle)
  • until

Boolean functions and values \u200b\u200bfor constructing expressions

Input Output

  • input
  • conclusion

General view of the algorithm

1
2
3
4
5
6

alg algorithm name (arguments and results)
| given algorithm applicability conditions
| need the purpose of the algorithm
early description of intermediate values
| sequence of commands (algorithm body)
con

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

In a sentence alg after the name of the algorithm in parentheses are the characteristics ( arg, cut) and value type ( intact, things, sim, litas or log) of all input (arguments) and output (results) variables. When describing arrays (tables), a special word is used tab, supplemented by boundary pairs for each index of array elements.

In an algorithm record, keywords are usually underlined or in bold. To highlight logical blocks, indentation is applied, and paired words of the beginning and end of the block are connected with a vertical line.

Basic algorithmic structures

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

| if condition
| | then actions
| all

Full fork

1
2
3
4
5

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

Branching

1
2
3
4
5
6
7
8

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

Loop with precondition

| nc bye condition
| | actions
| kts

Loop with postcondition

Ministry of Education of the Russian Federation Perm State Technical University

Department information technologies and automated systems

Vikentieva O. L.

Lecture notes for the course "Algorithmic languages \u200b\u200band programming" (Fundamentals of the C ++ language, I semester)

Introduction

In the first semester, the basic constructions of the C language and basic programming technology (structured programming) are considered.

Structured programming is a technology for creating programs that allows, by observing certain rules, to reduce development time and the number of errors, as well as to facilitate the possibility of program modification.

1.1. Algorithm and program

An algorithm is a precise prescription that determines the computational process that goes from variable initial data to the final result, that is, it is a recipe for achieving a goal.

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

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

1.2 Algorithm properties

1. Massiveness: 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 of 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. Certainty (determinism) - each action of the algorithm must be clear to its executor (the 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 at each step (i.e. steps cannot be broken down into smaller steps).

Algorithms can be presented in the following forms:

1) verbal description of the algorithm.

2) graphic description of the algorithm.

3) using an algorithmic programming language

1.2. Compilers and Interpreters

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

work progress, translating each operator 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 peculiarities, then it is called a low-level programming language. The lowest level language is assembly language, which simply represents each instruction in machine code as special symbols called mnemonics. With the help of low-level languages, very efficient and compact programs are created, since 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 be used only in this environment. Similar languages used to write small system applications, device drivers, etc.

Programming languages high level do not take into account the peculiarities of specific computer architectures, therefore created programs at the source level, they are easily ported to other platforms if the corresponding translators are created for them. Developing programs in high-level languages \u200b\u200bis much easier than in machine languages.

The high-level languages \u200b\u200bare:

1. Fortran is the first compiled language created in50s of the 20th century. A number of essential programming concepts were implemented in it. A huge number of libraries have been created for this language, ranging from statistical complexes to satellite control, so it continues to be used in many organizations.

2. Cobol - a compiled language for economic calculations and solutionsbusiness problems developed in the early 60s. In Cobol, very powerful tools were implemented for working with large amounts of data stored on external media.

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

4. BASIC - created in60s 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 and was not originally considered as a mainstream programming language. It was intended to replace assembler so that it could create programs that are as efficient and short as possible, but not depend on a particular processor. He is in many ways similar to Pascal and has additional features to work with memory. A lot of application and system programs are written on it, 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 beginning90s based on C ++. It is designed to simplify the development of C ++ applications 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 instruction takes one byte). This code can be executed using an interpreter - the Java Virtual Machine (JVM).

2.The structure of a C ++ program

A C program has the following structure: # preprocessor directives

. . . . . . . . .

# preprocessor directives function a ()

function operators in ()

operators

void main () // function, which starts the program execution statements

descriptions

assignments

function empty operator

composite

transition

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

1) preprocessor transformation of text;

2) compilation;

3) layout (link editing or assembly).

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

cessor - transformation of the text of the program before its compilation. The 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 every use of the ZERO name in the program will be replaced

2) #include< имя заголовочного файла> - intended for inclusion in the program text of the text from the "Header files" catalog supplied together 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. Using the include directive does not include the corresponding standard library

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

After preprocessing processing, not a single preprocessing directive remains in the program text.

A program is a set of descriptions and definitions, and consists of a set of functions. These functions should always include a function named main. Without it, the program cannot be executed. The function name is preceded by information about the type of the function's return value (result type). If the function returns nothing, then the void type is indicated: 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 is placed behind the function header. A function body is a series of definitions, descriptions, and executable statements enclosed in curly 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 processed data in the program. An example is

int y \u003d 10; // named constant float x; //variable

Descriptions - notify the compiler of the properties and names of objects and functions described elsewhere in the program.

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

Sample C program:

#include // preprocessor directive

Control questions

1. What parts does a C ++ program consist of?

2. How is a definition different from an ad?

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 means of the C ++ language 2.1. The composition of the language

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

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

Identifiers are the names of objects of SI programs. The identifier can contain Latin letters, numbers and underscore. Uppercase and lowercase letters are different, 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 to the compiler. They cannot be used as identifiers.

- Operation characters are one or more characters that define the action on the 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 selects a constant as a token (elementary construction) and assigns it to one of the types by its appearance.

Separators are brackets, period, comma, whitespace characters.

2.1.1. Constants in C ++

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

Constants are divided into 5 groups:

Wholes;

- real (floating point);

Enumerable;

Symbolic;

String.

The compiler extracts a token and assigns it to one or another group, and then internally

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

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

IN depending on the value of the integer constant the compilerwill present her differently

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

Real constants have a different form of internal representation in computer memory. The compiler recognizes such constants by their appearance. Real constants can have two forms of representation: 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 integer or fractional parts, or a decimal point, or an exponent sign with an exponent can be omitted.

Enumerated constants are entered using keyword enum. These are ordinary integer constants that are assigned unique and easy-to-use designations. Examples: enum (one \u003d 1, two \u003d 2, three \u003d 3, four \u003d 4);

enum (zero, one, two, three) - if you omit the \u003d and numeric values \u200b\u200bin the definition of enumerated constants, the values \u200b\u200bwill 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 \u003d 10, three \u003d 3, four, five, six);

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

Character constants are one or two characters enclosed in apostrophes. Symbolic 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 starting with a \\ are called control sequences, they are used:

- To represent non-graphical characters, for example:

\\ a - sound signal,

\\ b - go back 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 quotation marks.

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

“\\ N \\” High-level algorithmic programming languages \u200b\u200b\\ ””.

2.2. Data types in C ++

The data is displayed in the program around the world. The purpose of the program is to process data. Data different types stored and processed in different ways. The data type defines:

1) internal representation of data in computer memory;

2) a set of values \u200b\u200bthat can take values \u200b\u200bof this type;

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

IN depending on the requirements of the task, the programmer chooses the type for the program objects. C ++ types can be divided into simple and complex. 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 that specify the internal representation and range of standard types

short long signed

unsigned (unsigned)

2.2.1. Int type

Values \u200b\u200bof this type are integers.

The size of an int 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 int is preceded by the short specifier, then 2 bytes are allocated for the number, and if the long specifier, then 4 bytes. The amount of memory allocated for the object depends on the set of valid values \u200b\u200bthat the object can take:

short int - takes 2 bytes, therefore, has a range of –32768 .. + 32767;

long int - takes 4 bytes, therefore, has a range of –2 147 483 648 .. + 2 147 483 647

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

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

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

2.2.2. Char type

Values \u200b\u200bof this type are members of a finite ordered set of characters. Each character is associated with a number called the character code. 1 byte is allocated for the value of the character type. The char type can be used with the signed and unsigned specifiers. The signed char data type can store values \u200b\u200bin the range from –128 to 127. When using the unsigned char data type, the values \u200b\u200bcan range from 0 to 255. The encoding is ASCII (American Standard Code foe International Interchange). Characters with codes from 0 to 31 refer to service ones and have an independent meaning only in input-output statements.

Values \u200b\u200bof 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 1 byte is not enough, for example Unicode. This type is generally of the same size as short. String constants of this type are written with the prefix L: L “String # 1”.

2.2.4. Bool type

The bool type is called boolean. Its values \u200b\u200bcan take true values and false. The internal form is false - 0, any other value is interpreted as true.

2.2.5. Floating point types.

The internal representation of a real number consists of 2 parts: mantissa and order. In IBM-compatible PCs, float values \u200b\u200boccupy 4 bytes, of which one bit is reserved for the mantissa sign, 8 for the order and 24 for the mantissa.

Values \u200b\u200bof double types occupy 8 bytes, 11 and 52 bits are allocated for the order and mantissa, respectively. The length of the mantissa determines the precision of the number, and the length is of the order of its range.

If there is a long specifier before the name of the double type, then bytes are allocated for the value.

2.2.6. Void type

TO basic types also include the void type. The set of values \u200b\u200bof this type is

2.3. Variables

A variable in C ++ is a named memory area that stores data of a certain type. A variable has a name and a value. The name is used to refer to the memory area 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 memory class can take the following values: auto, extern, static, register. The memory class defines the lifetime and scope of the variable. If the memory class is not specified explicitly, 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 a part of the program text from which normal access to a variable is allowed. Usually the scope is the same as the scope. Except for the case when a variable with the same name exists 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. For these variables, memory is allocated upon entry into the block and freed upon exit from it. Such variables do not exist outside the block.

extern is a global variable, it is located in another place of the program (in another file or further along 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 memory for them is allocated in processor registers. If this is not possible, 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 \u003d 1; // assignment to a global variable

int a; // local variable a

a \u003d 2; // assignment to a local variable :: a \u003d 3; // assignment to a global variable

int x \u003d 4; // definition and initialization of x

In the example, the variable a is defined outside all blocks. The scope of the variable a is the entire program, except 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 the block is entered (since the default memory class is auto), and released when the block is exited. The variable with (static) exists while the program is running.

If the initial value of the variables is not specified explicitly during the definition, the compiler clears the global and static variables. Automatic variables are not initialized.

The variable name must be unique in its scope.

A variable declaration can be performed either as a declaration or as a definition. The declaration contains information about the memory class and the type of the variable, the definition together with this information gives an instruction to allocate memory. In the example extern int x; - declaration, and the rest are definitions.

2.4. Operation signs 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

& getting the address of the operand

* Addressing (dereferencing)

- unary minus, flips the sign of the arithmetic operand

++ Increase by one:

prefix operation - increments the operand before it is used

postfix operation increments the operand after it has been used

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

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

decrease by one:

prefix operation - decrements the operand before using it -

postfix operation decrements the operand after it is used

calculating 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 by default

Writing an algorithm in an algorithmic (formal) language is called a program. Sometimes the very concept of an algorithm is identified with its recording, so the words "algorithm" and "program" are almost synonyms. A slight difference is that when an algorithm is mentioned, as a rule, they mean the basic idea of \u200b\u200bits construction, which is common to all algorithmic languages. A program is always associated with writing an algorithm in a specific formal language.

When presenting the idea of \u200b\u200ban algorithm, for example, when publishing in a scientific article, it is not always advisable to use any specific programming language so as not to clutter up the presentation with insignificant details. In such cases an 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 to any specific programming language. Writing an algorithm in pseudocode is often clearer and clearer, it allows you to freely choose the level of detail, starting from the description in the most general outline and ending with a detailed presentation.

Pseudocodes Are semi-formalized descriptions of algorithms on conditional algorithmic language, including both elements of a programming language and natural language phrases, generally accepted mathematical notation, and more.

Pseudocode is a notation and rule system designed to consistently record algorithms.

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

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

General view of the algorithm:

alg algorithm name (arguments and results)

given algorithm applicability conditions

need the purpose of the algorithm

early description of intermediate values

sequence of commands (algorithm body)

Part of the algorithm from the word alg to the word early called the title, and the part 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 the type of the value (integer, thing, sym, lit or log) of all input (arguments) and output (results) variables are indicated. When describing arrays (tables), a special word is used tab, supplemented by boundary pairs for each index of array elements.

Sample sentences alg :

alg Volume and area of \u200b\u200bthe cylinder (arg item R, H, res item V, S)

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

alg Exclude element ( arg int N, arg rez thing tab A)

alg Diagonal ( arg int N, arg cel tab A, rez lit Otvet)

suggestions given and need optional. It is recommended to write in them statements describing the state of the environment of the executor of the algorithm, 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 Text string substring Str1 is replaced by Str2

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

given | N\u003e 0

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

alg Resistance (arg thing R1, R2, arg int N, res thing R)

given | N\u003e 5, R1\u003e 0, R2\u003e 0

need | R - circuit resistance

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

The main function words of the algorithmic language:

alg (algorithm) sim (symbolic) given for yes

arg (argument) lit (letter) should be from no

res (result) log (logical) if before at

start (start) tab (table) then value choice

end (end) nts (start of cycle) otherwise and input

int (whole) kts (end of cycle) all or output

thing (real) lengths (length) not yet approved

Basic commands:

1. The assignment command. Serves for evaluating expressions and assigning their values \u200b\u200bto variables. General form: A: \u003d Bwhere is the sign ":=" means the 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: \u003d (b + c) * sin (Pi / 4); i: \u003d i + 1.

Input and output commands.

input variable names (keyboard input)

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

Branching 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 operation. Each of the paths leads to a common exit, so the algorithm will continue to run no matter which path is taken.

The branching structure comes in four main flavors:

1. Team if - then;

if condition

then actions

2. Team if - then - otherwise;

if condition

then action 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 the choice is different.

Choice

at condition 1: actions 1

at condition 2: actions 2

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

at condition N: actions N

otherwise actions N + 1

Cycle commands.

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

There are two commands for organizing loops:

1. Loop type Until -Instructs to execute the loop body as long as the condition written after the word is satisfied until.

nts untilcondition

loop body

(sequencing)

kts

2. Loop type For -Instructs to execute the loop body for all values \u200b\u200bof some variable (loop parameter) in the specified range.

nts for i from i1 before i2

loop body

(sequencing)

kts

PROGRAMMING LANGUAGES

Currently, there are several hundred actually used programming languages \u200b\u200bin the world. Each has its own area of \u200b\u200bapplication.

Any algorithm, as we know, is a sequence of prescriptions that can be followed in a finite number of steps to go from the initial data to the result. Depending on the level of detail of the instructions, 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 sequences of characters make up a program (syntax rules) and which calculations the program describes (semantic rules).

Programming languages \u200b\u200bhave the following characteristics:

  • Language level - is characterized by the complexity of the tasks solved using this language.
  • Power of language - characterized by the number and variety of problems, 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 such that the wrong programs are difficult to write.
  • Readability b -ease of human perception of programs. This characteristic is important in teamwork, 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.

By this criterion, the following levels of programming languages \u200b\u200bcan be distinguished:

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

Machine languages \u200b\u200band machine-oriented languages \u200b\u200bare low-level languages \u200b\u200bthat require specifying small details of data processing. High-level languages, on the other hand, mimic natural languages \u200b\u200busing some of the words of the spoken language and common mathematical symbols. These languages \u200b\u200bare more human-friendly.

High-level languages \u200b\u200bare divided into:

  • procedural (algorithmic) (Basic, Pascal, C, etc.), which are designed to unambiguously describe algorithms; to solve a problem, procedural languages \u200b\u200brequire 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 written 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 a 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.

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

  • First generation: Machine languages.They 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 50s of the XX century
  • Third generation: Procedural languages.They appeared in the early 60s of the XX century. This generation includes high-level universal languages \u200b\u200bthat can be used to solve problems from any field (for example, Algol-60).
  • Fourth generation: Languages \u200b\u200bto support complex data structures(for example SQL). They appeared in the late 60s of the XX century.
  • Fifth generation: Artificial Intelligence Languages(e.g. Prolog). They 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-80s of the 20th century.

CONCLUSION

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