1. Introduction

Programming needs new universal algorithmic models, and hardware implements algorithms not only in a different form, but also on the basis of another algorithmic model - automaton. Borrowing technology from hardware development is the key idea behind automatic programming. However, the synthesis digital devices different from programming. But, borrowing the model, on the one hand, it is not desirable to change it significantly, and, on the other hand, it is impossible not to take into account the existing theory and practice of programming.

Next, we will consider the SWITCH technology for designing automatic programs, in which you encounter similar processes all the time. On the one hand, she changed the model so much state machine, which actually took it beyond the scope of automata theory. And, on the other hand, it introduces into programming concepts that are hardly perceived by programmers, and, at times, are simply superfluous, because there are more familiar analogues from the theory of programs and the practice of programming.

As a basis for discussing the problems of automatic programming, we take a recent lecture by Shalyto A.A. and his "software" papers to the definition of the automata programming paradigm.

Learning the basics and subtleties of the C++ programming language. Tutorial with practical tasks and tests. Do you want to learn how to program? Then you are at the right place - here free education programming. Whether you have experience or not, these programming lessons will help you get started creating, compiling and debugging C++ programs in different development environments: visual studio, Code::Blocks, Xcode or Eclipse.

Lots of examples and detailed explanations. Perfect for both beginners (dummies) and more advanced. Everything is explained from scratch to the smallest detail. These lessons (200+) will give you a good base / foundation in understanding programming not only in C ++, but also in other programming languages. And it's absolutely free!

It also covers step-by-step creation of a game in C ++, the SFML graphics library and more than 50 tasks to test your skills and knowledge in C ++. An added bonus is .

For repost +20 to karma and my gratitude!

Chapter number 0. Introduction. Beginning of work

Chapter number 1. Basics of C++

Chapter number 2. Variables and Basic Data Types in C++

Chapter number 3. Operators in C++

Chapter number 4. Scope and Other Types of Variables in C++

Chapter number 5. The order in which code is executed in a program. Loops, branches in C++

C++ (pronounced c-plus-plus) is a compiled, statically typed, general-purpose programming language that can be used to create programs of any level of complexity.
For more than 20 years, this language has been in the top three most popular and in-demand programming languages. (This can be verified by visiting the TIOBE website).
The language originated in the early 1980s, when Bell Labs employee Björn Stroustrup came up with a number of improvements to the C language for his own needs.

Bjarne Stroustrup - creator of the C++ language

Stroustrup decided to extend the C language with the features available in the Simula language. The C language, being the base language of the UNIX system on which the Bell computers ran, is fast, feature rich, and portable. Stroustrup added to it the ability to work with classes and objects. As a result, practical modeling problems turned out to be accessible both in terms of development time (due to the use of Simula-like classes) and in terms of computation time (due to the speed of C).
Here is how the developer of the language himself says it:



In 1998, the first language standard, known as C++98, was published by a standards committee. C++ continues to evolve to meet modern requirements. One of the groups that develops the C++ language and sends suggestions to the C++ standardization committee to improve it is Boost, which deals, among other things, with improving the capabilities of the language by adding metaprogramming features to it. The latest standard was released in 2017 and is called C++17. The next standard will not be long in coming and is expected to appear in 2020.
No one owns the rights to the C++ language, it is free. In March 2016, Russia established working group WG21 C++. The group was organized to collect proposals for the C++ standard, submit them to the committee, and defend them at general meetings of the International Organization for Standardization.
C++ is a multi-paradigm language (from the word paradigm - writing style computer programs), which includes a wide range of different programming styles and technologies. It is often referred to as an object-oriented language, but, strictly speaking, this is not the case. In the process of work, the developer gets absolute freedom in choosing tools so that the problem solved using one or another approach is solved as efficiently as possible. In other words, C++ does not force the programmer to adhere to only one style of program development (for example, object-oriented).
C++ has a rich standard library that includes common containers and algorithms, I/O, regular expressions, multithreading support and other features. C++ has influenced many programming languages, including: Java, C#, D. Since C++ belongs to a family of languages ​​based on the syntax of the C language, other programming languages ​​​​of this family can be easily mastered: JavaScript, PHP, Perl, Objective-C and many more. . etc., including the parent language itself - C. ()
During its existence, stable myths have been fixed for the C ++ language, which are easily refuted (see here: Part 1 and Part 2)

