f   Programming in JAVA, C++, PASCAL
Menu :
Starting point
Programming Basics
JAVA programming
Programming in C++
Programming in Pascal
Programming tasks
Self help guide for recording CD and DVD discs
Computer architecture Part 1
Computer Architecture part 2
Computer architecture part 3
Computer architecture part 4
PROGRAMMING BASICS
Programming is increasingly becoming an occupation only for professionals.
The slogan "Programming is the second literacy", announced in the mid — 1980s, has remained in the past.
The concept of "computer literacy" today includes, first of all, the skill of using various means of information technologies.
When solving a particular information problem, it is necessary to choose an adequate software tool.
These can be spreadsheets, database management systems, mathematical packages, etc.
And only in the case when such tools do not make it possible to solve the problem, you should resort to universal programming languages.
It is customary to distinguish between two categories of programmers: applied and system.
System programmers are developers of basic computer software (operating systems, translators, service tools, etc.).
They are professionals of the highest level in programming.
Application programmers develop computer application software tools designed to solve problems from various fields (science, technology, production, service sector, training, etc.).
The quality requirements for both application programs and system programs are very high today.
The program should not only solve the problem correctly, but also have a modern interface, be highly reliable, user friendly, etc.
Only such programs can withstand competition in the global software market.
No one needs programming at the amateur level today.
With the development of computer technology, both the methodology and the technology of programming also developed.
First, command and operator programming appeared, in the 1960s structural programming developed rapidly, logical and functional programming lines appeared, and recently object oriented and visual programming — The task that should be set during the initial study of programming is to master the basics of structural programming techniques.
For this purpose, the most suitable tool is the Pascal programming language.
The author of the Pascal language the Swiss professor Niklaus Wirth created it for this very purpose.
The structural methodology remains the basis of the programming culture.
Without mastering it, a person who has taken up programming has no chance of becoming a professional.
The implementation of Pascal in the Borland versions for IBM, known as Turbo Pascal, significantly expanded the language compared to the Wirth version.
Starting from version 5.5, Turbo Pascal also becomes an object programming language.
The content of the third chapter of this textbook is focused on the deep mastering by students of the basic concepts of high level programming languages in their implementation in Pascal.
This training makes it easier to learn other programming languages.
The presentation of the basics of C/C++ languages in the fourth chapter is based on the knowledge and skills acquired by students while studying Pascal.
When studying this course, students will need knowledge of the basics of algorithmization within the framework of the school's basic computer science course.
Usually at school, algorithmization is studied using training performers, with the help of which you can successfully master the basics of structural methodology, namely:
- building algorithms from basic structures;
- application of the sequential granularity method.
It is desirable to get acquainted with the computer architecture at the level of machine commands (it is enough to use model examples of educational computers studied in school computer science; it is not necessary to study real command languages or assembly language at all).
This knowledge allows you to master the basic concepts of programming, such as variable, assignment; "enter the translator's position" and thanks to this, do not make mistakes, even without remembering some details of the language syntax; anticipate those "pitfalls" that your program may "run into" during execution.
In fact, all these qualities distinguish a professional programmer from an amateur.
Another quality of a professional is the ability to perceive the beauty of the program, to get aesthetic pleasure from the fact that it is well written.
Often this feeling helps to intuitively distinguish the wrong program from the right one.
However, the main criterion for correctness is, of course, not intuition, but well organized testing.
The process of studying and practical mastering of programming is divided into three parts:
- study of methods for constructing algorithms;
- learning a programming language;
- study and practical development of a certain programming system .
The second and fifth chapters of the textbook are devoted to solving the first problem.
The second chapter gives the basic, basic concepts and principles of constructing algorithms for working with quantities.
The fifth chapter describes some well known methods for the complete construction of algorithms, discusses the problems of testing programs, evaluating the complexity of algorithms.
The Turbo Pascal and C/C++ programming languages are described in the third and fourth chapters of the textbook, respectively.
We emphasize that this book is primarily a textbook on programming, and not on the Pascal and C languages.
Therefore, you will not find an exhaustive description of these languages here.
Languages are taught to the extent necessary for the initial programming course.
A more detailed description of the languages can be found in the books listed in the list of references.
The textbook does not contain instructions on working with specific programming systems for the languages being studied.
Students should get acquainted with them in the process of practicing on a computer, using other sources.
The sixth chapter is a fairly large task book on programming.
This task book can be used to organize practical and laboratory classes in any of the languages being studied.
Navigation :
CHAPTER 1.
BASICS OF ALGORITHMIZATION
1.1.
Algorithms and values
Stages of solving the problem on a computer.
The work on solving any problem using a computer is divided into the following stages:
1. Problem statement.
2. Formalization of the task.
3. Construction of the algorithm.
(read more...)
page 0 1 2
1.2.
Linear computational algorithms
The main elementary action in computational algorithms is assigning a value to a variable value.
If the value of a constant is determined by the type of its record, then the variable gets a specific value only as a result of assignment.
(read more...)
page 3 4
1.3.
Branching and loops in computational algorithms
Let's make an algorithm for solving the quadratic equation
The problem is well known from mathematics.
The initial data here are the coefficients a, b, C.
The solution in the general case will be two roots x1 and x2, which are calculated by the formula:
All values used in this program are of real type.
(read more...)
page 5 6 7
1.4.
Auxiliary algorithms and procedures
In the theory of algorithms, the concept of an auxiliary algorithm is known.
An auxiliary algorithm is called an algorithm for solving a certain subtask from the main problem being solved.
In this case, the algorithm for solving the original problem is called the main algorithm.
(read more...)
p .
8 9 CHAPTER 2.
INTRODUCTION TO PROGRAMMING LANGUAGES
2.1.
History and classification of programming languages
A programming language is a way of writing programs for solving various tasks on a computer in a form that is understandable for a computer.
The computer processor directly understands the machine command language (YAMK).
Programmers wrote programs on YAMK only for the very first lamp machines computers of the first generation.
(read more...)
pp.
10 11 12 13
2.2.
Structure and methods of describing high level programming languages
In any programming language, the ways of organizing data and the ways of organizing actions on data are defined.
In addition, there is the concept of "language elements", which includes a set of symbols( alphabet), lexemes and other visual means of the programming language.
(read more...)
p .
14 15 CHAPTER 3.
PROGRAMMING IN PASCAL
3.1.
The first acquaintance with Pascal
The structure of the program in Pascal.
According to the definition of standard Pascal, a program consists of a program header and a program body (block), followed by a dot — a sign of the end of the program.
In turn, the block contains sections of descriptions and a section of operators.
(read more...)
pp.
16 17 18 19
3.2.
Some information about the Turbo Pascal system
The name Turbo Pascal is usually perceived in two senses:
• as a dialect of the Pascal language, which is an extension of the standard Pascal;
* as a Turbo Pascal programming system, which is a set of system programs designed for creating, debugging and executing Pascal programs.
(read more...)
pp.
20 21 22
3.3.
Elements of the Turbo Pascal language
Alphabet.
The alphabet of a language consists of many characters, including letters, numbers and special characters.
Latin letters: from A to Z (uppercase) and from a to z.
(lowercase).
Numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
(read more...)
p. 23
3.4.
Data types
The concept of data types is one of the central concepts in any programming language.
There are three properties associated with the type of a quantity: the form of its internal representation, the set of accepted values and the set of permissible operations.
(read more...)
page 24 25
3.5.
Arithmetic operations, functions, expressions.
Arithmetic assignment operator
Arithmetic data types include groups of real and integer types.
Arithmetic operations and relation operations are applicable to them.
Data operations can be unary (applicable to one operand) and binary (applicable to two operands).
(read more...)
page 26 27
3.6.
Keyboard input and screen output
Data entry is the transfer of information from external devices to RAM.
As a rule, the initial data of the problem being solved are entered.
Output is the reverse process, when data is transferred from RAM to external media (printer, display, magnetic devices, etc. (read more...)
page 28 29
3.7.
Control of character output to the screen
Using only the Write and WriteLn procedures for output to the screen gives the programmer very weak opportunities to control the location of the output text on the screen.
The text can only be printed from top to bottom, from left to right.
(read more...)
pp.
30 31 32
3.8.
Logical quantities, operations, expressions.
Logical assignment operator
A discipline called mathematical logic is directly related to programming.
The basis of mathematical logic is the algebra of logic, or the calculus of propositions.
An utterance is any statement in respect of which it is possible to say unequivocally whether it is true or false.
(read more...)
page 33 34
3.9.
Functions linking different types of data
Table 3.6 provides a list of standard functions that provide communication between different data types.
Table 3.6
The ord, pred, and succ functions are only applicable to ordinal types.
(read more...)
page 35 36
3.10.
Logical expressions in control operators
The algorithmic structure of branching is programmed in Pascal using a conditional operator.
We used to describe it in this form:
If <condition> Then <operator 1> Else <o (read more...)
page 37 38
3.11.
Cycle by parameter
Consider the following simple problem: you need to calculate the sum of integers from M to N by direct summation.
Here M and N are integers.
The problem can be formulated as follows:
The algorithm and program for solving this problem using the cycle structure are so far presented in Fig. (read more...)
page 39 40
3.12.
Features of integer and real arithmetic
Numerical calculations can be performed on a set of integers or on a set of real numbers.
From a mathematical point of view, integers are a subset of the set of real numbers.
(read more...)
pp.
41 42 43
3.13.
Subroutines
You are already familiar with the concept of an auxiliary algorithm (see section 1.4).
In programming languages, auxiliary algorithms are called subroutines.
There are two types of subroutines in Pascal: procedures and functions.
(read more...)
pp.
44 45 46 47 48 49
3.14.
Calculation of recurrent sequences
A recurrent sequence.
From the course of mathematics, the concept of a recurrent sequence is known.
This concept is introduced as follows: let k numbers a1, ..., ak be known.
These numbers are the first numbers of the numerical sequence.
(read more...)
pp.
50 51 52 53
3.15.
Basic p onyatiya and computer graphics tools in Turbo Pascal
Until now, we have used the computer screen only for displaying symbolic information — numbers, texts.
However, Turbo Pascal allows you to display drawings, drawings, graphs of functions, diagrams, etc. (read more...)
pp.
54 55 56 57 58 59 60
3.16.
String data type
Now we will get acquainted with the data type, which is among the structured ones.
This is a string data type (string).
It should be noted that the string data type is present in Turbo Pascal and is not present in standard Pascal.
(read more...)
pp.
61 62 63 64
3.17.
Tabular data and arrays
In everyday and scientific practice, it is often necessary to meet with information presented in tabular form.
Here, for example, is a table containing the average monthly temperature values, °C, for a certain year:
Such a table is called a linear one.
(read more...)
pp.
65 66 67 68 69
3.18.
The concept of a set.
Multiple data type
One of the fundamental branches of mathematics is set theory.
Some aspects of the mathematical apparatus of this theory are implemented in Pascal through a multiple data type (sets).
(read more...)
pp.
70 71 72 73
3.19.
Files.
File variables
You have already met with the term "file".
First of all, this concept is usually associated with information on external memory devices.
In Pascal, the concept of a file is used in two senses:
• as named information on an external device (external file); (read more...)
pp.
74 75 76 77 78 79
3.20.
Combined data type
All the structured data types that we have already met are collections of the same type of values.
A combined data type is a structured type consisting of a fixed number of components (fields) of different types.
(read more...)
pp.
80 81 82
3.21.
Pointers and dynamic structures
So far, we have considered programming related to processing only static data.
Static values are those values for which memory is allocated during compilation and stored during the entire operation of the program.
(read more...)
pp.
83 84 85 86 87 88 89
3.22.
External subroutines and modules
Standard Pascal does not have the means to develop and support programmer's libraries (unlike, say, Fortran and other high level programming languages), which are compiled separately and can later be used not only by the developer himself.
(read more...)
pp.
90 91 92 93
3.23.
Object oriented programming
Basic concepts of Object oriented programming (OOP).
The fundamental idea of one of the modern approaches to programming — object oriented is to combine data and procedures that process them into a single whole objects.
(read more...)
pp.
94 95 96 97 98 99 100
3.24.
Virtual methods.
Constructors and destructors
Objects in dynamic memory.
When working with objects, it is quite typical that a complex method has to be created anew for each type of object, although the differences in the behavior of objects may be small.
(read more...)
pp.
101 102 103 CHAPTER 4.
THE C++PROGRAMMING LANGUAGE
4.1.
Introduction to C and C++
The history of the C++programming language.
The second programming language that is offered for study in this manual is the C language (in the English version, its name is indicated by a single capital letter of the Latin alphabet C).
(read more...)
pp.
104 105 106
4.2.
Elements of the C++language
Alphabet.
The alphabet of the C++ language includes:
* Latin letters: from A to z (lowercase) and from A to Z (uppercase);
* decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
* special characters: "(read more...)
page 107
4.3.
Data types
The concept of data types is the most important aspect of any programming language.
The peculiarity of Pascal consists in a wide variety of types, schematically presented in section.
3.4 in Fig. 9. (read more...)
pp.
108 109 110 111
4.4.
Operations and expressions
In all programming languages, an expression is a construction made up of constants, variables, operation signs, functions, and brackets.
The expression defines the order of calculation of a certain value.
(read more...)
pp.
112 113 114 115 116 117
4.5.
Linear programs in C / C++
The structure of the program.
The general structure of the C/C++ program is as follows:
preprocessor directives
function definition 1
function definition 2
definition of the function N
Among the functions, there must be a main function named main.
(read more...)
pp.
118 119 120 121 122
4.6.
Branch programming
There are several different tools available for programming branching algorithms in the C language.
These include the conditions operation discussed above ?:, conditional if operator and switch selection operator.
(read more...)
pp.
123 124
4.7.
Cycle programming
In C, as in Pascal, there are all three types of loop operators: a loop with a precondition, a loop with a postcondition, and a loop with a parameter.
A loop with a precondition.
Format of a loop operator with a precondition:
while (expression) operator; (read more...)
pp.
125 126 127
4.8.
Functions
And now we have to deal with the question of how the mechanism of subroutines is implemented in C/C++.
Let us recall that there are two types of subroutines in Pascal: subroutines of a procedure and subroutines of a function.
(read more...)
pp.
128 129 130 131 132 133
4.9.
Arrays
The concept of an array is familiar from Pascal.
An array is a structure of the same type of elements that occupy a continuous memory area.
The following properties are associated with an array: name, type, dimension, size.
(read more...)
pp.
134 135 136
4.10.
Pointers
The concept of a pointer is familiar to the reader from section 3.21, which describes the reference data type in Pascal.
The meaning of this concept in C/C++ remains the same: a pointer is the address of a memory field occupied by a program object.
(read more...)
pp.
137 138 139 140
4.11.
Processing of character strings
In C/C++ languages, there is no specially defined string data type, as in Turbo Pascal.
Character strings are organized as arrays of characters, the last of which is the \0 character, whose internal code is zero.
(read more...)
pp.
141 142 143
4.12.
Structures and associations
In C/C++ languages, the concept of a structure is similar to the concept of a record in Pascal.
This is a structured data type, which is a named collection of different types of elements.
The structure type is usually used in the development of information systems, databases.
(read more...)
pp.
144 145 146
4.13.
Stream I / O in the Si standard
I / O in programming refers to the process of exchanging information between RAM and external devices: a keyboard, a display, magnetic drives, etc.
Input is the entry of information from external devices into RAM, and output is the removal of information from RAM to external devices.
(read more...)
pp.
147 148 149 150 151 152
4.14.
Object oriented programming in C++
The main difference between the C++ language and C is the presence of object oriented programming (OOP) tools in it.
Often in the literature, the C++ language is defined precisely as an object oriented programming language.
(read more...)
pp.
153 154 155 156 157
4.15.
Formatted I / O in C++
To organize I / O in C++, you can use the C language tools (conio. h).
However, in C++ there is a standard class library focused on organizing streaming I / O. (read more...)
page 158 159 CHAPTER 5.
METHODS OF CONSTRUCTING ALGORITHMS
5.1.
Basic concepts of structural programming
More than half a century has passed since the appearance of the first computer.
All this time, computer technology has been developing rapidly.
The element base of the computer changed, the speed, the amount of memory grew, the means of interaction between a person and a machine changed.
(read more...)
pp.
160 161 162 163
5.2.
Sequential granularity method
The essence of the method was described above.
First, the original problem is analyzed.
It highlights the subtasks.
A hierarchy of such subtasks is constructed (Fig. 48).
Then algorithms (or programs) are compiled, starting with the main algorithm (the main program), then — auxiliary algorithms (subroutines) with a sequential deepening of the level, until we get algorithms consisting of simple commands.
(read more...)
pp.
164 165 166
5.3.
Recursive methods
The essence of recursive methods is to reduce the problem to itself.
You already know that both in Pascal and in C there is a possibility of recursive definition of functions and procedures.
This feature is a way to programmatically implement recursive algorithms.
(read more...)
page 167 168
5.4.
Search methods in search tasks
In this section, we will look at some tasks related to the problem of finding information.
This is a huge class of problems described in sufficient detail in the classical programming literature (see, (read more...)
pp.
169 170 171 172
5.5.
Heuristic methods
Heuristic methods are understood as such methods, the correctness of which is not strictly proved.
They look plausible; it seems that in most cases they should give the right solutions.
At the level of expert evaluation of the algorithm, it is often not possible to come up with a counterexample proving the fallacy or non universality of the method.
(read more...)
page 173
5.6.
Complexity of algorithms
Traditionally, it is customary to assess the degree of complexity of an algorithm by the volume of the main computer resources used by it: processor time and RAM.
In this regard, such concepts as the time complexity of the algorithm and the volume complexity of the algorithm are introduced.
(read more...)
pp.
174 175
5.7.
Data sorting methods
There is a traditional division of algorithms into numerical and non numerical ones.
Numerical algorithms are designed for mathematical calculations: calculations by formulas, solving equations, statistical data processing, etc. (read more...)
p. 176 177 178 CHAPTER 6.
PROGRAMMING TASKS
6.1.
Tasks on the topic "Linear programs"
This chapter presents a large selection of tasks that can be used to organize practical programming classes in both Pascal and C++.
The tasks are systematized by language constructs, cover 17 topics and are grouped into sections.
(read more...)
pp.
179 180 181 182 183
6.2.
Tasks on the topic "Fork"
6.2.1.
Text tasks
But
1.
Three real numbers are given.
Square those of them whose values are non negative, and to the fourth power — negative.
2. Two points A(x1, y1) and B(x2, y2) are given.
(read more...)
pp.
184 185 186 187
6.3.
Tasks on the topic "Selection operator"
1.
Write a program that, based on the number of the day of the week (an integer from 1 to 7), gives as a result the number of lessons in your class on that day.
2. Write a program that allows you to determine the last digit of its square by the last digit of a number.
(read more...)
pp.
188 189
6.4.
Tasks on the topic "Cycles"
6.4.1.
Loop with the parameter
1.
There is a series of measurements of the triangle elements.
The groups of elements are numbered.
In a series, such groups of triangle elements can occur in any order:
1) base and height; (read more...)
pp.
190 191 192
6.5.
Problems on the topic "Integer arithmetic"
But
1.
The natural number p is given.
Find the sum of the first and last digits of this number.
2. The natural number p is given.
Rearrange the first and last digits of this number.
3. Given two natural numbers t and n (t ≤ (read more...)
pp.
193 194 195 196 197
6.6.
Tasks on the topic "Subroutines"
6.6.1.
Non recursive procedures and functions
But
1.
A triangle is defined by the coordinates of its vertices.
Create a program to calculate its area.
2. Create a program to find the largest common divisor and the smallest common multiple of two natural numbers .
(read more...)
pp.
198 199 200 201
6.7.
Tasks on the topic "One dimensional arrays"
But
1.
The array A[N] contains natural numbers.
Find the sum of those elements that are multiples of a given K.
2. There are zero elements in the integer sequence.
Create an array of the numbers of these elements.
(read more...)
pp.
202 203 204 205 206 207 208
6.8.
Tasks on the topic "Two dimensional arrays"
6.8.1.
Tasks for the formation of arrays
In problems 1-12, form a square matrix of order n according to a given sample:
13.
Construct a square matrix of order 2n:
14.
(read more...)
pp.
209 210 211 212 213
6.9.
Tasks on the topic "Working with strings"
1.A line ending with a dot is given.
Count how many words are in a line.
2.A string containing English text is given.
Find the number of words starting with the letter b.
3. A string is given.
Calculate how many letters r, k, t are in it.
(read more...)
pp.
214 215 216 217
6.10.
Problems for "long arithmetic"
1.
Create a program for comparing two n digit numbers (n > 20).
2. Create a program that sums two natural n digit numbers, where n
