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 testedRelational operatorVariable or constant to which the variable to be tested is compared to.
4 If statements: IF-THEN IF-THEN-ELSE Flowchart Symbols: Decision making and branchingConnector 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.PseudocodeIF (condition) thenOne or more instructions which will be carried out if the condition is trueENDIF
7 Examples IF-THEN Problem 1: If a student’s grade is greater than 85%, then she is given 3 merits.Solution:PseudocodeIF (grade > 85) thenmerit = 3ENDIFFlowchartnoyesgrade > 85merit = 3
8 Problem 2:Read the time. If the time is 11:00, output “Ring the bell”.SolutionPseudocodeRead timeIF (time = 11) thenPrint “Ring the bell”ENDIFFlowchartStudents 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 PseudocodeDraw 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 NIF (N >= 100) thenresult = N + 10Print “Result is ” resultENDIFPrint “Number is ” NStop
11 Print “Result is ”, result FlowchartSTARTSTOPPrint “Enter a number”Read NN >= 100Print “Result is ”, resultresult = N + 10Print “Number is ”, NNoYes
12 ProblemWrite 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-ELSEWhen two options are available and a selection must be made, the IF-THEN-ELSE is used.PseudocodeIF (condition) thenOne or more instructions which will be carried out if the condition is trueelseOne or more instructions which will be carried out if the condition is falseENDIF
16 Examples IF-THEN-ELSE Problem 1:If sales is greater than $7000, commission is $500 otherwise commission is $250Solution:PseudocodeIF (sales > 7000) thencommission = 500elsecommission = 250ENDIFFlowchartyes noSales > 7000Commission = 500Commission = 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:PseudocodeRead ageIF (age > 35) thenPrint “Old person”elsePrint “Young person”ENDIFFlowchartStudents 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 PseudocodeDraw 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 salaryIF (salary <= 44000) thenbonus = salary * 0.15elsebonus = salary * 0.10ENDIFPrint “Bonus amount is ” bonusStop
21 ProblemA 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 RequirementsList the operationsWrite the PseudocodeDraw Flowchart
23 Home Work Cambridge – Information Technology for CSEC Exercise 22 – Numbers 1 - 5