1 - Program Logic Formulation

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 60

Ms. Honey Girl A.

Avo
What is a COMPUTER PROGRAM?
a set of instructions for a computer.
receives data, carry out the instructions,
and
produce useful results.
What is COMPUTER PROGRAMMING?
shortened as PROGRAMMING or CODING.
the process of writing, testing,
debugging/troubleshooting, and maintaining
the source code of computer programs.
What is PROGRAMMING LANGUAGE?
an artificial language that can be used to
write programs which control the behavior of
a machine, particularly a computer.
defined by syntactic and semantic rules
which describe their structure and meaning
respectively.
they have some form of written
specification of their syntax and semantics.
What is a PROGRAMMER?
is a person who prepares instructions for
computers.
receives directions from a systems analyst.
also known as software developer.
write, test and maintain the detailed
instructions (computer programs), that
computers must follow to perform their
functions.
The First Programmer

Ada Lovelace
Countess of Lovelace (10 December 1815 27 November 1852)
Born Augusta Ada Byron, was an English writer
chiefly known for her work on Charles Babbage's
early mechanical general-purpose computer, the
analytical engine.
Her notes on the engine include what is
recognised as the first algorithm intended to be
processed by a machine
She is portrayed in popular culture as the "World's
First Computer Programmer".
Ada Lovelace
1) Define the Problem
2)Design a Test Plan
3) Design a Solution
Must understand exactly what the
problem is, before we can begin to solve
it.
Must answer such questions as
Which?, How? and What?.
Define the Scope and Generality of the Solution
Needed
Define the Input and Output
Define Constants and Formulas
Define Basic Computational Needs
Verification is an essential step in program
development.

a Test Plan consists of a list of input data


sets and the correct program result for each,
which often must be computed by hand.
Select and Create an Algorithm
Design the Driver
a part of the program that forms the interface
between the user and the computation.
Design Debugging Printouts
frequent output statements
scattered throughout your code, let you know
what is happening.
used to display the input values before
computation starts and the results after each
important computation.
a list of instructions for carrying out some
process step by step.

a method for solving a well-structured


problem.

the method must be completely defined,


unambiguous and effective.

must terminate; it cannot go on forever.


Steps in cooking pinakbet:
1.Saut pork until light brown.
2.Add bagoong, rice washing, tomato sauce, onions and ginger.
3.Bring to boil.
4.Simmer a few minutes.

5.Add the rest of the ingredients.

5.Cover and simmer for 15 minutes.


Algorithm in computer

Problem: Write an algorithm to read an


integer A then display the value of the integer.

Algorithm:
1. Read an integer A.
2. Display the value of integer A.
Algorithm in computer
Problem: Construct an algorithm to read in
three integers X, Y, Z. Compute the sum of the
three integers then store it to variable SUM.
Display the result.
Algorithm:
1. Read the value of the three integers X, Y,
Z.
2. Compute the sum using the formula
SUM = X+Y+Z.
3. Print SUM.
Exercise:
1.Write the algorithm to compute the average
of three input quizzes.

2.Give the algorithm to convert the input


dollar(s) into its equivalent peso. One dollar
is approximately equal to 50.60 pesos. Then
display the result.

3.Write an algorithm to convert the input


inch(es) into its equivalent centimeters. One
inch is equivalent to 2.54cms. Then display
the result.
Exercise:

4. Given three numbers A, B, and C. Construct


the algorithm to compute and print out the
sum, the average, and the product of these
values.

5. Construct an algorithm that will compute for


the midterm grade of a student. The
midterm grade is equal to one-third of the
minor A exam and two-thirds of the midterm
exam. Print the midterm grade.
Exercise:

6. Construct an algorithm that will input values


for A and B. Compare the two values
inputted and print which of the values is
higher including the remark Higher.

7. Write an algorithm that will input a grade of


student and determine whether the grade is
passed or failed. The passing grade is 75.
Print the name, grade and remarks of
student.
Exercise:

8. Write an algorithm that will display if the


