Student Copy2.0reviewer

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 131

START

PREPARE THE EGG


AND INGREDIENTS

HEAT THE PAN WITH OIL

SCRAMBLE THE EGG

PUT THE EGG ON THE PAN


AND WAIT TO COOK
END
“algorithm” relates to the name of the mathematician Al-
khowarizmi, which means a procedure or a technique.
INTRODUCTION CHARACTERISTICS TYPES OF CONTROL
STRUCTURE

SEQUENCE BRANCHING LOOPING


Software Engineer commonly uses an algorithm for
planning and solving the problems.
An algorithm is a sequence of steps to solve a particular
problem or algorithm is an ordered set of unambiguous
steps that produces a result and terminates in a finite time
• Input: An algorithm may or may not require
input
• Output: Each algorithm is expected to produce
at least one result
• Definiteness: Each instruction must be clear
and unambiguous.
• Finiteness: If the instructions of an algorithm
are executed, the algorithm should terminate
after finite number of steps
a. It receives an input.
b. It works on a set of inputs.
c. The steps must be precisely defined.
d. The result of each step should depend on
the results of previous steps.
e. It stops after a finite number of
instructions.
f. It produces the desired output.
What are the advantages of Algorithm?
• It is not dependent
• It is a step-wise • Every step in an
representation of
on any programming • An algorithm
language, so it is uses a definite algorithm has its
a solution to a easy to understand
procedure. own logical
given problem, for anyone even
which makes it sequence so it is
without
easy to programming easy to debug.
understand. knowledge.

What are the advantages of an Algorithm?


What are the DISadvantages of an Algorithm?
•To polish your shoes.

•Write the Algorithm


to solve the problem
•(in 6 STEPS)
• To go for a class picnic

•Write the Algorithm


to solve the problem
•(in 6 STEPS)
• To make tea/coffee

•Write the Algorithm


to solve the problem
•(in 6 STEPS)
• To celebrate New Year

•Write the Algorithm


to solve the problem
•(in 6 STEPS)
WHY IS ALGORITHM IMPORTANT IN
OUR DAILY LIFE?
WHAT ABOUT IN PROGRAMMING?
‘+’ for Addition
‘-’ for Subtraction
‘*’ for Multiplication
‘/’ for Division and
‘ ’ for assignment. For example A X*3
means A will have a value
of X*3.
SEQUENCE BRANCHING LOOPING

sequence of refers to a binary decision allows a statement or a


statements place based on some condition. If sequence of
one after the other – the condition is true, one of
statements to be
the one above or the two branches is
before another gets explored; if the condition is repeatedly executed
executed first. false, the other alternative is based on some loop
taken. condition
-rectangular process -diamond-shaped -represented by ‘while’
box decision box and ‘for’ constructs
SEQUENCE

sequence of
statements place
one after the other –
the one above or
before another gets
executed first.
-rectangular process
box
NUM1 AND NUM2
ARE A & B.
To play music stored in a CD.
BRANCHING

refers to a binary decision


based on some condition. If
the condition is true, one of
the two branches is
explored; if the condition is
false, the other alternative is
taken.
-diamond-shaped
decision box
• You can use these conditions to perform
different actions for different decisions
CONDITIONAL
STATEMENTS

ELSE ELSE IF
IF

https://www.w3schools.com/cpp/cpp_conditions.asp
Note that if is in lowercase letters. Uppercase letters
(If or IF) will generate an error.
Use the else statement to specify a block of code to be executed
if the condition is false.
Use the else if statement to specify a new condition if the
first condition is false.
Use the else if statement to specify a new condition if the
first condition is false.
LOOPING

