The use of exceptions in C++

Exceptions are called anomalous situation, occur during the execution of the program: the inability to open the file or to receive the necessary amount of memory, the use of out-of-bounds index for an array. Handling this kind of exceptions, as a rule, poorly integrated into the main algorithm of the program, and programmers are forced to invent different ways of correctly handle exceptions, стараясь в то же время не слишком усложнить […]

The use of templates in C++

Our IntArray class provides a good alternative to the built-in array of integers. But life can take arrays for various data types. We can assume, the only difference between array elements of double type from our type of the data is in the ads, весь остальной код совпадает буквально.Для решения данной проблемы в С++ введен механизм шаблонов. В объявлениях классов и функций допускается […]

Comments in programming languages

In C++ there are two types of comments. One is the same, as in With, using symbols /* to indicate the beginning and */ to mark the end of the comment. Between these pairs of characters can be any text, occupying one or more rows: the entire sequence between /* and */ as a comment. Too many comments, interspersed with the program code, […]

Implementation of I/o in programming languages C/C++

Частью стандартной библиотеки С++ является библиотека iostream, which is implemented as a class hierarchy and provides the basic features of I/o. The input terminal, called standard input, “привязан” к предопределенному объекту cin. Terminal output, or standard output, привязан к объекту cout. The third predefined object, cerr, is a standard output for errors. Обычно он используется для вывода сообщений об […]

The order of execution of instructions in the programming languages C/C++

By default, the program instructions run one after the other, consistently. В программе первой будет выполнена инструкция readIn, за ней sort, compact и наконец print. However, imagine a situation, when the number of sales is small: it is 1 or even 0. Вряд ли стоит вызывать функции sort и compact для такого случая. Print the result but still need, therefore, the function […]

Instructions in C++

В С++ действие называется выражением, and the expression, ending with a semicolon, - the manual. Manual – it is an atomic part of C++ program, which the program in C++ corresponds to a sentence of a natural language. Here are examples of instructions of C++:

Первая из приведенных инструкций является инструкцией объявления. book_count можно назвать идентификатором, symbolic variable (или просто переменной) или объектом. The variable corresponds to a region in computer memory, correlated with a specific name (in […]

Table identifiers

There is one problem with the compiler in its current state: it does nothing to save a variable when we declare it. So the compiler will quietly allocate memory for several variables with the same name. Вы можете легко убедиться в этом набрав строку типа pvavavabe. Here we declared A variable A three times. Как вы можете […]

Boolean logic

The next step should also be familiar to you. We need to add Boolean expressions and operators relations. Again, as we worked with them more than once, I won't detail all of them except, in which they differ from, what we did before. Again, мы не будем просто копировать их из других файлов потому […]

Control structures

We're almost home. Having a Boolean expression it is easy to add control structures. For TINY we solve only two of them, IF and WHILE: <if> ::= IF <bool-expression> <block> [ ELSE <block>] ENDIF <while> ::= WHILE <bool-expression> <block> ENDWHILE Еще раз позвольте мне разъяснить решения, implied in this syntax, which is very different from the syntax of C or Pascal. In […]

Doable approval

By this time, we can generate an empty program, which has some variables declared and possibly initialized. But until we have generated a single line of executable code. Do you believe or not, but we almost have a usable compiler! Missing only the executable code, to log in the main program. Но этот код – это только операции […]