Lesson 1-Introduction To Programming
Lesson 1-Introduction To Programming
But, since you are going to learn how to write computer programs, you need to know a
little bit about how a computer works. Your job will be to instruct the computer to do things.
Basically, writing software (computer programs) is describing how to do something. In its
simplest form, it is a lot like writing down the steps it takes to do something. The lists of
instructions that you will write are computer programs, and the stuff that these instructions
manipulate are different types of objects, e.g., numbers, words, graphics, etc...
So, writing a computer program can be like composing music, like designing a house,
like creating lots of stuff. It has been argued that in its current state it is an art, not engineering.
An important reason to consider learning about how to program a computer is that the concepts
underlying this will be valuable to you, regardless of whether or not you go on to make a career
out of it. One thing that you will learn quickly is that a computer is very dumb but obedient. It
does exactly what you tell it to do, which is not necessarily what you wanted.
Low-level Programming Languages – are similar to machine languages, but they are much
easier program because they allow a programmer to substitute names for numbers. Assembly
language is equipped with an assembler program.
Note:
The terms “high-level” and “low-level” are inherently relative. Originally, assembly
language was considered low-level and COBOL, C, etc. were considered high-level. Many
programmers today might refer to these latter languages as low-level.
Programmer’s Notes
Software - Software is a generic term for organized collections of computer data and
instructions
Program – are the instructions given to the computer to arrive at a certain result.
Programmer – person specialized in creating computer programs.
Programming – is the process of giving instruction to a computer.
Data - any facts, numbers, or text that can be processed by a computer.
Code – is a set of symbols and/or command used to create a program.
Compiler – program that translate high level programming statements into one or several
machine instructions.
Assembler – program that translate assembly statements into machine instructions.
Machine Language - it is the natural language of a particular computer. It is also called as
Binary Language (1 and 0).
3
Programmers do not sit down and start writing code right away when trying to make a
computer program. Instead, they follow an organized plan or methodology that breaks the
process into a series of task.
Here are the basic steps in trying to solve a problem on the computer.
STEP PROCEDURE
1 Problem Definition
2 Problem Analysis
3 Algorithm design and Representation
4 Coding and Debugging
A programmer is usually given a task in the form of a problem. Before a program can be
designed to solve a particular problem, the problem must be well and clearly defined first in
terms of input and output requirements.
A clearly defined problem is already half the solution. Computer programming requires
us to define the problem first before we even try to create a solution.
After the problem has been adequately defined, the simplest and yet most efficient and
effective approach to solve the problem must be formulated. Usually this step involves breaking
up the problem into smaller and simple sub problems.
Example Problem:
Determine and display the area of a square
Input to the Program:
Sides
4
Process:
Computation Formula: Area=Sides * Sides
Output of the Program:
Area of Square
Once our problem is clearly defined, we can now set to find a solution. In computer
programming, it is normally required to express our solution in a step-by-step manner. Solution
may express through flowchart or pseudocode.
S=0, A=0
1. Set the side and area of the square into zero
2. Read the side of the square
Get S
3. Compute the area using the formula: A=S * S
4. Display the area
A= S * S
After constructing the algorithm, it is now possible to create the source code. Using the
algorithm as basis, the source code can now be written using the programming language.
Sample Code:
Module Square
Dim s, a As Double
Sub Main()
s = Console.ReadLine
a=s*s
Console.ReadKey()
End Sub
End Module
Most of the time, after programmer has written the program, the program isn’t 100%
working right away. The programmer has to add some fixes to the program in case of bugs.
This process is called debugging.
There are two types of errors that a programmer will encounter along the way. The first
one is compile-time error and other is runtime error.
Programmer’s Notes
Compile-Time Errors – Occur if there is a syntax error
Bugs – This are the errors occurs in the
in the code. The compiler will detect error and the
program
program won’t even compile.
Debugging – process of correcting
(Ex. Forgetting to put a comma)
bugs
Runtime Error – This error are also called logic error. The compiler can’t detect as an error.
(Ex. Infinite Loop or incorrect value is computed)
6
Programming Paradigms
From the listed programming paradigms above, we will choose one to be our
programming style. Let’s take a closer look on Structured Programming.
Structured Programming
Program Structure
a. Sequence Control Structure – is used to show a single action or one action followed in
order (sequentially) by another. Actions can be input, process or output.
b. Selection Control Structure – is used to tell the program which action to take, based
on a certain condition. When the condition is evaluated, its result is either true or false.
If the result of the condition is true, one action is performed, and different action is
performed if the result of the condition is false.
c. Repetition Control Structure – also called as looping or iteration is used when a set of
actions is to be performed repeatedly.