Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Programming Basics Part1

This document provides an overview of the topics that will be covered in a programming basics course, including: computer systems and digital representation of data, numbering systems, memory and storage units, operating systems, software categories and development process, networking fundamentals, and programming languages. Specific topics mentioned include binary, octal, hexadecimal, and decimal numbering systems, bytes and larger storage units, the roles of programs and operating systems, software development lifecycles, the OSI networking model, and graphical user interfaces.

Uploaded by

elgreka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Programming Basics Part1

This document provides an overview of the topics that will be covered in a programming basics course, including: computer systems and digital representation of data, numbering systems, memory and storage units, operating systems, software categories and development process, networking fundamentals, and programming languages. Specific topics mentioned include binary, octal, hexadecimal, and decimal numbering systems, bytes and larger storage units, the roles of programs and operating systems, software development lifecycles, the OSI networking model, and graphical user interfaces.

Uploaded by

elgreka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Programming

Basics
course
by Dr. Yuri Granovsky
Content
Computer Digital World

Numbering System Notation

Information Basics

Software Basics

Networking

Operating System

Programming Language Basics

Operators
Content
Statement

Most Typical Errors

Integrated Development Platform

First Program Explanation

Function printf

Symbol Presentation and Coding

Exercise
Personal Computer Devices

4
Beyond Personal Computer

Network – no limits for computing


possibilities

5
Embedded Systems

6
What is the Common

● Signals Performing commands ● Signals


● Text by computing Unit (CPU) ● Text
● Video ● Video
● Sound ● Sound
● Output for another ● Output for another
Computing Unit Computing Unit

7
Computer Digital World
● Computer is appliance able to keep and process a
huge amount of data with a huge speed

● Computer commands and data are nothing but digits


and numbers
● All output computer devices are converters from digits
to either some human presentation level
(text,sound,video) or signals (radio waves, phone,
controlling, etc.)
● All input computer devices are converters from either
human presentation level or signals to digits
● Computing unit processes digits –how is out of the
Programming course
8
Exercises
Put kind of a computer device (input or output or
input/output) for following examples

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

● Human presentation Coding: Decimal –


Arabic system (Zero – 0, One- 1,…Nine – 9)
● Human binary presentation -
10111000111100

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

● Sequential division of decimal number on 2 4 100


until the last division result is 1 ☹
5 101
● 1 concatenated with sequence of all
reminders from last to first forms the binary 6 110
presentation 7 111

Think of decimal number 4 with binary 8 1000


presentation 100 9 1001
11
Octal Numbering System
Decimal Octal Binary

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

Binary number is divided on groups with 3 5 5 101


binary digits (division is done from the end – 6 6 110
why?) and each such group presents octal
7 7 111
digit
8 8 1000

9 9 1001
12
Decimal Binary Hexadecimal

Hexadecimal Numbering System 0 0 0

1 1 1

2 10 2

Think of how to convert binary number to 3 11 3

hexadecimal and vice versa 4 100 4

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?

What the numbering system does the number 1011101 present?

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

Minimal information unit addressable in as operating memory as in external storage is byte

One byte contains 8 bits with 2 (256) possible combinations, that is numbers as one combination may
present one number

1024 bytes = 1 Kilobyte (KB)

1024 Kilobytes = 1 Megabyte (MB)

1024 Megabytes = 1 Gigabyte (GB)

1024 Gigabytes = 1 Terabyte (TB)

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

00101101 10011011 10011011 00101110 00101100 00101111 00101101 11011011 01111000

00101101 10011011 10011011 00101110 00101100 00101111 00101101 11011011 01111000

00101101 10011011 10011011 00101110 00101100 00101111 00101101 11011011 01111000

00101101 10011011 10011011 00101110 00101100 00101111 00101101 11011011 01111000

00101101 10011011 10011011 00101110 00101100 00101111 00101101 11011011 01111000

11011011 01111000 11011011 01111000 11011011 01111000 11011011 01111000 11011011

11011011 01111000 11011011 01111000 11011011 01111000 11011011 01111000 11011011

Address 107374182414
16
Computing Program, Operating System and
Computing Resources
● Computing Program – sequence of the
commands executed by computing unit

● Applicative Program – computing program


running for some applicative purpose (e.g.
Power Point, Game, etc.)
● Operating System – computing program
intended for
- Scheduling of applicative programs
- Control of applicative programs
- Resources (memory, CPU) allocation for
applicative programs
- Performing of the Input/output operations Operating Memory and CPU
are the computing resources
for applicative programs
17
Software Areas
● Industrial

● 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

Graphical User Interface – GUI Business Logic Data search

Thick Client Concurrency

Thin Client Services

21
Networking
Layers of the OSI Model

22
SW units and Relations between them
Application– SW unit for user’s purpose

Program – SW unit for internal Application’s


purpose (API – Application Program Interface)

Process – SW unit interfacing with OS for


getting memory and CPU

Thread – SW unit interfacing with Process for


getting CPU and running computing
operations
23
Open Sources and Open Standards
Open Source – code you may download from internet for
any OS

Open Standard – Protocols, Languages, API’s issued by


known organizations (RFC, IEEE, ANSI, ASCII, many
others)

ASCII - American Standard Code for Information


Interchange

ANSI - American National Standard Institute

RFC – Internet Standards (Request for Comments)