allows a statement or a
sequence of
statements to be
repeatedly executed
based on some loop
condition
-represented by ‘while’
and ‘for’ constructs
When you know exactly
how many times you
want to loop through a
block of code,
use the for loop instead of
a while loop:
When you know exactly how many times you want to loop through a block of code,
use the for loop instead of a while loop:
The while
loop loops
through a
block of code
as long as a
specified
condition is
true:
The while loop loops through a block of code as long as a specified
condition is true:
In the example below, the code in the loop will run,
over and over again, as long as a variable (i) is less than 5:
The do/while loop is
a variant of the while
loop.
This loop will execute
the code block once,
before checking if the
condition is true,
then it will repeat the
loop as long as the
condition is true.
The do/while loop is a variant of the while loop.
This loop will execute the code block once, before checking if the condition is true,
then it will repeat the loop as long as the condition is true.
The example below uses a do/while loop. The loop will always be executed at least once,
even if the condition is false, because the code block is executed before the condition is tested:

Do not forget to increase the


variable used in the condition,
otherwise the loop will never end!
Conclusion 01 Conclusion 02 Conclusion 03
is the graphical representation of a program
FLOWCHART FLOWCHART REAL-LIFE SCENARIOS
SYMBOLS

EXERCISES DO IT! Conclusion


What are the rules
for flowcharting?
a. A flowchart should have only one
Start and one Stop symbol.
b. The general direction of flow in a
Following are flowchart is from top to bottom or
from left to right.
the rules for c. Arrowheads are used to indicate
flowcharting: the flow of information or sequence
of steps.
What are the rules
for flowcharting?
d. The arrow lines should not
cross each other.
e. Off-page and on-page
The following are connectors should be used when
the rules for joining parts of a flowchart
flowcharting: spanning multiple pages/same
page.
What are the Advantages
and DISadvantages
of Flowchart?
• Flowchart is an excellent way of
communicating the logic of a program.
Advantages • Easy and efficient to analyze problem
using flowchart.
of • During program development cycle, the
Flowchart? flowchart plays the role of a blueprint,
which makes program development
process easier.
• After successful development of a
program, it needs continuous timely
Advantages maintenance
during the course of its operation. The
of flowchart makes program or system
Flowchart? maintenance easier.
• It is easy to convert the flowchart into
any programming language code
• The flowchart can be complex when
the logic of a program is quite
DISadvantages complicated.
of Flowchart? • Drawing flowchart is a time-
consuming task.
• It is just a visualization of a program,
it cannot function like an actual
program
THE GIVEN
EXAMPLES ARE REAL
LIFE SCENARIOS
USE THE FLOWCHART
SYMBOLS IN
COMPLETING THE TASK

DO THE FLOWCHART
WITH YOUR PAIR
THE GIVEN
EXAMPLES ARE REAL
LIFE SCENARIOS
USE THE FLOWCHART If you are watching a news channel on
SYMBOLS IN your TV and you want to change it to a
COMPLETING THE TASK
sports channel, you need to do
DO THE FLOWCHART
WITH YOUR PAIR
something i.e. move to that channel by
pressing that channel number on your
remote. This is a kind of problem
solving.
START/END
START

READ A,B INPUT/OUTPUT SYMBOL

SUM = A+B PROCESS

PRINT SUM END


Now, broadly we can say that
FLOWCHART is essential in solving a
problem because______________...

CONTINUE CONTINUE
THE THE
STATEMENT… STATEMENT…
FLOWCHART

To play music To find the cost


Buying stationary
of 24 pens when
from the market. stored in a
the cost of one
CD. pen is P12.
Buying stationary from the market.
To play music stored in a CD.
To find the cost of 24 pens
when the cost of
one pen is P12.
• A symbol or name that stands for a value.
•A variable is a value that can change.
VARIABLE TYPES OF DECLARING A
VARIABLES VARIABLE

SYNTAX EXERCISES Conclusion


Local variable

Global variable
• Variables are containers for storing data values.
Where type is one of C++ types (such as int), and
variableName is the name of the variable (such as x
or myName).

The equal sign is used to assign values to the


variable. () “assignment operator”
or
• The opposite of a variable is a constant.
•A constant is a value that never changes.
-is classification of a particular type of
information.
https://www.w3schools.com
/cpp/cpp_operators.asp
Remainder
DO YOUR PRACTICE!
#include <iostream>
using namespace std;

int main() {
cout << “START YOUR
PROGRAMMING JOURNEY!";
return 0;
}
https://www.w3schools.com/cpp/cpp_syntax.asp
https://www.w3schools.com/

You might also like