0% found this document useful (0 votes)
80 views20 pages

Lecture 3 - Raptor Selections

The document discusses algorithms and the Raptor programming environment. It introduces how to design algorithms, use Raptor, and solve problems using selection and nested selection. Key aspects covered include describing algorithms, drawing flowcharts, the Raptor interface and symbols, variables, selection statements, and exercises to practice using these concepts.

Uploaded by

Wessal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views20 pages

Lecture 3 - Raptor Selections

The document discusses algorithms and the Raptor programming environment. It introduces how to design algorithms, use Raptor, and solve problems using selection and nested selection. Key aspects covered include describing algorithms, drawing flowcharts, the Raptor interface and symbols, variables, selection statements, and exercises to practice using these concepts.

Uploaded by

Wessal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

ALGORITHMS & RAPTOR

Pr. Hamza El Hafdaoui


E-mail: [email protected]
LAB 3:
ALGORITHMS
INTRODUCTION TO RAPTOR

In today’s class we will learn:

• How to design Algorithms for different problems.


• How to use Raptor.
• How to solve problems with selection.
• How to solve problems with nested selection.
ALGORITHMS
HOW CAN WE DESCRIBE AN
ALGORITHM?
 An algorithm can be described using:
 Natural language: written lines describing the algorithms’ steps
for solving a problem.
 Pseudo-code: is a detailed yet readable description of what a
computer program or algorithm must do, expressed in a formally-
styled natural language.
 Flowchart: visual representation of the algorithm using standard
symbols to represent the different types of instructions. These
symbols are used to construct the flowchart and show the step-by-
step solution to the problem.
HOW DO WE DRAW A FLOWCHART?
 When having a computational problem to solve, you should first write the
algorithm in pseudo-code.
 Flowchart can be drawn using standard symbols…

http://www.bbc.co.uk/education/guides/z3bq7ty/revision/3
INTRODUCTION TO RAPTOR
WHAT’S RAPTOR?

 RAPTOR is a flowchart-based programming environment.


 RAPTOR programs are created visually and executed visually
by tracing the execution through the flowchart.
 It allows you to detect errors in your algorithm before coding…
INTERFACE

It is downloadable from: http://raptor.martincarlisle.com/


LAYOUT

Run the program

Pause

Stop

Speed of running

Generate source code


PROGRAM STRUCTURE
 A RAPTOR program starts at (Start) and will
stop executing when the End symbol is
reached.

RAPTOR STATEMENTS/SYMBOLS

 The top four statement types:


 Assignment, Call, Input, and Output
 The bottom two types:
 Selection and Loops
VARIABLES IN RAPTOR
 When you create a variable, it should have a value. Either a
string or a number.
 A variable is automatically created when it is first used in the
flowchart.
 Example:
COMMON ERRORS WITH VARIABLES

Start
Start

Miles ← 100
X←Y

Distance ← Mile * 5

End
End

Start

Miles ← 100

Miles ← "Distance to town"

End
OTHER SYMBOLS
ASSIGNMENT OUTPUT
INPUT STATEMENT STATEMENT STATEMENT
/SYMBOL /SYMBOL /SYMBOL
EXERCISE 1
 Prompt the user for two numbers. Use variables called N1 and N2.
Output the multiplication of these two numbers.
 Constraint: you should have only two variable in your flowchart:
N1 and N2!

EXERCISE 2
 Write an algorithm that takes from the user two numbers, N1 and
N2, swaps the values of these two variables, and outputs them to
the user.
 Example: N1=2, N2=10

Outpout: N1=10, N2=2


SELECTION…
SELECTION

Statement 1

Decision

Statement 2a Statement 2b

Statement 3
RELATIONAL AND LOGICAL
OPERATORS
Operation Description Example
= "is equal to" 3 = 4 is No(false)
!= "is not equal to" 3 != 4 is Yes(true)
/= 3 /= 4 is Yes(true)
< "is less than" 3 < 4 is Yes(true)
<= "is less than or equal to" 3 <= 4 is Yes(true)
> "is greater than" 3 > 4 is No(false)
>= "is greater than or equal to" 3 >= 4 is No(false)
and Yes(true) if both are Yes (3 < 4) and (10 < 20)
is Yes(true)
or Yes(true) if either are Yes (3 < 4) or (10 > 20)
is Yes(true)
xor Yes(true) if the "yes/no" values Yes xor No
are not equal is Yes(true)
not Invert the logic of the value not (3 < 4)
Yes if No; No if Yes is No(false)

http://www.bbc.co.uk/education/guides/z3bq7ty/revision/3
NESTED SELECTION…
EXERCISE 1
 Write an algorithm that takes the GPA of a student and displays whether
this student will be in the President or Dean lists or didn’t make it any of
them.
 Recall:

 GPA = 4  Student is in the President’s List.

 3<=GPA<4  Student is in the Dean’s List.

 GPA < 3  Student didn’t make it to any list.

EXERCISE 2
 Write an algorithm that takes the GPA of a student and give the letter
grade.

94 – 100  A 77 – 79  C+ 60 – 62  D-
90 – 93  A- 73 – 76  C < 60  F
87 – 89 B+ 70 – 72  C-
83 – 86 B 67 – 69  D+
80 – 82  B- 63 – 66  D
EXERCISE 3
Write an algorithm, using flowcharts, that does the following:
o It will ask the user to choose for which shape they want to compute the
area:
-If the user chooses the circle, it will ask the user for radius
The area of circle is: PI*radius²
- If the user chooses the rectangle, it will ask the user for the height and the
length of the rectangle
The area of the rectangle is: height*length
- If the user chooses the triangle, It will ask the user for the base and height
The area of the circle is: 0.5*height*base
o Your program should print the appropriate area with accompanying text.

You might also like