Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Introduction To Programming With RAPTOR

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Introduction to Programming with RAPTOR

[ Rapid Algorithmic Prototyping Tool for Ordered Reasoning ]

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.

We use RAPTOR for several reasons.


 The RAPTOR development environment minimizes the amount of syntax you must learn to write
correct program instructions.
 The RAPTOR development environment is visual. RAPTOR programs are diagrams (directed graphs)
that can be executed one symbol at a time. This will help you follow the flow of instruction execution in
RAPTOR programs.
 RAPTOR is designed for ease of use.
 RAPTOR error messages are designed to be more readily understandable by beginning programmers.

RAPTOR Program Structure


A RAPTOR program is a set of connected symbols that represent actions to be performed.
The arrows that connect the symbols determine the order in which the actions are performed.
When executing a RAPTOR program, you begin at the Start symbol and follow the arrows
to execute the program. A RAPTOR program stops executing when the End symbol is
reached. The smallest RAPTOR program (which does nothing) is depicted at the right. By
placing additional RAPTOR statements between the Start and End symbols you can create
meaningful RAPTOR programs.

Introduction to RAPTOR Statements/Symbols


RAPTOR has six (6) basic symbols, where each symbol represents a unique type of
instruction. The basic symbols are shown at the right. The top four statement types,
Assignment, Call, Input, and Output, are explained in this reading, The bottom
two types, Selection and Loops, will be explained in a future reading.

The typical computer program has three basic components:


 INPUT – get the data values that are needed to accomplish the task.
 PROCESSING – manipulate the data values to accomplish the task.
 OUTPUT – display (or save) the values which provide a solution to the task.
These three components have a direct correlation to RAPTOR instructions as shown in the following table.

Purpose Symbol
Start Name Description
input Allow the user to enter data. Each data value
INPUT statement is stored in a variable.
Start
Start

assignment Change the value of a variable using some


PROCESSING statement type of mathematical calculation.

procedure Execute a group of instructions defined in


call the named procedure. In some cases some of
PROCESSING
the procedure arguments (i.e., variables) will
be changed by the procedure's instructions.
output Display (or save to a file) the value of a
OUTPUT statement variable.
End
End
End
The common thread among these four instructions is that they all do something to variables! To understand how
to develop algorithms into working computer programs, you must understand the concept of a variable. Please
study the next section carefully!

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.

 The first assignment statement, X←32, assigns the data


32
value 32 to the variable X.
 The next assignment statement, X←X+1, retrieves the
current value of X, 32, adds 1 to it, and puts the result, 33
33, in the variable X.
 The next assignment statement, X←X*2, retrieves the
current value of X, 33, multiplies it by 2, and puts the 66
result, 66, in the variable X.
During the execution of the previous example program, the variable X stored three distinct values. Please note
that the order of statements in a program is very important. If you re-ordered these three assignment statements,
the values stored into X would be different.

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 ”

Common errors when using variables:


Error 1: "Variable ____ does not have a value"
There are two common reasons for this error:

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

Error 2: "Can't assign string to numeric variable _____"


"Can't assign numeric to string variable _____"
This error will occur if your statements attempt to change the data type of a variable.

Start

Miles ← 100

Miles ← "Distance to town"


End

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 + “: ”.

At run-time, an input statement will display an input dialog box, an


example of which is shown to the right. After a user enters a value
and hits the enter key (or clicks OK), the value entered by the user is
assigned to the input statement's variable.

Make sure you distinguish between the "definition of a statement"


and the "execution of a statement". The dialog box that is used to
define a statement is totally different from the dialog box that is used
at run-time when a program is executing.
Assignment Statement/Symbol

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.

An assignment statement is displayed inside its RAPTOR


symbol using the syntax:

Variable ← Expression

For example, the statement created by the dialog box to the


right is displayed as:
Start

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

You might also like