0% found this document useful (0 votes)
10 views

Week 2part 1 DCIT22 Introduction To Program Logic Formulation and Program Coding

Uploaded by

idashuuu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Week 2part 1 DCIT22 Introduction To Program Logic Formulation and Program Coding

Uploaded by

idashuuu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

DCIT22-Computer Programming I

Lesson 1:

Introduction to Program
Logic Formulation and
Program Coding

Prepared by:
Ms.Mariella R. Leyba, MIT
OBJECTIVES
After the completion of the chapter, students will be
able to:

1. Understand the algorithms, as part of software


development;
2. Define and identify the symbols used in
flowcharting;
3. Analyze and design pseudocode and flowchart in
solving a problem; and
4. Create an algorithms, pseudocode, and flowchart
in solving a problem.
ALGORITHMS
It is a step by step
instructions to solve a
specific problem.
ALGORITHMS

How to get ready for


1. Wake up.
school:
2. Eat breakfast.
3. Practice good hygiene.
4. Get dressed.
5. Take everything you need.
6. Head out the door.
7. Ride your school bus.
“An algorithm is a
representation of a
solution to a problem.”
There are two commonly used tools to help document
program logic (the algorithm):
1. Pseudocode
2. Flowchart PSEUDOCODE

- is simply a numbered list of


instructions to perform some task.
- it is a simpler version of a
programming code in plain English
before it is implemented in a
specific programming language.
- it is meant to be a high-level way
of representing an algorithm
without tying it to a specific
language.
PSEUDOCOD
E

Ways of Writing a Pseudocode:

1.Number each instruction;


○ This is to enforce the notion of an ordered
sequence of operations.
○ Furthermore we introduce a dot notation (e.g.
3.1 comes after 3 but before 4) to number
subordinate operations for conditional and
iterative operations

2.Each instruction should be


unambiguous and effective; and
Basic Elements of Pseudocode:
1. Variable

- having a name and value.


Example: number = 1
(name) (value)

- There are two operations performed on a variable.

• Assignment Operation
• Read Operation
Basic Elements of Pseudocode:
2. Assigned Operation

- the one which associates a value to a


variable.
- While writing Pseudo-code you may follow your own
syntax.

Some of the possible syntaxes are:


- Assign 1 to number
- Set number equal to 1 Pseudocode:
Step 1: Start
1. Example: number = 1
Step 2: Assign 1 to number.
(name) (value)
Step 3: End
Pseudocode:
first_name = “Mariella” Step 1: Start
(name) (value) Step 2: Set first_name is equal to “Mariella”.
Step 3: End
Basic Elements of Pseudocode:

3. Read Operation
- intends to retrieve the value previously
assigned to that variable.
Example:
- Set the value of num1 equal to the
value of num2.
Operation:num1 = 5
num2 = 6 Pseudocode:
Step 1: Start
num1 = num2 Step 2: Assign 5 to num1.
Output: num1 = 6 Step 3: Assign 6 to num2.
Step 4: Set the value of num1 equal
num2 = 6 to the value of num2.
Step 5: End
Basic Elements of Pseudocode:

4. Read the input from user

- get the value of a variable from the user


Example #1:
Example #2:(STRING)
1. Operation: number(variable)
2. Operation: name(variable)
Enter a number: 5
Enter your name: JOSH
Output: number = 5
Output: name = “JOSH”
Pseudocode:
Step 1: Start Pseudocode:
Step 2: Print “Enter a number:”, number. Step 1: Start
Step 3: End Step 2: Print “Enter a your name:”, name.
Step 3: End
Basic Elements of Pseudocode:

5. Print the output to the user


- Print x (This will print value of variable x)
- Print “Your mileage is” x

Operation: name (variable)


Enter your name: JUNIOR
name= “JUNIOR” Pseudocode:
Output: HELLO JUNIOR Step 1: Start
Step 2: Print “Enter a your name:”, name
Step 3: Print “HELLO”, name.
Step 4: End
Basic Elements of Pseudocode:

*Carry out basic arithmetical computation


Example
- Add num1 and num2
- Subtract num2 from num1
Example:
Pseudocode for adding two numbers.

Step 1: Begin.
Step 2: Print “Enter first number:”, num1.
Step 3: Print “Enter second number:”, num2.
Step 4: Add num1 and num2 for the value of sum.
Step 5: Print “The sum is “, sum.
Step 6: Quit.

num1 = 10
Enter first number: 10
num2 = 5
Enter second number: 5
sum = num1 + num2
The sum is 15
sum= 15
EXAMPLE
S
BASIC nname = “Ella”
fnum = 10

ARITHMETIC snum = 5
difference = fnum - snum

PSEUDOCODE

- Step 1: Start
- Step 2: Print “Enter your nickname”,
nname.
- Step 3: Print “Enter first number:”,
fnum.
- Step 4: Print “Enter second number:”,
snum.
- Step 5: Subtract snum from fnum for
the value of difference.
- Step 6: Print “Good day,”, nname, “!”.
- Step 7: Print “The difference of”,
fnum, “and “, snum, “is “,
difference
DECISION fnum = 6
snum = 3

MAKING
PSEUDOCODE

- Step 1: Start
- Step 2: Print “Enter first number:”, fnum.
- Step 3: Print “Enter second number:”,
snum.
- Step 4: If fnum is greater than the value of
snum.
- Step 4.1: Print fnum, “ is greater than “,
snum.
- Step 5: Else, print snum, “ is greater than
“, fnum.
- Step 6: End
LOOPING
current_year = 2020
name = “Mariella”
birth_year = 1998
age = current_year - birth_year

PSEUDOCODE
- Step 1: Start
- Step 2: Read current_year=2020
- Step 3: Print “Enter your name:”, name
- Step 4: Print “Enter your birth year:”,
birth_year
- Step 5: The value of age is equal to
current_year minus
birth_year.
- Step 6: Print “Hi”, name, “! You are ”,
age, “ years old this year 2020.”
- Step 7: Print “Do you want to try again?
(Y or N)”, answer
- Step 8: Check if answer is equals to ‘Y’.
- Step 8.1: Then, go to Step 3.
- Step 9: Else, print “Thank you!”
Thank you and God
bless! ☺
___

You might also like