The history of the language and the release of standards

1983

Language creator - Bjorn Stroustrup, at Bell Labs, introduced an early version of C++ (“C with Classes”)

1985

First commercial release of C++, language takes on modern name

1986

Release of the first edition of The C++ Programming Language, a C++ book written by Bjorn Stroustrup

1998

The international C++ language standard was ratified: ISO/IEC 14882:1998 "Standard for the C++ Programming Language"

2003
2005

Library Technical Report 1 (TR1) released. While not officially part of the standard, the report described extensions to the standard library that should be included in next version C++ language

2011

Release of a new standard - C++11 or ISO/IEC 14882:2011; new standard included additions to the core of the language and an extension to the standard library, including much of TR1

2014

Release of the C++14 standard (“International Standard ISO/IEC 14882:2014(E) Programming Language C++”); C++14 can be seen as a small extension of C++11, containing mostly bug fixes and minor improvements.

2017

The release of the new standard is C++1z (C++17). This standard has made many changes and additions. For example, STD included C11 standard libraries, file system, based on boost::filesystem, a large part of the experimental TS I library.

2020

C++20 is the informal name for the ISO/IEC standard for the C++ programming language, which is expected after C++17. Draft of the N4800 standard.

Philosophy C++

In The Design and Evolution of C++ (2007), Bjorn Stroustrup describes the principles he followed when designing C++ (given in abbreviated form):

  • Get a universal language with static data types, the efficiency and portability of C.
  • Directly and comprehensively support a variety of programming styles.
  • Give the programmer freedom of choice, even if it gives him the opportunity to choose incorrectly.
  • Keep compatibility with C as much as possible, thereby making it possible to easily switch from programming to C.
  • Avoid confusion between C and C++: any construct allowed in both languages ​​must mean the same thing in each of them and lead to the same program behavior.
  • Avoid features that are platform dependent or not universal.
  • "Don't pay for what you don't use" - No language feature should cause performance degradation for programs that don't use it.
  • Do not require too complicated programming environment.

C and C++

The C++ syntax is inherited from the C language. Although, formally, one of the principles of C++ remains to maintain compatibility with the C language, in fact, the standardization groups of these languages ​​​​do not interact, and the changes they make not only do not correlate, but often fundamentally contradict each other ideologically. So, the elements that the new C standards add to the kernel are elements of the standard library in the C ++ standard and are generally absent in the kernel, for example, dynamic arrays, arrays with fixed boundaries, parallel processing facilities. Combining the development of the two languages ​​would be of great benefit, Stroustrup says, but it's unlikely for political reasons. So practical compatibility between C and C++ will gradually be lost.
AT this example, depending on the compiler used, either "C++" or "C" will be output:

Program 9.1

#include int main() ( printf("%s\n", (sizeof("a") == sizeof(char)) ? "C++" : "C"); return 0; )

This is due to the fact that character constants in C are of type int , and in C++ they are of type char , but the sizes of these types differ.

Application life cycle models

Life cycle software is the period of time that begins from the moment a decision is made on the need to create software product and ends at the moment of its complete withdrawal from operation. This cycle is the process of building and developing software (SW). There are several models life cycle.
Cascade model life cycle (English waterfall model) was proposed in 1970 by Winston Royce. It provides for the sequential implementation of all stages of the project in a strictly fixed order. The transition to the next stage means the complete completion of the work at the previous stage. The requirements defined at the requirements generation stage are strictly documented in the form terms of reference and are fixed for the duration of the project. Each stage ends with the release complete set sufficient documentation so that development can be continued by another development team.
Project stages according to the waterfall model:

  1. Formation of requirements;
  2. Design;
  3. Implementation;
  4. Testing;
  5. implementation;
  6. Operation and maintenance.

