Presentation is loading. Please wait.

Presentation is loading. Please wait.

Subject: Information Technology Grade: 10

Similar presentations


Presentation on theme: "Subject: Information Technology Grade: 10"— Presentation transcript:

1 Subject: Information Technology Grade: 10
Topics: Selection Statements

2 Processing Involving Selecting Instructions
An instruction that allows deviation and selection to take place uses the ‘IF’ command. The IF statement contains a condition that is made up of three parts: Variable to be tested Relational operator Variable or constant to which the variable to be tested is compared to.

3 Relational Operators

4 If statements: IF-THEN IF-THEN-ELSE Flowchart Symbols:
Decision making and branching Connector or joining two parts of a program. It is also used to connect sections of a flowchart when a flowchart is long and cannot fit on a page. A letter or digit can be placed in the small circle to indicate the link on the first page. Another identically labeled connector is placed on the next page to indicate the continuation of flow.

5 IF-THEN Pseudocode IF (condition) then
When one option is available and a selection may or may not be made, the IF-THEN is used. Pseudocode IF (condition) then One or more instructions which will be carried out if the condition is true ENDIF

6 Flowchart no yes Condition Statement - True

7 Examples IF-THEN Problem 1:
If a student’s grade is greater than 85%, then she is given 3 merits. Solution: Pseudocode IF (grade > 85) then merit = 3 ENDIF Flowchart no yes grade > 85 merit = 3

8 Problem 2: Read the time. If the time is 11:00, output “Ring the bell”. Solution Pseudocode Read time IF (time = 11) then Print “Ring the bell” ENDIF Flowchart Students is required to do the flowchart

9 Problem 3: Write a program to read a number N. If N is greater than or equal to 100, add 10 to the number and display the result. Print the number. Requirements: Write the Pseudocode Draw the flowchart

10 Pseudocode Start Declare N, result as Integer
Print “A program that accepts a number, and if the number is greater than 100 then 10 is added to the number.” Print “Enter a number: ” Read N IF (N >= 100) then result = N + 10 Print “Result is ” result ENDIF Print “Number is ” N Stop

11 Print “Result is ”, result
Flowchart START STOP Print “Enter a number” Read N N >= 100 Print “Result is ”, result result = N + 10 Print “Number is ”, N No Yes

12 Problem Write a program that calculates the total price of a ruler and a pencil. If the total price is more than $150, a discount of 5% is given. Compute and print the discount amount. Input the prices for the ruler and pencil and display the total price and the amount payable.

13 Requirements List the operations Write the Pseudocode
Draw the Flowchart.

14 IF-THEN-ELSE When two options are available and a selection must be made, the IF-THEN-ELSE is used. Pseudocode IF (condition) then One or more instructions which will be carried out if the condition is true else One or more instructions which will be carried out if the condition is false ENDIF

15 Flowchart yes no Condition Statement - True Statement - False

16 Examples IF-THEN-ELSE
Problem 1: If sales is greater than $7000, commission is $500 otherwise commission is $250 Solution: Pseudocode IF (sales > 7000) then commission = 500 else commission = 250 ENDIF Flowchart yes no Sales > 7000 Commission = 500 Commission = 250

17 Examples IF-THEN-ELSE
Problem 2: Read the age of a person. If age is greater than 35, output “old person” otherwise output “young person” Solution: Pseudocode Read age IF (age > 35) then Print “Old person” else Print “Young person” ENDIF Flowchart Students is required to do the flowchart

18 Problem 3: Write a program that accepts employee’s salary. If the salary is less than or equal to $44000, then a bonus of 15% is given, otherwise 10% is given. Calculate and display the bonus amount given. Requirements: Write the Pseudocode Draw the Flowchart

19 Pseudocode Start Declare salary, bonus as Real
Print “A program that accepts the salary for an employee, and calculate the bonus given” Print “Enter salary” Read salary IF (salary <= 44000) then bonus = salary * 0.15 else bonus = salary * 0.10 ENDIF Print “Bonus amount is ” bonus Stop

20 Flowchart STOP START Print “Enter salary” Read salary Print
bonus = salary * 0.15 bonus = salary * 0.10 Yes No

21 Problem A credit union pays 4% interest on shares that are greater than $25000 and 3% on all other shares. No interest is paid on deposits. Write a program that prompts the user to input a share a deposit. The program should calculate and output the interest amount and the total savings (Total savings = shares + deposit + interest amount).

22 Requirements List the operations Write the Pseudocode Draw Flowchart

23 Home Work Cambridge – Information Technology for CSEC
Exercise 22 – Numbers 1 - 5

24 THE END


Download ppt "Subject: Information Technology Grade: 10"

Similar presentations


Ads by Google