inputted age is qualified to vote or not. The
qualifying age is 18 and above.
Quiz: Algorithm
1. Write an algorithm to read in name and age of student.
Display the inputted values.
2. Celsius (centigrade) temperature C can be converted to
an equivalent Fahrenheit temperature F according to the
following formula:
F = (9/5)C + 32
Write the algorithm that will read in a Celsius temperature
and then output the equivalent Fahrenheit temperature.
3. The straight-line method for computing the yearly
depreciation in value D for an item is given by the
formula
D=PS
Y
where P is the purchase price, S is the salvage value, and
Y is the number of years the item is used. Write an
algorithm that takes as input the purchase price of an
item, its expected number of years of service, and its
expected salvage value, and then outputs the yearly
Flowchart
1. Since
Advantages flowcharts
of Flowchartare language-
independent, they can be learned and
applied without formal knowledge of a
programming language.
2. It enforces users to give attention to
significant matters over the less
significant ones.
3. Being graphically portrayed,
flowcharts provide an alternative to
the usual narrative description of a
system or a program.
4. Flowcharts are easier to understand
than a program written in a particular
Types of Flowchart
Program Flowchart describes graphically in
detail the logical operations and steps within a
program and the sequence in which these
steps are to be executed for the transformation
of data to produce the needed output.
System Flowchart is a graphical
representation of the procedures involved in
converting data on input media to data in
output form.
portray the interaction among data,
hardware, and personnel.
Disadvantages of Flowchart
1. Flowcharts do not represent a programming
language and are more of a person-to-person
than a person-to-computer means of
communication. A computer cannot accept a
program described in flowcharting form.
2. Since thinking in graphic terms is not normal,
flowcharts cannot be viewed as a natural
means of communication.
3. Certain details often require a long sequence
of interconnected symbols which could easily
be described in just a few lines of explanation.
4. It does not convey why a given set of
operations is made. Flowcharts only portray
how.
5. Flowcharts do not highlight the important
details since each step receives as much
NOTATION MEANING NOTATION MEANING
+ Addition Blank
- Subtraction = or EQ Equal to
* Multiplication > or GT Greater than
/ Division < or LT Less than
** Exponentiation <> or or NE Not Equal to
% Modulus > or GE Greater than or Equal to
: Comparison < or LE Less than or Equal to
( ) Grouping Y Yes
Logical or N No
& Logical and EOF End of File
FLOWCHARTING
SYMBOLS
Flowcharting Symbols
Flowcharting Symbols
Flowcharting Symbols

Decision Symbol
(Diamond)

- denotes a point in the


program where more
than one path can be
taken.

- the particular path that


is chosen depends on the
answer to a question or
the result of a test which
is inserted in the symbol.
Flowcharting Symbols
Preparation Symbol (Hexagon)
this symbol is used to represent an
instruction or group of instructions that
will alter, or modify a programs course
of execution.
it is commonly used to specify
operations such as control, index
register, initialization, switch setting,
and in indicating loops.
Flowcharting Symbols
Terminal Symbol (Oval)
used to designate the beginning and the
end of a program, or a point of interruption.
it can also be used elsewhere in the
flowchart for specifying error conditions,
such as parity error checks or detection of
invalid characters.
Flowcharting Symbols
Predefined Process Symbol (Rectangle with Two
Vertical Bars)
a specialized process symbol that
represents a named operation or
programmed step not explicitly detailed
in the program flowchart. As a
subroutine symbol, it can be used when
a procedure needs to be repeated
several times. Rather than write the
instructions for the procedure each time
it is needed, this symbol is used.
Flowcharting Symbols
On-page Connector (Small Circle)
this is a non-processing symbol which is
used to connect one part of a flowchart to
another without drawing flow lines.
denotes an entry or an exit from another
part of the flowchart and also used to change
the reading sequence of a flowchart on the
same page.
conserve space by keeping related blocks
near one another, reduces the number of flow
lines in complex programs, and eliminates
cross lines from taking place.
Flowcharting Symbols
Flow Direction Indicators (Arrowheads)
used to show the direction of
processing or data flow.
these are added to flow lines if a
flowchart appears confusing in its
layout.
Flowcharting Symbols

Off-page Connector (Small Pentagon)


used instead of the on-page connector to
designate entry to or exit from a page when a
flowchart requires more than one page.
Flowcharting Symbols
Flow Lines (Horizontal/Vertical Lines)
flow lines are used to show reading order
or sequence in which flowchart symbols are
to be read.
the commonly accepted practice is to
indicate an arrowhead if the logic flow is
from left to right or from bottom to top.
arrowheads are not required when the
logic flow is from top to bottom or from right
to left. Left to Right

Bottom to Top
Example 1: Sequence
Write an algorithm to read an integer A then display the value of
the integer.
BEGIN
Algorithm:
1. Read the value of integer A.
2. Display the value of integer A. READ A

Flowchart
PRINT A

END
Example 2 : Sequence
Construct an algorithm to read in three integers X, Y, Z.
Compute the sum of the three integers then store it to variable
SUM. Display the result. BEGIN

Algorithm:
1. Read the value of the READ X, Y, Z
three integers X, Y, Z.
Flowchar
2. Determine the sum t
using the formula SUM SUM = X + Y + Z

