Hi Hello Good Bye
Hi Hello Good Bye
Introduction to Programming
CC 103Computer Programming 1
LESSON
3 Program Structures
CC 103Computer Programming 1
LESSON
3 Program Control Structures
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Sequential
CC 103Computer Programming 1
LESSON
3 Program Control Structures
Examples: Sequential
Problem 1: sum computation Problem 2: average computation Problem 3: bonus computation
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Selection/Conditional
The execution of instructions by selection, wherein conditions for a series of
alternative statements are evaluated to specify which instruction is to be
executed. In this way, the flow of the program depends on the set of
conditions that are written.
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Selection/Conditional
In this way, the flow of the program depends on the set of conditions that are
written.
Algorithm : Flowchart :
Process A Condition
Process B
else
Yes /True
Process B
Process A
CC 103Computer Programming 1
LESSON
3 • Selection/Conditional
start
Problem 4:
Determine if the grade of a student is
"passed" or failed," considered 75 as
the passing grade. grade = 0
Algorithm :
Input grade
Input grade
if (grade >=75) then
print”passed”
F
else print “Failed”
grade >= 75 1
print “failed”
print “Passed”
1
end CC 103Computer Programming 1
LESSON
3 • Selection/Conditional
start
Let h=hours worked ; r=rate per hour; b=bonus;
s=salary
Problem 5: h=0;r=0;
Compute the bonus of an b=0;s=0;
employee. Consider the following
criteria: If the employee’s salary is
greater than or equal to 10000 Input h,r
pesos, the bonus is 50% of the
salary; else, the bonus is 25% of
s=h * r 1
the salary. Salary is hours worked
times rate per hour.
F
s >= 10000 b= s*.25 Output b end
b= s*.50
1
CC 103Computer Programming 1
LESSON
3 • Selection/Conditional
start
h=0;r=0;
b=0;s=0;
Problem 6:
Compute the bonus of an
Input h,r
employee. Consider the following
criteria: If the employee’s salary is
less than 10,000 pesos the bonus
s=h * r 1
is 25% of the salary; for employees
with salaries greater than to
10,000 pesos, the bonus is 50% of T
the salary ;and for salaries equal s < 10000 b= s*.25 Output b end
to 10,000 pesos, bonus is 35% of
salary. Salary is hours worked F
b= s*.35 1
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Repetition/ Iteration /Loop
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Repetition/ Iteration /Loop
The way the count-controlled loop works is simple: the loop
Count-controlled loop holds a count of the number of times it runs, and the loop
stops when the count reaches the specified count.
Initialization of
This loop normally performs the following three counter (control
actions: variable)
starts. Condition
END
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Repetition/ Iteration /Loop
CC 103Computer Programming 1
LESSON
3 • Repetition/ Iteration /Loop
Problem 7:
Create a flowchart that accepts number 5 times
Problem 8:
Create a flowchart that accepts numbers and stops when the user
enters 0.
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Modular/Procedural
The approach is sometimes called divide and conquer
because a large task is divided into several smaller tasks
that are easily performed.
Predefined Process
CC 103Computer Programming 1
LESSON
3 Program Control Structures
• Modular/Procedural
CC 103Computer Programming 1