Introduction To Programming With RAPTOR
Introduction To Programming With RAPTOR
Introduction To Programming With RAPTOR
What is RAPTOR?
RAPTOR is a visual programming development environment based on flowcharts. A flowchart is a collection
of connected graphic symbols, where each symbol represents a specific type of instruction to be executed. The
connections between symbols determine the order in which instructions are executed. These ideas will become
clearer as you use RAPTOR to solve problems.
Purpose Symbol
Start Name Description
input Allow the user to enter data. Each data value
INPUT statement is stored in a variable.
Start
Start
RAPTOR Variables
Variables are computer memory locations that hold a data value. At any given time a variable can only hold a
single value. However, the value of a variable can vary (change) as a program executes. That's why we call
them "variables"! As an example, study the following table that traces the value of a variable called X.
Description Value of Program
X
When the program begins, no variables exist. In
RAPTOR, variables are automatically created when
Undefined
they are first used in a statement.
A variable can have its value set (or changed) in one of three ways:
By the value entered from an input statement.
By the value calculated from an equation in an assignment statement.
By a return value from a procedure call (more on this later).
It is variables, and their changing data values, that enable a program to act differently every time it is executed.
All variables should be given meaningful and descriptive names by the programmer. Variable names should
relate to the purpose the variable serves in your program. A variable name must start with a letter and can
contain only letters, numerical digits, and underscores (but no spaces or other special characters). If a variable
name contains multiple "words," the name is more "readable" if each word is separated by an underscore
character. The table below shows some examples of good, poor, and illegal variable names.
Good variable names Poor variable names Illegal variable names
tax_rate a (not descriptive) 4sale (does not start with a letter)
sales_tax milesperhour (add underscores) sales tax (includes a space)
distance_in_miles my4to (not descriptive) sales$ (includes invalid character)
mpg
IMPORTANT: If you give each value in a program a meaningful, descriptive variable name, it will help you
think more clearly about the problem you are solving and it will help you find errors in your program.
One way of understanding the purpose of variables is to think of them as a means to communicate information
between one part of a program and another. By using the same variable name in different parts of your program
you are using the value that is stored at that location in different parts of your program. Think of the variable as
a place holder or storage area for values between each use in your program computations.
When a RAPTOR program begins execution, no variables exist. The first time RAPTOR encounters a new
variable name, it automatically creates a new memory location and associates this variable name with the new
memory. The variable will exist from that point in the program execution until the program terminates. When a
new variable is created, its initial value determines whether the variable will store numerical data or textual
data. This is called the variable's data type. A variable's data type cannot change during the execution of a
program. In summary, variables are automatically created by RAPTOR and can hold either:
Numbers e.g., 12, 567, -4, 3.1415, 0.000371, or
Strings e.g., “Hello, how are you?”, “James Bond”, “The value of x is ”
1) The variable has not been given a value. 2) The variable name was misspelled.
Start
Start
Miles ← 100
X←Y
Distance ← Mile * 5
End
End
Start
Miles ← 100
RAPTOR Statements/Symbols
The following four sections provide details about each of the four basic statements: Input, Assignment,
Call, and Output.
Input Statement/Symbol
An input statement/symbol allows the user of a program to enter a data value into a program variable during
program execution. It is important that a user know exactly what type of value is expected for input. Therefore,
when you define an input statement you specify a string of text that
will be the prompt that describes the required input. The prompt
should be as explicit as possible. If the expected value needs to be in
particular units (e.g., feet, meters, or miles) you should mention the
units in the prompt.
When you define an input statement, you must specify two things: a
prompt and the variable that will be assigned the value enter by the
user at run-time. As you can see by the “Enter Input” dialog box at the
right there are two types of input prompts: Text and Expression
prompts. An Expression prompt enables you to mix text and
variables together like the following prompt: “Enter a number
between ” + low + “ and ” + high + “: ”.
The assignment symbol is used to perform a computation and then store the results in a variable. The definition
of an assignment statement is performed using the dialog box shown on the right. The variable to be assigned a
value is entering into the "Set" field, and the computation to
perform is enter into the "to" field. The example on the right
sets the value of the variable x to 0.707106781186547.
Variable ← Expression
x ← sin(pi / 4)
End
One assignment statement can only change the value of a single
variable, that is, the variable on the left hand side of the arrow.
If this variable did not exist prior to the statement, a new
variable is created. If this variable did exist prior to the
statement, then its previous value is lost and its new value is
based on the computation that is performed. No variables on the
right hand side of the arrow (i.e., the expression) are ever
changed by the assignment statement.
Expressions
The expression (or computation) of an assignment statement
can be any simple or complex equation that computes a single
value. An expression is a combination of values (either
constants or variables) and operators. Please carefully study the following rules for constructing valid
expressions.
EXAMPLE 1
EXAMPLE 2