The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by inaazlin, 2018-12-12 21:03:04

2.1 Design a Solution - Sequence

Design a Solution - Sequence

Keywords: Design a Solution - Sequence

2.1 Design a Solution

c) Explain each control structure and their
respective purposes.
d) Apply appropriate control structure.

Control Structure
• Sequence
• Selection
• Looping

What is a control structure?

1. Control structures control the flow of a program’s logic.
2. Consist of three structures:

i. Sequence structure
ii. Selection structure
iii. Looping structure

What is a control structure?

• Sequence Control Structure

• Performs actions one after another in sequence

• Selection Control Structure

• Performs action(s) based on a certain condition

• Repetition Control Structure

• performs one or more actions repeatedly while a certain
condition is true.

SEQUENCE STRUCTURE

• A sequence control structure performs actions one
after another in sequence

• All actions will be executed, none will be skipped
• Actions can be input, process, or output.

Example of Problem 1

•Find the sum and average of three
numbers input by user.

•Problem Analysis

•Input : num1, num2, num3
•Process : Calculate sum and average of

three numbers
•Output : sum, average

Example of Problem 1

Pseudocode
start

READ num1, num2, num3
sum = num1+num2+num3
average(num1+num2+num3)/3
PRINT sum, average
end

Example of Problem 1

• Flowchart start

READ num1, num2, num3

sum = num1+num2+num3
average = (num1+num2+num3)/3

PRINT sum, average

end

Example of Problem 2

Calculate and display the addition,
subtraction, multiplication and
division of two numbers.

Example Problem 2

• Write an IPO analysis for a program that
calculate and display the addition,
subtraction, multiplication and division of two
numbers.

Input number1, number2
Process
Output Calculate the addition, subtraction,
multiplication and division of two
numbers.

addition, subtraction, multiplication
and division

Example of Problem 2

Pseudocode

START
READ number1, number2
addition = number1 + number2
subtraction = number1 – number2
multiplication = number1 x number2
division = number1 / number2
PRINT addition, subtraction, multiplication,
division

STOP

Example of Problem 2

Flowchart START

READ number1, number2

addition = number1 + number2
subtraction = number1 – number 2
multiplication = number1 * number2

division = number1 / number2

PRINT addition, subtraction,
multiplication, division

STOP

Example of Problem 3

Calculate the total and average
of five subjects.

Example Problem 3

• Write an IPO analysis for a program that
calculate the total and average of five Marks.

Input mark1, mark2, mark3, mark4,
Process mark5
Output
Calculate the total and average
of five marks.

Total,average

Example of Problem 3

Pseudocode

START
READ mark1, mark2, mark3, mark4,
mark5
total = mark1 + mark2 + mark3 +
mark4 + mark5
average = total / 5
PRINT total , average

STOP

Example of Problem 3

Flowchart START

READ mark1,mark2, mark3,
mark4, mark5

total = mark1+mark2+mark3+mark4+mark5
average = total / 5

PRINT total , average

STOP

Example of Problem 4

Calculate the diameter,
circumference and area of a

circle.

Example Problem 4

• Write an IPO analysis for a program that
calculate the diameter, circumference and
area of a circle.

Input radius
Process
Output Calculate the diameter,
circumference and area of a
circle.
diameter, circumference and
area

Example of Problem 4

Pseudocode

START
READ radius
diameter = 2 x radius
circumference = 2 x 3.142 x radius
area = 3.142 x radius x radius
PRINT diameter, circumference, area

STOP

Example of Problem 4

Flowchart START

READ radius

diameter = 2 * radius
circumference = 2 * 3.142 * radius

area = 3.142 * radius * radius

PRINT diameter, circumference,
area

STOP

Example of Problem 5

Calculate the quotient and
remainder of a division.

Example Problem 5

• Write an IPO analysis for a program that
calculate the quotient and remainder of a
division.

Input number1, number2
Process
Output Calculate the quotient and
remainder of a division.

quotient, remainder

Example of Problem 5

Pseudocode

START
READ number1, number2
quotient = number1 / number2
remainder = number1 % number2
PRINT quotient, remainder

STOP

Example of Problem 5

Flowchart START

READ number1, number2

quotient = number1 / number2
remainder = number1 % number2

PRINT quotient, remainder

STOP

Example of Problem 6

• Calculate the discount and sale price of a book
after given 15% discount.

• Problem Analysis

• Input : original price

• Process : Calculate discount and sale price of

books

• Output : discount, sale price

• Pseudocode
start

Input original price
discount = 0.15 x original price
sale price = original price – discount
Output discount, sale price
end

• Flowchart start
Input original price
discount = 15% x original price
sale price = original price - discount

Print discount, sale price

end

Write a pseudocode & flowchart

1. Calculate the volume of cuboid.
2. Calculate the product of three numbers.
3. Calculate an average mark of 3 students.
4. Calculate a price of smartphone if 20% discount

is given to customer.
5. Calculate total and average of two numbers.


Click to View FlipBook Version