In the waterfall model, the transition from one project phase to another assumes the complete correctness of the result of the previous phase. In large projects, this is almost impossible to achieve. Therefore, such a model is suitable only for the development of a small project. (W. Royce himself did not adhere to this model and used an iterative model).
Iterative model
An alternative to the waterfall model is the model of iterative and incremental development (IID), which received from T. Gilb in the 70s. the name of the evolutionary model. The IID model breaks down the life cycle of a project into a sequence of iterations, each of which resembles a "mini-project", including all development processes applied to the creation of smaller pieces of functionality, compared to the project as a whole. The goal of each iteration is to obtain a working version of the software system, including the functionality defined by the integrated content of all previous and current iterations. The result of the final iteration contains all the required functionality of the product. Thus, with the completion of each iteration, the product receives an increment - an increment - to its capabilities, which, therefore, develop evolutionarily.


Various variants of the iterative approach are implemented in most modern development methodologies:

Development process - Rational Unified Process (RUP)

Rational Unified Process (RUP)(rational unified process) is a software development methodology maintained by Rational Software (IBM). The methodology provides recommendations for all stages of development: from business modeling to testing and commissioning of the finished program. The Unified Modeling Language (UML) is used as the modeling language.
The complete product development life cycle consists of four phases, each of which includes one or more iterations.

  • Initial stage (Inception)
  • Determining the scope of the project and the amount of required resources. The main requirements, restrictions and key functionality of the product are determined. The risks are assessed. Action planning. At the end of the inception phase, achievement of the goal's Lifecycle Objective Milestone is assessed, which implies an agreement between the stakeholders to continue the project.

  • Elaboration
  • Requirements documentation. Design, implementation and testing of the executable architecture. Specification of terms and cost. Reduction of the main risks. Successful completion of the development phase means reaching the Lifecycle Architecture Milestone.

  • Construction
  • In the "Build" phase, most of the functionality of the product is implemented: the design of the application is completed, source written. The Build phase ends with the first external release of the system and the Initial Operational Capability milestone.

  • Implementation (Transition)
  • In the "Implementation" phase, the final version of the product is created and transferred from the developer to the customer. This includes a beta testing program, user education, and product quality assurance. In case the quality does not meet the expectations of the users or the criteria set in the Start phase, the Implementation phase is repeated again. Meeting all goals means reaching the milestone of the finished product (Product Release) and completing the full development cycle.



« Information technology. System and software engineering. Life cycle processes software tools» . This standard has been adopted by the Federal Agency for Technical Regulation and Metrology of the Russian Federation and is similar to the international standard ISO/IEC 12207:2008. This standard, establishes a general framework for the software life cycle processes that can be used as guidance in the software industry. The standard does not offer specific model life cycle. Its provisions are common to any life cycle models, methods and technologies for creating software. It describes the structure of life cycle processes without specifying how to implement or perform the activities and tasks included in these processes.

Presentation for the lesson
Message topics
  • Free Software Foundation (FSF)
  • Free software licenses
  • Free Software and Open Source
  • History of the development of programming languages
  • History of C. C and C++
  • Story
  • Criticism of C++
  • History of UNIX
  • Spiral Software Life Cycle Model
  • UML (English Unified Modeling Language - unified modeling language)
  • Microsoft Solutions Framework
  • IDE for C/C++ programming on Windows
  • C/C++ compilers
  • Creating a Console Application on Windows
Questions
  1. Why is the waterfall software development model not used in large projects?
  2. What is the difference between waterfall and iterative development models?
  3. List the stages of software development in the Rational Unified Process (RUP) methodology

In this article, the scanf() function is considered in general terms without reference to a specific standard, so data from any C99, C11, C++11, C++14 standards is included here. Perhaps, in some standards, the function works with differences from the material presented in the article.

scanf C function - description

scanf() is a function located in the stdio.h(C) and cstdio(C++) header files, also known as formatted program input. scanf reads characters from the standard input stream (stdin) and converts them according to the format, then writes them to the specified variables. Format - means that the data is converted to a certain form upon receipt. So the scanf C function is described:

scanf("%format", &variable1[, &variable2,[…]]),

where variables are passed as addresses. The reason for passing variables to a function in this way is obvious: as a result of work, it returns a value indicating the presence of errors, so the only way to change the values ​​of variables is to pass by address. Also, thanks to this method, the function can process data of any type.

