Intro To Programming Module 1A
Intro To Programming Module 1A
Intro To Programming Module 1A
Module 1 of 4 modules
Programming 1
Philip L. Balagtey
09514915726
[email protected]
Information Technology
1st Semester, School Year 2021-2022
INTRODUCTION
A computer is a machine that performs a variety of tasks according to specific
instructions. It is a data processing machine which accepts data via an input device
and its processor manipulates the data according to a program.
This module contains three lessons. The first lesson presents the basic
components of a computer, both hardware and software. The second lesson will give
us a brief overview of programming languages and the development life cycle of a
program. Finally, the third lesson describes the numbers system that computers use.
The number of hours allotted for this module shall be for 7 hours.
LEARNING OUTCOMES
PRE-TEST
Choose the best answer for each question and write the letter of your
choice after the number.
1. What is an electronic device that manipulates data?_____________
a. Computer
b. Mouse
c. Printer
d. Typewriter
1
b. Code.
c. Flowchart
d. Pseudocode
10. Programs that people use to get their work done. _____________
a. Application Software
b. Hardware
c. Operating Software
d. Screwdriver
2
LESSON 1: Components of a Computer System
Objectives:
LET’S ENGAGE
Source: ComputerHope.com
3
Basic Components of a Computer
Hardware
Source: www.computerHope.com
4
Memory
The memory is where data and instructions needed by the CPU to do its
appointed tasks can be found. It is divided into several storage locations which
have corresponding addresses. The CPU accesses the memory with the use of
these addresses.
Main memory
The main memory is very closely connected to the processor. It is used to
hold programs and data, that the processor is actively working with. It is not
used for long-term storage. It is sometimes called the RAM (Random Access
Memory).
Main Memory
www.computerHope.com
Secondary Memory
The secondary memory is connected to main memory. It is used to hold
programs and data for long term use. Examples of secondary memory are hard
disks and flash drives.
Source: www.computerHope.com
5
Volatile Yes No
Input Devices
Source: www.computerHope.com
Output Devices
Software
www.computerHope.com
Computer Computer
Directs/
Software Hardware
Instructs
6
Some Types of Computer Software
System Software
Refers to the operating system and all utility programs that manage
computer resources at a low level.
The BIOS (Basic Input/Output System) gets the computer system started
after you turn in on and manages the data flow between the operating system
and attached devices such as the hard disk, video adapter, keyboard, mouse
and printer.
Application Software
Examples:
Word Processor, Spreadsheet, Computer Games, Image Editor, etc.
Utility Software
Software utility is a computer system software intended to analyze, configure,
monitor, or help maintain a computer. Usually, a utility is smaller than a
standard program in size and may be included with an operating
system or installed separately.
Examples:
Backup Software, Compression utility, Disk partition software, file
manager, registry cleaners, screen savers, etc.
7
Objectives:
LET’S ENGAGE
The same is true with computers; you can never operate them without
using standard languages that will help you translate human readable
instructions to machine acceptable codes. Programming languages are
essential in the development of application software. In turn, these software
application enables you to use the computers for your daily needs.
8
LET’S TALK ABOUT IT
Source: www.techdotmatrix.com
9
Source: www.technodotmatrix.com
Low-level programming language are divided into two categories:
Machine Language and Assembly Language.
Machine Language
Machine language is the sequence of bits (machine code) that directly
controls a processor, causing it to add, compare, move data from one place to
another, and so forth at appropriate times. The computer microprocessor can
process directly the machine codes without a previous transformation.
Specifying programs at this level of detail is an enormously tedious task.
Assembly Language
Assembly language uses structured commands (mnemonics) as
substitutions for numbers allowing humans to read the code easier than
looking at binary. Although easier to read than binary, assembly language is a
difficult language and is usually substituted for a higher language such as C.
Typically, one machine instruction is represented as one line of assembly
code. Assemblers produce object files which may be linked with other object
files or loaded on their own.
10
Source: www.technodotmatrix.com
High level languages are portable (machine independent) as it can be run
on different machines with little or no change.
Furthermore, the rules for programming in a particular high-level
language are much the same for all computers, so that a program written for
one computer can generally be run on many different computers with little or
no alteration. Thus, we see that a high-level language offers three significant
advantages over machine language: simplicity, uniformity and portability.
11
Logical Languages: The programming paradigm in these languages is based
on formal logic. A program written in a logic programming language is a set of
sentences in logical form, expressing facts and rules about some problem
domain.
Language Translator
Source: http://www.vidyagyaan.com
Source: www.differencebetween.info
Assembler
Programmers found it difficult to write or read programs in a machine
language. In their quest for a more convenient language they began to use a
mnemonic (symbol) for each machine instruction, which they would
subsequently translate into machine language. Such a pneumonic machine
language is now called an assembly language. Translator Programs known as
assemblers were written to automate the translation of assembly language into
machine language. As the assembly language is machine dependent, assembler
12
is also a machine dependent system program which must be supplied by the
computer manufacturer.
Interpreter
Source: www.codeforwin.org
Source:www.codeforwin.org
Compiler
A compiler is simply a program which translates a source program
written in a particular programming language to an object program which is
capable of being run on a particular computer. The compiler is therefore both
language and machine dependent. The most important characteristic of a
complier is that its output is a program in some form or another and not an
answer of any kind. A complier must perform at least the following functions:
analysis of source code, retrieval of appropriate subroutines from a library,
storage allocation, and creation of actual machine code.
13
Source: www.greenteapea.com
Program Development Life Cycle
When we want to develop a program using any programming language,
we follow a sequence of steps. These steps are called phases in program
development. The program development life cycle is a set of steps or phases
that are used to develop a program in any programming language.
Problem Definition
Source: www.umich.edu
Problem analysis
After the problem has been adequately defined, the simplest and yet the
most efficient and effective approach to solve the problem must be formulated.
Usually, this step involves breaking up the problem into smaller and simpler
sub problems. Example Problem: Determine the number of times a name
occurs in a list Input to the program: list of names, name to look for Output of
the program: the number of times the name occurs in a list
14
Once our problem is clearly defined, we can now set to finding a solution.
In computer programming, it is normally required to express our solution in a
step-by-step manner. An Algorithm is a clear and unambiguous specification of
the steps needed to solve a problem. It may be expressed in either Human
language (English, Tagalog), through a graphical representation like a flowchart
or through a pseudocode, which is a cross between human language and a
programming language. Now given the problem defined in the previous
sections, how do we express our general solution in such a way that it is
simple yet understandable? Expressing our solution through Human language:
There are two types of errors that a programmer will encounter along the
way. The first one is compile-time error, and the other is runtime error.
15
point, the programmer is unable to form an executable that a user can run
until the error is fixed.
For example, the actual syntax of the code looks okay. But when you
follow the code's logic, the same piece of code keeps executing over and over
again infinitely so that it loops. In such a case, compilers aren't really smart
enough to catch all of these types of errors at compile-time, and therefore, the
program compiles fine into an executable file. However, and unfortunately,
when the end-user runs the program, the program (or even their whole
computer) freezes up due to an infinite loop. Other types of run-time errors are
when an incorrect value is computed, the wrong thing happens, etc.
If you want to know more interesting facts about Programming Languages and
Program Development Life Cycle, visit the following:
Machine Code and High Level Language Using Interpreters and Compilers.
https://www.youtube.com/watch?v=1OukpDfsuXE
Objectives:
LET’S ENGAGE
Computer and humans do not understand each other because it is does
not understand human language because it is arbitrary. But numbers are not
arbitrary, and that is the reason we prefer numbers to interact with computer
and machines. Hence, the number system was discovered. Number System is a
16
system through which we communicate and understand the machine. For
example, for a computer 0 is OFF and 1 is ON. In this lesson, we will discuss
different types of number systems, and their conversion rules.
Examine the table below.
•••
•••
• ••
• • •
••• ••
••• •
•
•
•••
• What do you spot about the dots on the card?
How many dots would the next card have if we continue on the left?
• •these
Use • cards to make numbers by turning some of them face down and
•
adding up the dots that are showing.
Example
•• 7
•• • •
•
6
••
•
••
•
7
•• 17
• •
••
0 0 1 1 1
111 requires cards 4,2 and 1 the rest are facing down.
Using these cards, try to find the binary equivalent of these integers:
17 15 25 19 23
Number System
Decimal Number
We normally represent numbers in their decimal form. Numbers in
decimal form are in base 10. This means that the only digits that appear are 0-
9. Here are examples of numbers written in decimal form:
Binary Numbers
18
Numbers in binary form are in base 2. This means that the only legal
digits are 0 and 1. We need to write the subscript 2 to indicate that the number
is a binary number. Here are examples of numbers written in binary form:
11111102
10112
Octal Numbers
Numbers in octal form are in base 8. This means that the only legal
digits are 0-7. We need to write the subscript 8 to indicate that the number is
an octal number. Here are examples of numbers written in octal form:
1768
138
Hexadecimal
Hexadecimal Numbers in hexadecimal form are in base 16. This means
that the only legal digits are 0- 9 and the letters A-F (or a-f, lowercase or
uppercase does not matter). We need to write the subscript 16 to indicate that
the number is a hexadecimal number. Here are examples of numbers written
in hexadecimal form:
7E16
B16
Decimal to Binary
To convert a decimal number to binary, continuously divide the number
by 2 and get the remainder (which is either 0 or 1), and get that number as a
digit of the binary form of the number. Get the quotient and divide that
number again by 2 and repeat the whole process until the quotient reaches 0
or 1. We then get all the remainders starting from the last remainder, and the
result is the binary form of the number. NOTE: For the last digit which is
already less than the divisor (which is 2) just copy the value to the remainder
portion.
Quotien Remainder
t
126/2 63 0
63/2 31 1
Read this way
31/2 15 1
19
15/2 7 1
7/2 3 1
3/2 1 1
1/2 1
So, writing the remainders from the bottom up, we get the binary
number 11111102
Another Examples:
23/2111
11/251
23 is equivalent to 1 0 1 1 1
34 / 2 17 0
17 / 2 8 1
8/2 4 0
4/2 2 0
2/2 1 0
34 is equivalent to 100010
1/ 2 1
55 109 51 120 98
Binary to Decimal
To convert a binary number to decimal, we multiply the binary digit to "2
raised to the position of the binary number". We then add all the products to
get the resulting decimal number.
0 x 20 = 0
1 x 21 = 2
1 x 22 = 4
1 x 23 = 8
1 x 24 = 16
1 x 25 = 32
1 x 26 = 64
Total 126 20
110110 1110111 x 20 = 1
0 x 20 = 0
1 x 21 = 2 1 x 21= 2
1 x 22 = 4 0 x 22= 0
0 x 23 = 0 1 x 23= 8
1 x 24= 16 1 x 24= 16
1 x 25= 32 1 x 25= 32
Total = 54 Total = 59
Self-assessment: Convert the following binary numbers to decimal numbers.
11101
101101101
10001
101011
1101011
126/8156
15/817
1/81
So, writing the remainders from the bottom up, we get the octal number
176 base 8
21
20
70
90
125
155
For Example (Hexadecimal):
12610 = ? 16
QUOTIENTREMAINDER
7/167
So, writing the remainders from the bottom up, we get the hexadecimal
number 7E16
176
6 x 80 = 6
7 x 81 = 56
1 x 82 = 64
Total 126
7E
14 x 160 = 14
7 x 161 = 112
Total 126
Base on the table above E in hexadecimal is equivalent to 14 in decimal.
Let us try converting 7816 and 9616 to decimal number.
Binary 0to Octal / Octal to Binary
8 x 16 = 8
7 x 161 = 112
Answer: 120
6 x 160 = 6
9 x 161 = 144
Answer: 150
23
For Example:
1111110
0 0 1 1 1 1 1 1 0
1 7 6 Octal number
equivalent
Hexadecimal Binary
Digit Representation
Hexadecim Binary
0 0000
al Digit Representatio
1 0001
n
2 0010
8 1000
3 0011
9 1001
4 0100
A 1010
5 0101
B 1011
6 0110
C 1100
7 0111
D 1101
E 1110
F 1111
Hexadecimal Digits and their corresponding binary representation
24
For Example:
11111102 = ? 16
1 1 1 1 1 1 0
7 E Hexadecimal Number Equivalent
1 1 0 1 1 0 to hexadecimal number
1 1 0 1 1 0
3 6
Answer: 36
1 1 1 0 1 1 to hexadecimal number
1 1 1 0 1 1
3 B (11)
Answer: 3B
25
REFERENCES
26