k-tree
E-learning book

Program

Any machine, be it an electronic coffee machine or a rover, performs actions according to some algorithm. For example, if there are no beans in the coffee machine, it asks you to fill them up. The signal to the rover goes up to 20 minutes, therefore, he cannot receive instructions in real time and acts independently on the basis of the program embedded in it, occasionally receiving and sending signals to earth.

Any programming, whether it's a spacecraft, a complex 3D game, or a website, is designed to be done those actions that a person could automate. In general, the program is a black box that has an owner (programmer) and user. The user enters information into this black box by input: keyboard, mouse, voice, touch screen and others. The result is returned as output: on the monitor screen, in the speakers, in the form of an automatically opening door and other sources of tangible information for a person.

From the programmer's side, a program is a way to automate some process, for which there is a set various tools that defines the programming language and the environment in which the program is executed.

I will tell you by the example of writing the simplest program for a coffee machine. To make coffee, you will need coffee beans and water itself, which means you need two input devices (the input device always implies entering into the program): scales for coffee and water volume, also, the user needs to press a button — this is interaction with the program, which means it also requires one input device, for a total of three input devices. Now I need to signal the user, that the coffee is ready, there are not enough grains or water, a total of three output devices.

Now it is necessary to build an algorithm, an algorithm is an instruction for the processor, a program in a programming language is a record of the algorithm in this language. There are many languages (not 100 or even 1000), there are unimaginably many fields of application, but everyone is united by one thing — an algorithm and a flowchart!

A flowchart is a record of an algorithm in a publicly available language. Ultimately, the algorithm is written for the processor, any processor can not do so much, but nevertheless it is quite capacious: read and write data using I/O devices, move inside the program using conditions, perform arithmetic operations.

A small digression: how input devices work. The processor has input channels (called ports), the processor operates at a certain frequency, let's say 4.8 MHz (4,800 000 pulses per second), each of these pulses it checks whether information has been received through the input device. That is, he does not sit idle until you press a key, he checked 4,800,000 times a second whether you pressed the button or not.

So, we have input, output, a condition with moving through the program and performing operations — these are the elements of the flowchart, each has its own designation:

The algorithm

Algorithm is an instruction for the performer, the performer in our case is the processor, so in the instruction we we can use three blocks corresponding to the capabilities of the processor. The blocks are shown in Figure 1 (there are others, but we will not consider them in this chapter).

I want to make a coffee machine that will make coffee at the touch of a button, in general, the process will take place in this order: the user presses the button, the coffee machine checks that all the elements are normal and starts cooking, if there are problems — informs the user about it. Now what it looks like in the diagram.

Carefully study the diagram and try to make your own (I use the yEd program or paper and pen), if not ideas for the process, practice on the following:

  • Alarm clock
  • Robot vacuum cleaner
  • Automatic shutdown of the iron
  • Road crossing
  • Brewing tea
  • Airing the room

The development of a flowchart allows the abstract process to be transferred to a linear one, the flowchart displays the algorithm and it is always developed before writing the program.

For analysis, write to tg @zakhar_it


Do you find this article curious? /

Seen: 4 675