Some programmers refer to functions like scanf() or printf() as procedures because of the analogy with other languages.

Scanf allows you to input all the basic types of the language: char, int, float, string, etc. In the case of variables string type there is no need to specify the address sign - "&", because type variable string is an array, and its name is the address of the first element of the array in computer memory.

Input format or control string

Let's start by looking at an example of using the scanf C function from the description.

#include int main() ( int x; while (scanf("%d", &x) == 1) printf("%d\n", x); return 0; //requirement for linux systems )

The input format consists of the following four parameters: %[*][width][modifiers] type. In this case, the "%" sign and the type are mandatory parameters. That is, the minimum form of the format looks like this: “%s”, “%d” and so on.

In general, the characters that make up the format string are divided into:

  • format specifiers - everything that starts with the % character;
  • separator or space characters - they are space, tab (\t), new line(\n);
  • characters other than whitespace.

The function may not be safe.

Use the scanf_s() function instead of scanf().

(post from Visual Studio)

Type, or format specifiers, or conversion characters, or control characters

A scanf C declaration must contain, at a minimum, a format specifier, which is specified at the end of expressions beginning with a "%" character. It tells the program the type of data to expect when entering, usually from the keyboard. List of all format specifiers in the table below.

Meaning

The program is waiting for a character input. The variable to be written must be of type char.

The program is waiting for input decimal number integer type. The variable must be of type int.

The program expects an input of a floating point (comma) number in exponential form. The variable must be of type float.

The program expects the input of a floating point number (comma). The variable must be of type float.

7

The program expects the input of a floating point number (comma). The variable must be of type float.

The program is waiting for input octal number. The variable must be of type int.

The program is waiting for a string input. A string is a set of any characters up to the first separator character encountered. The variable must be of type string.

The program expects a hexadecimal number to be entered. The variable must be of type int.

The variable expects a pointer input. The variable must be of pointer type.

Writes to the variable an integer value equal to the number of characters read so far by the scanf function.

The program reads an unsigned integer. The variable type must be unsigned integer.

The program expects a binary number to be entered. The variable must be of type int.

The set of characters to be scanned. The program waits for input of characters from the limited pool specified between scanf will work as long as there are characters from the specified set on the input stream.

Characters in the format string

Asterisk symbol (*)

The asterisk (*) is a flag indicating that the assignment operation should be suppressed. An asterisk is placed immediately after the "%" sign. For example,

Scanf("%d%*c%d", &x, &y); //ignore character between two integers. scanf("%s%*d%s", str, str2); //ignore integer between two strings.

That is, if you enter the line "45-20" in the console, the program will do the following:

  1. The variable "x" will be assigned the value 45.
  2. The variable "y" will be assigned the value 20.
  3. And the minus sign (dash) "-" will be ignored thanks to "%*c".

Width (or margin width)

This is an integer between the "%" sign and the format specifier that specifies maximum amount characters to read for the current read operation.

Keep in mind a few important points:

  1. scanf will abort if it encounters a separator character, even if it didn't count 20 characters.
  2. If more than 20 characters are input, only the first 20 characters will be written to str.

Type modifiers (or precision)

