CHAPTER 1: LOGIC FORMULATION
COMPUTER PROGRAMMING 1
GERALD M. VILLARAN
Laguna State Polytechnic University
Sta. Cruz Campus
College of Computer Studies
LEARNING OBJECTIVES:
At the end of this chapter, the student should be able
to:
• Understand what a Computer Program is.
• Describe what a Programming Language and classify examples of
common languages used by developers in different fields.
• Know what a Programmer is and what the job title entails.
• Describe what an Algorithm is.
• Use Logic in analyzing a problem and designing a solution.
• Understand how Pseudocodes and Flowcharts are used in planning
a solution.
• Apply the Steps in Problem Solving in real-life situations.
Laguna State Polytechnic University
Sta. Cruz Campus
Laguna State Polytechnic University
Sta. Cruz Campus
WHAT IS A PROGRAM?
A computer program is a
detailed plan or
procedure for solving a
problem with a
computer; more
specifically, an
unambiguous, ordered
sequence of
computational
instructions necessary
to achieve such a
solution.
Laguna State Polytechnic University
Sta. Cruz Campus
WHAT IS A PROGRAMMING LANGUAGE?
A programming language is a formal language
which comprises a set of instructions used to
produce various kinds of output. Programming
languages are used to create programs that
implement specific algorithms.
Laguna State Polytechnic University
Sta. Cruz Campus
WHAT IS A PROGRAMMING LANGUAGE?
Laguna State Polytechnic University
Sta. Cruz Campus
PROGRAMMING PARADIGMS
Laguna State Polytechnic University
Sta. Cruz Campus
WHAT IS A PROGRAMMER?
Alternatively referred to as a coder or software
developer, a programmer is an individual who
writes code or creates software for a living.
Many programmers who program for a profession
have a college degree in computer science. While
each job differs, most programmers are
responsible for creating the software program or
parts of a program, debugging problems, or
adding onto a program.
Laguna State Polytechnic University
Sta. Cruz Campus
Women were the first programmers.
Laguna State Polytechnic University
Sta. Cruz Campus
ADA LOVELACE
Augusta Ada King-Noel
Countess of Lovelace
English mathematician and
writer
known for her work on Charles
Babbage's proposed mechanical
general-purpose computer,
the Analytical Engine.
Laguna State Polytechnic University
Sta. Cruz Campus
ENIAC
ENIAC is the acronym for Electronic Numerical Integrator
and Computer. It was one assignment of the ballistic lab
USA with Moore School of Philadelphia. The chief
engineer was J. Presper Eckert and the consulting
engineer was John W. Mauchly. ENIAC was finished in 1945
and in 1947, it was moved to Aberdeen test area where it
was modified for its improvement. In 1955, it was not
active anymore. ENIAC was important to define the
architecture of modern computers or the von Neumann
Laguna State Polytechnic University
architecture.
Sta. Cruz Campus
THE VON NEUMANN ARCHITECTURE
A von Neumann architecture
machine, designed by physicist and
mathematician John von Neumann
(1903–1957) is a theoretical design
for a stored program computer that
serves as the basis for almost all
modern computers.
Laguna State Polytechnic University
Sta. Cruz Campus
ENIAC
It was a computer for a general
purpose and it was able to solve various
problems like differential calculus and
integral. It consisted of 20 adder
accumulators, a multiplier and a square root
divider. Also, it had one master programmer,
more than one only lecture intern memory of
312 numbers and another extern memory
made by keypunch which could read and
print.
Laguna State Polytechnic University
Sta. Cruz Campus
ENIAC
The women of ENIAC, as they
were called.
In the photo, it can be seen how
complicated was to program by
connecting cables and setting
switches.
Laguna State Polytechnic University
Sta. Cruz Campus
Vacuum Tubes
of the ENIAC
Laguna State Polytechnic University
Sta. Cruz Campus
Laguna State Polytechnic University
Sta. Cruz Campus
WHAT IS LOGIC?
Logic is something that guides the behavior of
the code according to the external conditions; a
good knowledge of logic fits to fairly wide
range of issues starting from databases and to
low level code.
Mathematics and logic are among the most useful
skills in computer programming next to
creativity.
Laguna State Polytechnic University
Sta. Cruz Campus
Laguna State Polytechnic University
Sta. Cruz Campus
ALGORITHMS
COMPUTER PROGRAMMING 1
WHAT IS AN ALGORITHM?
A programming algorithm is a computer procedure
that is a lot like a recipe (called a procedure)
and tells your computer precisely what steps to
take to solve a problem or reach a goal.
An algorithm takes ingredients called inputs,
performs a process and repeats until the desired
results, called outputs, are achieved.
Laguna State Polytechnic University
Sta. Cruz Campus
BUBBLE SORT
Bubble Sort is the simplest sorting algorithm
that works by repeatedly swapping the adjacent
elements if they are in wrong order.
Laguna State Polytechnic University
Sta. Cruz Campus
MERGE SORT
Merge Sort is a Divide and Conquer algorithm.
Divide and conquer algorithms divide the
original data into smaller sets of data to solve
the problem.
Laguna State Polytechnic University
Sta. Cruz Campus
MERGE SORT
Average Case
Laguna State Polytechnic University
Sta. Cruz Campus
MERGE SORT
Normal Case
Laguna State Polytechnic University
Sta. Cruz Campus
OTHER SORTING ALGORITHMS
Insertion Sort
Quicksort
Heapsort
Counting Sort
Radix Sort
Etc…
Laguna State Polytechnic University
Sta. Cruz Campus
Laguna State Polytechnic University
Sta. Cruz Campus
Popular Algorithms
Euclidean Algorithm
Face Detection Algorithm
Page Ranking Algorithm
Gale Shapley Algorithm
Air Traffic Control
Laguna State Polytechnic University
Sta. Cruz Campus
AL-KHWARIZMI
Abu Ja’far Muhammad ibn
Musa al-Khwarizmi
(780 – 850 CE)
The grandfather of
computer science and
the father of Algebra.
Laguna State Polytechnic University
Sta. Cruz Campus
PSEUDOCODE AND FLOWCHARTS
COMPUTER PROGRAMMING 1
PSEUDOCODE
Pseudocode is an
informal high-level
description of the
operating principle of
a computer program or
other algorithm. It
uses the structural
conventions of a normal
programming language,
but is intended for
human reading rather
than machine reading.
Laguna State Polytechnic University
Sta. Cruz Campus
COMMON PSEUDOCODE NOTATIONS
INPUT – indicates a user will be inputting something
OUTPUT – indicates that an output will appear on the
screen
WHILE – a loop (an iteration that has a condition at the
beginning)
FOR – a counting loop (iteration)
REPEAT – UNTIL – a loop (iteration) that has a condition
at the end
IF – THEN – ELSE – a decision (selection) in which a
choice is made
any instructions that occur inside a selection or
iteration are usually indented
Laguna State Polytechnic University
*beginners may not be able to grasp the concepts of these notations since they
Sta. Cruz Campus
FLOWCHARTS
A flowchart is a
diagram that depicts
the flow of instruction
in a system or computer
algorithm. They are
widely used to
communicate often
complex processes in
clear, easy-to-
understand diagrams.
Laguna State Polytechnic University
Sta. Cruz Campus
FLOWCHART SYMBOLS
Laguna State Polytechnic University
Sta. Cruz Campus
WHEN TO USE WHICH?
Pseudocode is linear (i.e. a sequence of lines
with instructions), a flowchart is not.
Therefore, flowcharts are a higher abstraction
level, used before writing pseudocode or for
documentation. Flowcharts have, in my opinion,
two strong advantages over pseudocode: Firstly,
they are graphical.
Laguna State Polytechnic University
Sta. Cruz Campus
WHEN TO USE WHICH?
The advantages of flowcharts is that they are
capable of showing the overall flow of
instruction and data from one process to
another. We can get the main concept of the
whole program at just a glance.
Laguna State Polytechnic University
Sta. Cruz Campus
WHEN TO USE WHICH?
However, the advantage of pseudocode over
flowchart is that it is very much similar to the
final program code. It requires less time,
precision and space to. The beauty of it is that
even if the are some common pseudocode
notations, you can write it your way with no
fixed rules.
Laguna State Polytechnic University
Sta. Cruz Campus
WHEN TO USE WHICH?
Flowcharts are recommended for learners since it
is graphical and do not need any programming
knowledge to understand unlike with pseudocodes.
Laguna State Polytechnic University
Sta. Cruz Campus
NOTE
Pseudocode and Flowcharts act as a blueprints in
planning a software design. However, a program
may stray away from these blueprints as they
become more complex.
Developers may opt to use other modeling tools
to express the operating principles of their
program or software. These diagrams are
discussed in future courses such as System
Analysis and Design & Software Engineering.
Laguna State Polytechnic University
Sta. Cruz Campus
FLOWCHART PROGRAMS
Laguna State Polytechnic University
Sta. Cruz Campus
STEPS IN PROBLEM
SOLVING
COMPUTER PROGRAMMING 1
STEPS IN PROBLEM SOLVING
1. Understand the Problem
2. Design a Solution
3. Implement your Solution
4. Check your Solution
Laguna State Polytechnic University
Sta. Cruz Campus
UNDERSTAND THE PROBLEM
Solving the right problem is the most important
part of problem solving. Be sure, absolutely
100% positively sure, that you understand the
problem before attempting a solution. This
involves:
• Reading the problem description
• Research on existing articles/ papers that
discusses similar problems
• Look at smaller examples
Laguna State Polytechnic University
Sta. Cruz Campus
DESIGN A SOLUTION
Formulate an algorithm to solve your problem
1. Understand the problem and focus on the high-level
goals
2. Understand the data requirements
Inputs
Outputs
3. Work on the processes involved in producing the
desired result
4. Use modeling tools: pseudocode and/or flowcharts
5. Divide and Conquer
6. Modularize
Laguna State Polytechnic University
Sta. Cruz Campus
IMPLEMENT YOUR SOLUTION
1. Understand what the intended output
requirements
2. Rather than doing this linearly, implement
small chunks at a time.
3. Handle syntax errors by systematically
commenting out blocks of code until you find
the block that causes the problem.
4. Handle logical errors by tracing your output
line by line.
Laguna State Polytechnic University
Sta. Cruz Campus
CHECK YOUR SOLUTION
1. Make sure all data requirements are met.
2. Test your program with different inputs:
Values
Volume
3. Try to break the program.
4. List down errors and formulate
recommendations
Laguna State Polytechnic University
Sta. Cruz Campus
BASIC PROGRAM STRUCTURES
COMPUTER PROGRAMMING 1
BASIC PROGRAM STRUCTURES
SEQUENCE
DECISION
ITERATION
SELECTION
Laguna State Polytechnic University
Sta. Cruz Campus
SEQUENCE
A sequence is the simplest
flowcharting construction. You
do each step in order.
Laguna State Polytechnic University
Sta. Cruz Campus
DECISION (SELECTION)
"If Then.. Else" or a
conditional.
A question is asked
in the decision shape.
Depending on the answer
the control follows
either of two paths.
Laguna State Polytechnic University
Sta. Cruz Campus
SELECTION
Laguna State Polytechnic University
Sta. Cruz Campus
ITERATION (LOOP)
Do While While Loop
Loop
This structure allows you to repeat a task over and
over.
Laguna State Polytechnic University
Sta. Cruz Campus
ITERATION (LOOP)
For Loop
a control flow
statement for
specifying iteration,
which allows code to
be executed
repeatedly.
Laguna State Polytechnic University
Sta. Cruz Campus
CHAPTER SUMMARY
• Computer Program
• Programming Languages
• Programmer
• Algorithm
• Logic
• Pseudocode and Flowcharts
• Steps in Problem Solving.
Laguna State Polytechnic University
Sta. Cruz Campus
Thank You