Programming Basics Part1
Programming Basics Part1
Basics
course
by Dr. Yuri Granovsky
Content
Computer Digital World
Information Basics
Software Basics
Networking
Operating System
Operators
Content
Statement
Function printf
Exercise
Personal Computer Devices
4
Beyond Personal Computer
5
Embedded Systems
6
What is the Common
7
Computer Digital World
● Computer is appliance able to keep and process a
huge amount of data with a huge speed
Display -
Keyboard -
Mouse -
Internet modem -
DVD disk -
DVD player -
Blood Pressure meter -
Sensor -
9
Numbering System Notation
● Amount of possible symbols in one
position/digit
● Computer binary presentation – yes/no
- impulse / no impulse
10
Number Systems Conversion
Decimal Binary
Formula for conversion from binary to decimal 0 0
1 1
where n – number of digits
2 10
Method for conversion from decimal to binary:
● Better to use calculator ☺ 3 11
0 0 0
Convenient method of conversion to/from
1 1 1
binary form
2 2 10
Each digit of the octal number may be 3 3 11
converted directly according to the table
4 4 100
9 9 1001
12
Decimal Binary Hexadecimal
1 1 1
2 10 2
5 101 5
6 110 6
7 111 7
?
8 1000 8
9 1001 9
10 0 A
11 1 B
12 10 C
13 11 D
14 100 E
15 101 F 13
Exercises
Why doesn’t the unary (only one symbol) numbering system exist?
Think of common method for conversions from any numbering system to any
Convert number %$@$%%@ presented in the numbering system with three symbols %
- 2; @ - 0; $ - 1 to the system with 6 Arabic numbers (0 – 5)
Convert binary number 1011101 into the quarto (четверичная) numbering system
Convert following impulse diagram into binary, octal, hexadecimal and decimal
number (impulse – 1, no impulse – 0)
14
Information Basics
Minimal information unit is one bit with two possible values: 0, 1
One byte contains 8 bits with 2 (256) possible combinations, that is numbers as one combination may
present one number
Non-programmer says that there are 1000 bytes in one Kilobyte and programmer says that there are 1024
meters in one kilometer
How many combinations may be presented in 1 TB: only 2 1024 x 1024 x 1024 x 1024 x 8 = ??? ; 1 TB = 262144
books “War and Peace”
15
Operating Memory
Address 0
10011011 10011011 10011011 00101110 00101100 00101111 00101101 11011011 01111000
Address 107374182414
16
Computing Program, Operating System and
Computing Resources
● Computing Program – sequence of the
commands executed by computing unit
● Telecommunication
● Mobile Phones
● Internet
● Health and Medical
● Entertainment
● Software Tools
● Embedded
● Many others
18
Software Infrastructure
Testing – Test Cases Verification
Tools:
Programming - Implementation
● Computers
● Operating Systems
Design – How implement it
● Databases
● Source Control
Test Cases – Does SW do it
Requirements – SW shall do …
19
Software Iceberg
20
Software Applications
21
Networking
Layers of the OSI Model
22
SW units and Relations between them
Application– SW unit for user’s purpose
25
C/C++ Project and File Types
26
Functions Stack
Push – add to a stack top
27
Function Calls Sequence Diagram
28
Exercise
29
...To be Programmer means
1. To know a programming language
30
Programming Language Basics
Data Types
1
Variables Constants
Operators
3
Temporary result object
Statements
4 Expressions Comments Simple and complex statements
Condition Statements Iterative Statements
Functions / Classes
5
Standard ones User ones
31
Variables
Variable – piece of operating memory defined in the
program text by a programmer with type and name
Examples
Type defines length (number of bytes) and operations
which may be performed with data containing in the
piece of operating memory int A;
A. 1ad A. -_ + 25
B. Ad-fr B. A/B;
D. Ad234_ D. 37%3+-28
E. Df(32) E. A#35/2
34
Operators
Unary Binary Conditional Pointer
● -(number with opposite ● Arithmetical (*,/,% Returns result of the Explained in the C/C++
sign) ; (remainder from division), expression 2 if expression 1 course
-, + ) is true, otherwise returns the
● ++ (increment on 1) ; result of the expression 3
● Logical (==, !=, <, >, <=, >=,
● -- (decrement on 1); ||(or), && (and)). <Expression 1> ? <Expression
2> : <Expression 3>
● ! (logical NOT); ● Bitwise (<< (left shift), >> Example: A<B?B:A
(right shift), | (or), & (and),
● ~ (Bitwise NOT)
^ (Xor)).
Note:“or”, “and”, “Xor” operator perform operation according ➔ “Operator result” is a piece of the operating memory having
to the binary logic table explained later some type but with only R-value
➔ Operator returns result means the creation of “operator
result” with some value
➔ Each operator has priority. If you are not sure, good style to
35
use brackets
= Operator Assignment
A=D=L
36
Operators – Exercises
1. A – variable with R-value 5; B – variable with R-value
3; C – variable with R-value 10;
● What value will be returned after execution of the
following expressions:
A + B – C%(A*B); A-5?B:C
● is the following expression “true” A<=B<=C
37
Shorthand Operators Form
Arithmetical Bitwise
operator operators
Postfix form B=A++ => B=A ; A=A+1 Prefix form B=++A => B=A+1; A=A+1
For example: To add 3 to R-value of variable A and assign result to the variable A => A=A+3
38
Shorthand Form Operators - Exercise
A contains 5, B contains 3, C contains 4
R = (A++)*C % B
R = (A+B)++ * C
39
Statement
40
Conditional Statements “IF- THEN”
Block-schema
if (A==3)
{
D++;
}
41
Conditional Statements “IF-THEN-ELSE”
Block-schema if (A==3)
{
B--;
D++;
}
else
{
B++;
D--;
}
42
IF-THEN and IF-THEN-ELSE Exercises
A contains 5, B contains 3, C contains 4, R contains 10
What result will be in R
if (A>=B)
C = B+=4;
R = B-3;
What result will be in R
if (A-B < R)
if (A>R)
R++;
else
R--;
R+=5;
Draw block-schema for previous exercise
43
Conditional Statements SWITCH/CASE
switch (A)
{
case 0: D++; break;
case 1: D--; break;
}
44
Iterative Statement WHILE-DO
while (A>0)
{
D++;
A--;
}
45
Iterative Statement DO-WHILE
do
{
D =/ 10;
A++;
} while (D !=
0);
46
WHILE-DO & DO-WHILE Exercises
Variable A contains value 200, variable B contains
value 0
1 2 3 4
47
Iterative Statement FOR-DO
48
FOR-DO Exercises
1. for (ind = 0,A=0,B=10; ind < 28; ind++)
A++;
B++;
What value will be in A and in B ?
2. for (ind = 0, B=100; ind < B; ind--);
49
Most Typical Errors
1. if (A=B) instead of A==B
3. for (ind = 0,A=1; ind < N; ind++); //difficult to find out Why?
{
A*=10;
}
50
Integrated Development Platform –
Eclipse – Programmer Working Place
51
C/C++ Development Platform
Open Source
Download from
http://www.eclipse.org/downloads/
52
Integrated Development Environment
53
CDT Installation
54
IDE Verification – “Hello” project creation
Type into
File->New ->
“project Press “Finish”
C Project
name” hello
55
- IDE Verification
Press
cntrl+F11
56
First Program
File->New -> C project
Select “empty project” ->type Multiply into “project
name”->press “Finish”
File->New ->Source File
File->New->Source File
60
Function printf – print formatted
Console – logic device with input/output Some formats:
By default, console input matches keyboard as physical %d – for presentation of an integer number in the
device and output does display as physical device decimal form
Function printf is intended for printing on console %o – for presentation of an integer number in the octal
formatted data in the human form form
#include <stdio.h> //header file containing function %x – for presentation of an integer number in the
prototype hexadecimal form
\t - tabulation
61
Symbol Presentation and Coding
● A symbol is a number
● For using symbols the variables of the type “char” may be used
char symbol = ‘A’; //This Data Type Statement defines variable symbol with
value 65 matching symbol A
62
Exercise
1. Write program for printing ASCII table
The output should look like the following. Note: 4 symbols on each row
63