Professional Documents
Culture Documents
Introduction To Programming Program Is Synonymous With Software A Sequence or Set of Instructions
Introduction To Programming Program Is Synonymous With Software A Sequence or Set of Instructions
Introduction To Programming Program Is Synonymous With Software A Sequence or Set of Instructions
2
A short history of Programming Languages
The development of programming languages, unsurprisingly, follows
closely the development of the physical and electronic processes used in today's
computers.
Programming languages have been under development for years and will
remain so for many years to come. They got their start with a list of steps to wire
a computer to perform a task. These steps eventually found their way into
software and began to acquire newer and better features. The first major
languages were characterized by the simple fact that they were intended for one
purpose and one purpose only, while the languages of today are differentiated by
the way they are programmed in, as they can be used for almost any purpose.
And perhaps the languages of tomorrow will be more natural with the invention of
quantum and biological computers.
Charles Babbage is often credited with designing the first computer-like
machines, which had several programs written for them (in the equivalent of
assembly language) by Ada Lovelace.
In the 1940s the first recognizably modern, electrically powered computers
were created. Some military calculation needs were a driving force in early
computer development, such as encryption, decryption, trajectory calculation and
massive number crunching needed in the development of atomic bombs. At that
time, computers were extremely large, slow and expensive: advances in
electronic technology in the post-war years led to the construction of more
practical electronic computers. At that time only Konrad Zuse imagined the use of
a programming language (developed eventually as Plankalkül) like those of today
for solving problems.
Subsequent breakthroughs in electronic technology (transistors, integrated
circuits, and chips) drove the development of increasingly reliable and more
usable computers. The first widely used high level programming language was
Fortran, developed during 1954–57 by an IBM team led by John W. Backus. It is
still widely used for numerical work, with the latest international standard
released in 2004. A Computer Languages History graphic shows a timeline from
Fortran in 1954.
Natural L Programming L
human to machine (vice
Communication Parties human to human
versa)
Mode of
verbal, non-verbal type, record, audio, scan
Communication
What is being feelings, reactions,
Instruction, data
transferred? emotions
Representation:
Words Strings
Sentence Statements
Paragraph Programs
4
A person using a machine/PC can do programs by using compilers or
interpreters.
Levels of Programming Language
There is only one programming language that any computer can actually
understand and execute: its own native binary machine code. This is the lowest
possible level of language in which it is possible to write a computer program. All
other languages are said to be high level or low level according to how closely
they can be said to resemble machine code.
Low-level languages have the advantage that they can be written to take
advantage of any peculiarities in the architecture of the central processing unit
(CPU) which is the "brain" of any computer. Thus, a program written in a low-
level language can be extremely efficient, making optimum use of both computer
memory and processing time. However, to write a low-level program takes a
substantial amount of time, as well as a clear understanding of the inner
workings of the processor itself. Therefore, low-level programming is typically
used only for very small programs, or for segments of code that are highly
critical and must run as efficiently as possible.
The very lowest possible level at which you can program a computer
is in its own native machine code, consisting of strings of 1's and 0's and
stored as binary numbers. The main problems with using machine code
5
directly are that it is very easy to make a mistake, and very hard to find it
once you realize the mistake has been made.
Assembly Language
Compiler Language
6
Typically, the compiled machine code is less efficient than the code
produced when using assembly language. This means that it runs a bit more
slowly and uses a bit more memory than the equivalent assembled program. To
offset this drawback, however, we also have the fact that it takes much less time
to develop a compiler-language program, so it can be ready to go sooner than
the assembly-language program.
Interpreter Language
On the down side, this arrangement requires that both the interpreter and
the user's program reside in memory at the same time. In addition, because the
interpreter has to scan the user's program one line at a time and execute internal
portions of itself in response, execution of an interpreted program is much slower
than for a compiled program.
7
PROGRAMMING BASICS
Planning the Solution
In planning the solution to any problem, it is always necessary that if you
identify the problem you will arrive to a good solution. We must be “more specific”
about the three components: input, process and output.
The result of our planning is a series of procedure that later be converted
into programs.
Structured Programming
This is a technique that makes programs easier to write, check, read and
maintain. This technique emphasized the breaking of a program into logical
sections or “modules” following a universal programming standard. Breaking of
programs into smaller modules will help organize the flow of solution from one
module to next.
Control Structure
It is a series of steps that determines what instructions or set of
instructions will be done next.
3 Basic Control Structures
1. Sequential C.S.
2. Selection C.S.
3. Iteration C.S.
Process 1
Process 2 8
Selection Control Structure
It is used to let your algorithm or program make a decision or choice.
Format:
if (condition) then (process1) else (process2)
if false
if true
use a relational operator
True False
if
Process 1 Process 2
Iteration or Loop
It is used when an algorithm or program repeat a process on a specific
number of times. This repeats an instruction or program until a condition is met.
Process
no
Is the condition
met?
yes
Input / Output
Direction
9
Initialization Box
Examples:
Sequential Control Structure
Problem 1: Create a flowchart the will accept the name and course of a student.
begin
name=” “
course=” “
Input name,
course
end
Problem 2: Create a flowchart that will accept two numbers and output the sum.
begin
n1,n2=0
sum=0
Input n1, n2
sum=n1+n2
Display sum
end
10
Problem 3: Create a flowchart showing the input of four numbers (any type) and
output the average in floating data type.
x
begin
Display
n1,n2,n3,n4=0.0 average
average=0.0
end
Input
n1,n2,n3,n4
average=(n1+n2+n3+n4)/4
begin begin
C, rad=0.0
C, rad=0.0 pi = 3.1416
Input Input
rad rad
Or
C = 2 (3.1416) (rad) C = 2 (pi) (rad)
Display Display
C C
end end
11
Problem 5: Create a flowchart to read a "float" representing a number in
millimeter, and print as a "float" the equivalent value in centimeter, decimeter and
meter.
begin begin
Input Input
mm mm
OR
cm = mm / 10 cm = mm / 10
dm = mm / 100 dm = cm / 10
m = mm / 1000 m = dm / 10
Display Display
cm, dm, m cm, dm, m
end end
Problem 6: Create a flowchart that will accept input from a student name, course
and year. Also, inputs from his class standing (60%) and prelim grade (40%) to
computer for his prelim grade. Finally, display the student name, course and his
prelim grade.
x
begin
Display name,
name, course, yr = “ “ course
CS, PE, PG = 0.0 PG
CS = CS * 0.60
PG = (CS*0.60) + (PE*0.4) PE = PE * 0.40
Or PG = CS + PE
12
Selection Control Structure (Simple)
Problem 1: Create a flowchart that will accept student name and final grade then
identify by displaying also whether his grade “passed” or “failed”.
begin
name = “ “
FG = 0.0
Input name
Input FG
If
FG >=75
end
Problem 2: Input two numbers. Print their sum if the first number entered was
lesser than the second number. Otherwise print their average.
begin
Input n1
Input n2
True False
If
n1 < n2
sum = n1+n2
sum = n1 + n2
average = sum / 2
end
13
Problem 3: Input two numbers and get their difference. From the difference
identify and display whether the difference is a “positive” or a “negative” number.
begin
Input n1, n2
diff = n1 – n2
True False
If
diff > 0
Positive Negative
end
sexcode = ‘ ‘
Input sexcode
True False
If
Sexcode= ‘M’
end
14
Selection Control Structure (Ladderized)
Problem 5: Create a flowchart that will accept input to represent angle (an
integer) and identify whether it is an “acute angle”, a “right angle”, an “obtuse
angle” or a “complex angle”.
begin
Angle = 0
Input Angle
True
If
Acute angle
Angle < 90
False
True
If
Right angle
Angle = 90
False
True
If
Obtuse angle
Angle >= 180
False
Complex angle
end
15
Problem 6: Create a flowchart that will input the student name and his final
grade. Also, identify whether his grade falls on the remarks below and display the
remark that corresponds to his level of standing.
Final Grade Remarks
75 below “very poor”
75 to 80 “poor”
81 to 85 “average”
86 to 90 “good”
91 to 95
begin “very good”
96 “excellent”
FG = 0.0
Input FG
True
If
Very poor
FG < 75
False
True
If
Poor
FG <= 80
False
True
If
Average
FG <= 85
False
True
If
Good
FG <= 90
False
True
If
Very Good
FG <= 95
False
Very Good
end
16
begin
x=1
True
If
x=x+1
x <= 10
False
end
Or
begin
x=0
x=x+1
True
If
x <= 10
False
end
17
Note: the counter increments by 2.
begin
x=0
x=x+2
True
If
Display x
x <= 20
False
end
OR
begin
y = 0, x=0
x=x+2
y=y+1
True
If
Display x
y <= 10
False
end
Problem 3: Create a flowchart that will verify and confirm each password entered
by a user to restrict unauthorized users. Each time the user fail to enter correct
18
password, the computer will display “invalid password” otherwise if password is
correct, then it displays “password accepted”.
Password is “rolmaq”
begin
pw = “ "
Enter pw
False
If Invalid
pw = rolmaq password
True
Password
accepted
end
Problem 4: (same as the problem above only that trial in entering a password
should only be three attempts. After which the process terminates for at most 3
attempts failed to do so).
begin
pw = “ "
ctr=1
True
False
If Invalid
If ctr < 4
pw = “rolmaq" password
True False
Password
accepted end
19