These are special flags that modify the type of data expected for input. The flag is specified to the left of the type specifier:

  • L or l (small L) When "l" is used with the specifiers d, i, o, u, x, the flag tells the program that long int input is expected. When using "l" with the e or f specifier, the flag tells the program that it should expect a double value. The use of "L" tells the program that a long double is expected. The use of "l" with the "c" and "s" specifiers tells the program that two-byte characters like wchar_t are expected. For example, "%lc", "%ls", "%l".
  • h is a flag indicating the short type.
  • hh - indicates that the variable is a pointer to a value of type signed char or unsigned char. The flag can be used with the specifiers d, i, o, u, x, n.
  • ll (two small L's) indicates that the variable is a pointer to a value of type signed int or unsigned long long int. The flag is used with specifiers: d, i, o, u, x, n.
  • j - indicates that the variable is a pointer to type intmax_t or uintmax_t from header file stdint.h Used with specifiers: d, i, o, u, x, n.
  • z - indicates that the variable is a pointer to the size_t type, the definition of which is in stddef.h. Used with specifiers: d, i, o, u, x, n.
  • t - indicates that the variable is a pointer to the ptrdiff_t type. The definition for this type is in stddef.h. Used with specifiers: d, i, o, u, x, n.

More clearly, the picture with modifiers can be presented in the form of a table. Such a description of scanf C for programmers will be clearer.

Other characters

Any characters encountered in the format will be discarded. At the same time, it should be noted that the presence of whitespace or separator characters (newline, space, tab) in the control string can lead to different behavior of the function. In one version, scanf() will read without saving any number of separators until it encounters a character other than the separator, and in another version, spaces (only they) do not play a role and the expression "%d + %d" is equivalent to "% d+%d".

Examples

Let's consider a number of examples that allow you to think and more accurately understand the operation of the function.

scanf("%3s", str); //if you enter the string "1d2s3d1;3" in the console, only "1d2" will be written to str scanf("%dminus%d", &x, &y); //minus characters between two numbers will be discarded scanf("%5", str); // characters will be entered into str until there are 5 characters and the characters are numbers from 0 to 9. scanf("%lf", &d); //expect double input scanf("%hd", &x); //expected number of type short scanf("%hu", &y); //expect unsigned number short scanf("lx", &z); //expected number of type long int

From the examples given, you can see how the expected number changes using different symbols.

scanf C - description for beginners

This section will be useful for beginners. Often you need to have on hand not so much Full description scanf C how many details of how the function works.

  • The feature is somewhat deprecated. There are several different implementations in libraries of different versions. For example, the improved scanf S C function, a description of which can be found on the microsoft.
  • The number of specifiers in the format must match the number of arguments passed to the function.
  • Elements of the input stream must be separated only by separator characters: space, tab, newline. Comma, semicolon, period, etc. - these characters are not separators for the scanf() function.
  • If scanf encounters a separator character, input will be stopped. If there is more than one variable to read, then scanf will move on to reading the next variable.
  • The slightest inconsistency in the format of the input data leads to unpredictable results of the program. Well, if the program just ends with an error. But often the program continues to work and does it wrong.
  • scanf("%20s...",...); If the input stream exceeds 20 characters, then scanf will read the first 20 characters and either abort or move on to reading the next variable, if one is specified. In this case, the next call to scanf will continue reading the input stream from the point where the work of the previous call to scanf stopped. If a separator character is encountered while reading the first 20 characters, scanf will abort or move on to reading the next variable, even if it did not read 20 characters for the first variable. In this case, all unread characters will be attached to the next variable.
  • If the set of scanned characters starts with a "^" sign, then scanf will read the data until it encounters a delimiter character or a character from the set. For example, "%[^A-E1-5]" will read data from the stream until one of the English characters from A to E in upper case or one of the numbers from 1 to 5.
  • The scanf C function, by definition, returns a number equal to the number of successful writes to variables. If scanf writes 3 variables, then the success result of the function will return the number 3. If scanf could not write any variables, then the result will be 0. And, finally, if scanf could not start at all for some reason, the result will be EOF .
  • If the scanf() function completed its work incorrectly. For example, scanf("%d", &x) - a number was expected, but the input received characters. The next call to scanf() will start at the point in the input stream where the previous function call left off. To overcome this problem, it is necessary to get rid of the problem characters. This can be done, for example, by calling scanf("%*s"). That is, the function will read a string of characters and throw it away. In this tricky way, you can continue entering the necessary data.
  • Some implementations of scanf() do not allow "-" in the character set to be scanned.
  • The "%c" specifier reads each character from the stream. That is, it also reads the separator character. To skip the delimiter character and continue reading the desired character, "%1s" can be used.
  • When using the "c" specifier, it is acceptable to use the width "%10c", but then in the form function variable scanf needs to pass an array of elements of type char.
  • “%” means “all small letters of the English alphabet”, and “%” means just 3 characters: 'z', 'a', '-'. In other words, the character "-" means a range only if it is between two characters that are in the correct order. If "-" is at the end of an expression, at the beginning, or in the wrong order of characters on either side of them, then it is just a hyphen character, not a range.

Conclusion

This concludes the description of scanf C. This is a nice handy function to work with in small programs and when using the procedural method of programming. However, the main disadvantage is the number of unpredictable errors that can occur when using scanf. Therefore, the description of scanf C when programming is best kept in front of your eyes. In large professional projects, iostreams are used, due to the fact that they have higher-level capabilities, they are better able to catch and handle errors, and also work with significant amounts of information. It should also be noted that the description of scanf C in Russian is available on many online sources, as well as examples of its use, due to the age of the function. Therefore, if necessary, you can always find the answer on thematic forums.

C++ programming language

Last update: 08/28/2017

The C++ programming language is a high-level, general-purpose, statically typed, compiled programming language that is suitable for building the most various applications. C++ is one of the most popular and widespread languages ​​today.

It has its roots in the C language, which was developed in 1969-1973 at Bell Labs by programmer Dennis Ritchie. In the early 1980s, Danish programmer Bjarne Stroustrup, then at Bell Labs, developed C++ as an extension to the C language. In fact, in the beginning, C++ simply supplemented the C language with some features of object-oriented programming. And so Stroustrup himself at first called it "C with classes" ("C with classes").

Subsequently, the new language began to gain popularity. New features were added to it that made it not just an addition to C, but a completely new programming language. As a result, "C with classes" was renamed to C++. And since then, both languages ​​began to develop independently of each other.

C++ is a powerful language, inheriting rich memory capabilities from C. Therefore, C++ often finds its application in system programming, in particular, when creating operating systems, drivers, various utilities, antiviruses, etc. By the way, Windows is mostly written in C++. But only system programming the use of this language is not limited. C++ can be used in programs of any level where speed and performance are important. It is often used to create graphic applications, various application programs. It is also especially often used to create games with rich rich visuals. In addition, the mobile direction has recently been gaining momentum, where C ++ has also found its application. And even in web development, you can also use C++ to create web applications or some kind of auxiliary services that serve web applications. In general, C++ is a widely used language in which you can write almost any kind of program.

C++ is a compiled language, which means that the compiler translates C++ source code into an executable file that contains a set of machine instructions. But different platforms have their own characteristics, so compiled programs cannot simply be transferred from one platform to another and run there already. However, at the source code level, C++ programs are mostly portable unless some OS-specific features are used. And the availability of compilers, libraries, and development tools for almost all common platforms makes it possible to compile the same C++ source code into applications for these platforms.

Unlike C, the C++ language allows you to write applications in an object-oriented style, representing a program as a collection of classes and objects interacting with each other. This simplifies the creation of large applications.

Milestones of development

In 1979-80, Bjarne Stroustrup developed an extension to the C language - "C with classes". In 1983 the language was renamed to C++.

In 1985, the first commercial version of the C++ language was released, as well as the first edition of the book "The C++ Programming Language", which represented the first description of this language in the absence of an official standard.

Released in 1989 a new version C++ 2.0, which included a number of new features. After that, the language developed relatively slowly until 2011. But at the same time, in 1998, the first attempt was made to standardize the language by the ISO (International Organization for Standardization). The first standard was called ISO/IEC 14882:1998 or C++98 for short. Later in 2003 a new version of the C++03 standard was published.

In 2011, the new C++11 standard was published, which contained many additions and enriched the C++ language with a large number of new features. This was followed in 2014 by a minor addition to the standard, also known as C++14. And one more key release language is scheduled for 2017.

Compilers and Development Environments

To develop programs in C++, you need a compiler - it translates C++ source code into an executable file, which can then be run. But in this moment there are a lot of different compilers out there. They may differ in various aspects, in particular in the implementation of standards. A basic list of compilers for C++ can be found on wikipedia. It is recommended for development to choose those compilers that develop and implement all the latest standards. For example, throughout this tutorial, the freely available g++ compiler, developed by the GNU project, will be used predominantly.

You can also use IDEs such as Visual Studio, Netbeans, Eclipse, Qt, etc. to create programs.