Sie sind auf Seite 1von 76

Chapter

Introduction to Programming
1 and Visual Basic 6
Computer Systems:
1.1 Hardware and Software

Computer Systems Consist of Similar


Hardware Devices and Components
Computer Hardware

 Refers to the physical components


 Not one device but a system of many devices
 Major types of components include:
 Central Processing Unit

 Main memory:

 Random Access Memory (RAM)


 Read-Only Memory (ROM)
 Secondary storage devices
 Input devices
 Output devices
Slide 1- 3
Organization of a Computer System

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

Central Processing Unit (CPU)


or
Microprocessor
Slide 1- 7
Central Processing Unit

Slide 1- 8
Main Memory
 Read-Only Memory (ROM)
 The memory from which we can only read but cannot

write on it. This type of memory is non-volatile. A ROM


stores such instructions that are required to start a
computer.
 Commonly known as Random Access Memory, or just RAM
 Holds instructions and data needed for programs that are

currently running
 RAM is usually a volatile type of memory

 Contents are lost when power is turned off

 Used as temporary storage

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

 Provides fast access to large amounts of data

 Optical devices store data on CD’s as pits


 USB flash memory devices
 High capacity device plugs into USB port

 Portable, reliable, and fits easily in a pocket

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

 An image such as a picture

 A sound

 Common output devices include:


 Monitor (display screen)

 Printer

Slide 1- 15
Motherboard

Slide 1- 16
Back of COMPAQ 7000

Input Terminals

Input & Output


Terminals

Input & Output


Terminals
Input & Output
Terminals
Slide 1- 17
Power Input
AC Power
AC Power Input
Input

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

2510 = 110012 = 318 = 1916

Base

Slide 1- 31
Decimal to Decimal (just for fun)

Decimal Octal

Binary Hexadecimal

Next slide…

Slide 1- 32
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

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

“weight” of the bit


 The weight is the position of the bit,

starting from 0 on the right


 Add the results

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

“weight” of the bit


 The weight is the position of the bit,

starting from 0 on the right


 Add the results

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

“weight” of the bit


 The weight is the position of the bit,

starting from 0 on the right


 Add the results

Slide 1- 41
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810

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

 First remainder is bit 0 (LSB, least-

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.

A single binary digit (like "0" or "1") is called a "bit".


For example 11010 is five bits long.
The word bit is made up from the words "binary digit"

Slide 1- 47
The same thing is done in binary ...
  Binary Decimal  
  0 0  Start at 0

• 1 1  Then 1

•• 10 2  Now start back at 0 again, but add 1 on the left

••• 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   

Start back at 0 again (for all 3 digits), 


•••••••• 1000 8  add 1 on the left

••••••••• 1001  9 And so on! Slide 1- 48


Position
In the Decimal System there are Ones, Tens, Hundreds, etc
In Binary there are Ones, Twos, Fours, etc, like this:

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

To show that a number is a binary number, follow it with a


little 2 like this: 1012

This way people won't think it is the decimal number "101"


(one hundred and one).

Slide 1- 50
Fractions

 Binary to decimal

10.1011 => 1 x 2-4 = 0.0625


1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875

pp. 46-
50
Slide 1- 51
Fractions

 Decimal to binary .14579


x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.

p. 50

Slide 1- 52
Examples

 Example: What is 11112 in Decimal?

 Answer: 1111 = 8+4+2+1 = 15 in Decimal

 Example: What is 1.12 in Decimal?

 1.1 is "1 and 1 half" = 1.5 in Decimal

Slide 1- 53
Binary Addition (1 of 2)

 Two 1-bit values

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)

 Two n-bit values


 Add individual bits

 Propagate carries

 E.g.,

1 1
10101 21
+ 11001 + 25
101110 46

Slide 1- 55
Multiplication (2 of 3)

 Binary, two 1-bit values

A B AB
0 0 0
0 1 0
1 0 0
1 1 1

Slide 1- 56
Multiplication (3 of 3)

 Binary, two n-bit values


 As with decimal values

 E.g.,

1110
x 1011
1110
1110
0000
1110
10011010

Slide 1- 57
Programs and
1.3 Programming Languages

A Program Is a Set of Instructions a Computer


Follows in Order to Perform a Task
A Programming Language Is a Special Language
Used to Write Computer Programs
Software
 The programs that run on a computer
 Two major categories
 Operating systems

 Controls the processes within the computer


 Manages the computer's hardware devices
 Application Software
 Solve problems or perform tasks needed by users
 Examples include word processing, spreadsheets,
games, Internet browsers, playing music, etc)
 Each program is referred to as an application
 This material develops applications in Visual Basic

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

 In order solving problems by computer, we must


perform the steps on the following slide

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.

2. Write the algorithm


An algorithm is a procedure or formula for solving a
problem, based on conducting a sequence of specified actions.

Ex.: Write an algorithm to determine a student’s final grade


and indicate whether it is passing or failing. The final grade is
calculated as the average of four marks..
Step1: Input M1, M2, M3, M4
Step2: Grade = (M1+M2+M3+M4)/4
Step3: if (Grade < 50) then
Print “FAIL”
else
Print “PASS”
endif
Slide 1- 62
3. Flowchart

A graphical representation of the sequence of operations in


an information system or program. Information system
flowcharts show how data flows from source documents
through the computer to final distribution to users. Program
flowcharts show the sequence of instructions in a single
program or subroutine. Different symbols are used to draw
each type of flowchart.

Slide 1- 63
FLOWCHART SYMBOLS
Symbol Use in Flowchart

Denotes the beginning or end of the program

Denotes an input and out put operation

Denotes a process to be carried out e.g. addition,


subtraction, division etc.

Denotes a decision (or branch) to be made. The


program should continue along one of two routes.
(e.g. IF/THEN/ELSE)

Used for connecting

Denotes the direction of logic flow in the program


Slide 1- 64
Step1: Input M1, M2, M3, M4
Step2: Grade =
(M1+M2+M3+M4)/4
Step3: if (Grade < 50) then

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.

5. Check the program and correct the errors.

6. Documenting the program


After ensuring that the program works correctly, it is
documented so that others can benefit from it.

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

 Visual Basic is not just a programming language


 It’s a programming environment with tools to:
 Create screen elements
 Write programming language statements

Slide 1- 72
Methods of Programming
 Procedural
 Constructed as a set of procedures

(operational, functional units)


 Each procedure is a set of instructions

 The sum of numbers from (1) to (100) is a

procedure
 Object-Oriented
 is a programming paradigm based on the

concept of "objects", which may contain data, in


the form of fields, often known
as attributes; and code, in the form of
procedures, often known as methods.
Slide 1- 73
Example of an Object
 This is a Visual Basic
GUI (graphical user interface)
object called a form
 Contains data and actions

 Data, such as Hourly Pay

Rate, is a text property


that determines the
appearance of form objects
 Actions, such as Calculate Gross Pay, is a method that

determines how the form reacts


 A form is an object that contains other objects such as

buttons, text boxes, and labels

Slide 1- 74
Example of an Object
 Form elements are
objects called controls
 This form has:
 Two TextBox controls

 Four Label controls

 Two Button controls

 The value displayed by


a control is held in the text property of the control
 Left button text property is Calculate Gross Pay
 Buttons have methods attached to click events

Slide 1- 75
Homework:

1.Example: What is 101012 in Decimal?

2.Write an algorithm and draw a flowchart that


will read the two sides of a rectangle and
calculate its area.

3.Write an algorithm that reads three numbers and


prints the value of the largest number.

Slide 1- 76

Das könnte Ihnen auch gefallen