= X + Y + Z.
3. Print SUM. PRINT SUM

END
Exercise
A. Write the algorithm and draw the flowchart. Given three
numbers A, B, and C. Compute and print out the sum,
the product and the average of these values.

B. The radius of a circle is equal to one unit. Give the


algorithm and draw the flowchart to compute the
corresponding area of the circle and print out the value
of the radius and the area. Use the formula Area = r 2
to get the area of the circle. PI has a value of 3.1416.
Write the algorithm and draw the
flowchart to accept the magic number.
Determine if the input magic number is
right, if it is so, the magic words will be
displayed. The magic number is 143
and its corresponding magic words are
I Love You. If the input number is
wrong, displays: Sorry, better luck
next time.
Draw a flowchart that determines if the
employee has to be paid of overtime
pay (OT). They will be paid an OT if
they exceed 40 hours work in a week,
regular pay (RP) if less than or equal to
40 hours only. Display OT Pay or RP
Pay, based on this condition.
Draw a flowchart that determines if the
input number is positive or negative.
Consider 0 as positive number.
The CCIT Manufacturing Company plans to give
a year-end bonus to each of its employees. Give
the algorithm then draw the flowchart which will
compute the bonus of an employee. Consider
the following criteria: If the employees monthly
salary is less than 1,000.00 pesos, the bonus is
50% of the salary; for employees with salaries
greater than or equal to 1,000.00 pesos, the
bonus is 1,000.00. Print out the name and
corresponding bonus of the employee.
Application of If/else if
Statements and Decision
Symbols
Example:

1. Draw a flowchart that will display the corresponding


color of the given input letter. The corresponding letter of
each color are given below:

Letters Colors
B or b Blue
R or r Red
G or g Green
Y or y Yellow
Other letters Unlisted Color
Example:

2. Draw a flowchart that will display the corresponding


remark of a given input grade. The range of grades and its
corresponding remark are given below:

Range of Grades Colors


90 - 100 Excellent
80 -89 Good
75 - 79 Fair
50 - 74 Poor
Other grades Out-of-range
Draw a flowchart that will display the corresponding college
level of a given input year level. The year and the college
levels are given below:

Year Level College Level


1 Freshmen
2 Sophomore
3 Junior
4 Senior
Other years Unlisted Level
Construct a flowchart that will accept the evaluation score
of a faculty and determine its equivalent remarks. Print the
name of the faculty and the remarks obtained. Remarks are
based on the following criteria:

4.00 5.00 Outstanding


4.00 4.49 Very Satisfactory
3.50 3.99 Satisfactory
3.00 3.49 Poor
2.99 below Poor
Draw the flowchart to read in the age of
an individual and determine if it is
qualified to vote or not. The qualifying
age to vote is 18 and above. If the age
is 18 below, display Too young!. Note
that there are no such ages as 0 or
negative however display Invalid age
and if age is above 100 displays Out of
range.
Loops in Algorithm and Flowcharts

LOOPING is used when it is desired to make the


same calculation on more than one set of data.
consists of repeating a program, or a section of a
program, and substituting new data for each
repetition.

COUNTER a set up in program loop to keep


track of the number of times the program segment
is repeated.
Steps in Loop Control

Initialization
the value of a counter used is initially set equal to 0 or 1.
this process is always done outside the loop.
Test for Limit Conditions
before logic flow gets out of a loop, a loop-terminating condition must
first be satisfied.
the process of testing usually found either at the beginning or at
the end of a loop.
Incrementation
after each loop is executed, 1 is added to the counter.
thus the counter reflects the number of times the operation has been
performed.
note that the process of incrementation is always done within the
loop.
Write the algorithm and draw a
flowchart that will calculate the sum of the
given sequence numbers: 1 2 3 4 5.
That is,
1+2+3+4+5
The sum is: 15
1. Draw a flowchart that determines if the input number is
ODD or EVEN. Odd numbers are 1,3,5,7, and even
numbers are 2,4,6,8,10,

2. Draw a flowchart that will display the corresponding


remark of a given score in 20 items quiz. The range of
scores and its corresponding remarks are given below:
RANGE OF SCORES REMARKS
16 20 Best
10 -15 Better
59 Good
04 Poor
other scores Out-of Range
3. Draw a flowchart that will generate and
print the given sequence numbers:
1
4
27 Sequence
256
3125
3413 Sum
4. Given two numbers X and Y, draw a
flowchart to determine the difference
between X and Y. If X Y is negative,
compute R = X + Y ; if X Y is positive,
compute R = X * Y. Print the value of X, Y and
R. Assume that X Y is not equal to zero.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy