Beruflich Dokumente
Kultur Dokumente
Introduction to Programming
1 and Visual Basic 6
Computer Systems:
1.1 Hardware and Software
Main memory:
Central
Processing
Unit
Input Output
Device Device
Main
Memory
Secondary
Storage
Slide 1- 4
Slide 1- 5
The CPU-Central Processing Unit
Performs arithmetic and logic operations
Fetches instructions from main memory
Carries out the operations commanded by the
instructions
Each instruction produces some outcome
CPU gets instructions from a program
A program is an entire sequence of instructions
Instructions are stored as binary numbers
Binary number - a sequence of 1’s and 0’s
Slide 1- 6
Computer Hardware
Slide 1- 8
Main Memory
Read-Only Memory (ROM)
The memory from which we can only read but cannot
currently running
RAM is usually a volatile type of memory
Slide 1- 9
RAM ROM
Slide 1- 10
Adding RAM
Slide 1- 11
Secondary Storage
Hard disk drives are most common
Records data magnetically on a circular disk
Slide 1- 12
Hard Drive
Cover Removed
Slide 1- 13
Input Devices
Any type of device that provides data to a
computer from the outside world
For example:
Keyboard
Mouse
Scanner
Slide 1- 14
Output Devices
Any type of device that provides data from a
computer to the outside world
Examples of output data:
A printed report
A sound
Printer
Slide 1- 15
Motherboard
Slide 1- 16
Back of COMPAQ 7000
Input Terminals
110 Volt
110 Volt // 220
220 Volt
Volt
Selection Switch
Selection Switch
Slide 1- 18
Input & Output Terminals
Keyboard
Keyboard Mouse
Mouse
Universal
niversal
Universal
Universal
U USB
USB
SSerial
erial Bus
Serial
Serial Bus
us
Bus
B
Joystick
Joystick
Parallel
Parallel
Printer
Printer
Slide 1- 19
Input & Output Terminals
Monitor
Monitor
Slide 1- 20
Input & Output Terminals
FireWire
FireWire
IEEE
IEEE 1394
1394
Audio
Audio Inputs
Inputs and
and
Outputs
Outputs
Slide 1- 21
Input & Output Terminals
NOT for
NOT for Ethernet Jack
Ethernet Jack
Phone
Phone
Line for
Line for Output for
Output for
Phone Modem
Phone Modem aa Phone
Phone
Slide 1- 22
Cards and Drives
Slide 1- 23
Expansion Cards
VIDEO CARD
FireWire CARD
1394, i.LINK
SOUND CARD
EITHERNET CARD
MODEM CARD
Slide 1- 24
1.2 Number Systems
Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Slide 1- 26
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
Slide 1- 27
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Slide 1- 28
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
Slide 1- 29
Conversion Among Bases
The possibilities:
Decimal Octal
Binary Hexadecimal
pp. 40-
46
Slide 1- 30
Quick Example
Base
Slide 1- 31
Decimal to Decimal (just for fun)
Decimal Octal
Binary Hexadecimal
Next slide…
Slide 1- 32
Weight
Base
Slide 1- 33
Binary to Decimal
Decimal Octal
Binary Hexadecimal
Slide 1- 34
Binary to Decimal
Technique
Multiply each bit by 2n, where n is the
Slide 1- 35
Example
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Slide 1- 36
Octal to Decimal
Decimal Octal
Binary Hexadecimal
Slide 1- 37
Octal to Decimal
Technique
Multiply each bit by 8n, where n is the
Slide 1- 38
Example
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Slide 1- 39
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Slide 1- 40
Hexadecimal to Decimal
Technique
Multiply each bit by 16n, where n is the
Slide 1- 41
Example
Slide 1- 42
Decimal to Binary
Decimal Octal
Binary Hexadecimal
Slide 1- 43
Decimal to Binary
Technique
Divide by two, keep track of the remainder
significant bit)
Second remainder is bit 1
Etc.
Slide 1- 44
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Slide 1- 45
Binary Number System
A Binary Number is made up of only 0s and 1s.
Example of a Binary Number:
110100
There is no 2, 3, 4, 5, 6, 7, 8 or 9 in Binary!
A "bit" is a single binary digit. The number above
has 6 bits.
Slide 1- 46
Words
The word binary comes from "Bi-" meaning two. We see
"bi-" in words such as "bicycle" (two wheels) or "binocular"
(two eyes).
When you say a binary number, pronounce each digit
(example, the binary number "101" is spoken as "one
zero one", or sometimes "one-oh-one"). This way
people don't get confused with the decimal number.
Slide 1- 47
The same thing is done in binary ...
Binary Decimal
0 0 Start at 0
• 1 1 Then 1
••• 11 3 1 more
start back at 0 again, and add one to the number on the left...
•••• 100 4 ... but that number is already at 1 so it also goes back to 0 ...
... and 1 is added to the next position on the left
••••• 101 5
•••••• 110 6
••••••• 111 7
This is
1×8 + 1×4 + 0×2 + 1 + 1×(1/2) + 0×(1/4) +
1×(1/8) = 13.625 in Decimal Slide 1- 49
How to Show that a Number is Binary
Slide 1- 50
Fractions
Binary to decimal
pp. 46-
50
Slide 1- 51
Fractions
p. 50
Slide 1- 52
Examples
Slide 1- 53
Binary Addition (1 of 2)
A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
pp. 36-
38
Slide 1- 54
Binary Addition (2 of 2)
Propagate carries
E.g.,
1 1
10101 21
+ 11001 + 25
101110 46
Slide 1- 55
Multiplication (2 of 3)
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Slide 1- 56
Multiplication (3 of 3)
E.g.,
1110
x 1011
1110
1110
0000
1110
10011010
Slide 1- 57
Programs and
1.3 Programming Languages
Slide 1- 59
What Is a Program?
Computers can only follow instructions
A computer program is a set of instructions on
how to solve a problem or perform a task
Slide 1- 60
Solving problems by computer
1) Identify and analyze the problem.
2) Write the algorithm.
3) Draw the Flowchart.
4) Write the program.
5) Test the program.
6) Documenting the program
Slide 1- 61
1. Identify and analyze the problem.
Identify the given data and its purpose.
Slide 1- 63
FLOWCHART SYMBOLS
Symbol Use in Flowchart
Print “FAIL”
else
Print “PASS”
endif
Slide 1- 65
EX.2: Write an algorithm and draw a flowchart to convert the length
in feet to centimeter
Flowchart
Algorithm
•Step 1: Input L ft
•Step 2: L cm = L ft x 30
•Step 3: Print L cm
Slide 1- 66
Example 3: Draw the flowchart to calculate the value of
y, where y=A+B.
Slide 1- 67
Example 4: Write an algorithm that reads two values, determines the
largest value and prints the largest value with an identifying message.
ALGORITHM
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX = VALUE1
else
MAX =VALUE2
endif
Step 3: Print “The largest value is”,
MAX
Slide 1- 68
Example 4: Draw the flowchart to calculate the sum of
numbers from (1) to (100).
Slide 1- 69
4. Write the program
After completing the flowchart, write the program by
converting the flowchart to a set of sentences understood
by the calculator and these sentences are collectively
called the program.
Slide 1- 70
Programming Languages
The steps in our algorithm must be stated in a
form the computer understands
The CPU processes instructions as a series of
1’s and 0’s called machine language
This is a tedious and difficult format for people
Instead, programming languages allow us to use
words instead of numbers
Software converts the programming language
statements to machine language
Slide 1- 71
Common Programming Languages
Visual Basic C#
Python C
Javascript C++
Java PHP
Slide 1- 72
Methods of Programming
Procedural
Constructed as a set of procedures
procedure
Object-Oriented
is a programming paradigm based on the
Slide 1- 74
Example of an Object
Form elements are
objects called controls
This form has:
Two TextBox controls
Slide 1- 75
Homework:
Slide 1- 76