IEEE - Institute of Electrical and Electronics Engineers

Ocean of standard acronyms 24


Program Interface with Operating System- OS
Multi Layers – Multi brokers

Function – set operations Class – data and methods


with input parameters and definition
returned result x=f(y) Method – What may be done
with data

25
C/C++ Project and File Types

26
Functions Stack
Push – add to a stack top

Pop – remove from a stack top

Only top of the stack is accessible

Only function at the stack top is running

Once function ends it gets out from the stack

27
Function Calls Sequence Diagram

28
Exercise

1. How many functions does


“main” calls?
2. Which functions are not
called?
3. Which functions don’t call
any other functions?
4. Draw snapshot of a stack
with maximal amount of
the functions into a stack

29
...To be Programmer means
1. To know a programming language

2. To know the programming patterns


3. To understand a task
4. To know dividing of a complex task on many
simple ones
5. To know finding out a computing solution for a
task
6. To know expressing of the solution on a
programming language
7. To know testing of the solution

30
Programming Language Basics
Data Types
1
Variables Constants

Data Types Statements


2
Variables definitions

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;

Name defines reference to the piece of operating char B;


memory which will be converted to an address
float C;
For separation of two different values of “A” in the
int – for integer numbers with length depending
A=A+B expression there are two terms: L-value (left on CPU (usually 4 bytes)
value) and R-value (right value)
char – for integer numbers with one byte of the
length
Each variable presents some L-value and R-value
float – for fractures numbers 32
Name and Expression

Possible but not recommended to use one-letter names.

Name should reflect some meaning (e.g. count)


33
Name and Expression Exercises
1. Which names are right and which are 2. Which expressions are right and which are
wrong: wrong

A. 1ad A. -_ + 25

B. Ad-fr B. A/B;

C. ____ (all underscores) C. L-

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

● Regular operator from the point of returning a


result
● The lowest priority (why ?)
● All operators are executed from left to right
but “=“ is from right to left (why ?)
A = B+C+D

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

2. What is the common between variable and operator


result?

3. What is the difference between variable and


operator result?

4. What is wrong and How to fix the following


expression A – C + D = 5?

37
Shorthand Operators Form
Arithmetical Bitwise
operator operators

+=, -=, *=, /= <<=, >>=, |=, &=

A=A+3 => A+=3 A<<=3 => A=A<<3

A=A+1 => A+=1=>A++ => ++A

A=A-1 => A-=1 => A-- => --A

Postfix form B=A++ => B=A ; A=A+1 Prefix form B=++A => B=A+1; A=A+1

B=A-- => B=A ; A=A-1 B=--A => B=A-1; A=A-1

When an expression contains L-Value and R-Value of the same variable:

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

What will result be in R?

R = (A++)*C % B

What will result be in R?

R = (A+B)++ * C

What will result be in R and in A?

R = A<B ? ++A : A++

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

What value will be in B after execution of the


following

1 2 3 4

while (A--) while (A--) do do


{ { { {
B++; B++; B++; B++;
} } } while (A--); } while
(--A);

47
Iterative Statement FOR-DO

for (ind = 0,A=1; ind < N; ind++)


{
A*=10;
}

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--);

2.1 How many iterations will be performed

2.2 Update only one symbol for performing


100 iterations

49
Most Typical Errors
1. if (A=B) instead of A==B

2. while (A>0) ; //easy to find out Why?


{
D*=10;
A--;
}

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

Development Platform CDT – C/C++


(Eclipse) + Development Development Tools, JDT CDT Installation – see
Tools (Compiler, Builder, – Java development next slide
Debugger, etc.) tools

53
CDT Installation

Launch Put to “work Select


C/C++ with: Wascana and
Eclipse help -> install http://svn.cod press “next” Restart
Development new software espot.com/a/e and follow Eclipse
platform clipselabs.org/ the
wascana/repo instructions

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

Type test_multiply.c into Source file -> press “Finish

Type into editor area the following

File->New->Source File

Type multiply.c into Source file -> press “Finish

Type into editor area the following


Project ->”build all” (in output area there should be
Build complete for project Multiply)
cntrl+F11 => Nothing happened ☺ 57
First Program Explanation – Prototype of
Function

int multiply(int op1, int op2);

#include <assert.h> - header file containing prototypes of the


standard function assert
58
First Program Explanation – Function Call

assert (4==multiply(2,2)) Standard function causing abnormal exit from


the program in the case if the passed expression
is “false”

multiply(2,2) Our function returning multiplication result of first


parameter on the second
59
First Program Explanation – Function Body

“main” function for testing of


multiply function

multiply function for


multiplying of two numbers

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

printf (“hello world”); %c – for symbol presentation

printf (“first operand is %d \n second operand is %d \n Escape sequences


result is %d”, op1, op2, result);
\n – new line

\t - tabulation
61
Symbol Presentation and Coding
● A symbol is a number

● Coding is the mapping between symbol and number

● One byte – one char matches code ASCII

● Code ASCII defines standard for coding of English, punctuation marks


and symbols for example, number 65 is coding symbol A and number 97
is a

● No need to remember the numbers as there are ASCII constants, for


example ‘A’

● 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

2. Whole range of printable symbols is from 33 to 126

3. Function main is as follows

The output should look like the following. Note: 4 symbols on each row

63

You might also like