Académique Documents
Professionnel Documents
Culture Documents
Lesson 5: RAPTOR
-Sequence
-Selection
-Loop
Lesson 1: COMPUTER COMPONENTS AND OPERATIONS
INTRODUCTION
Hardware is the machine itself and its connected devices such as monitor,
keyboard, mouse etc. all of which are physical objects that can be touched.
These devices are used to enter information and instructions into a computer
for storage or processing and to deliver the processed data to a user. Input/Output
devices are required for users to communicate with the computer. In simple terms, input
devices bring information INTO the computer and output devices bring information OUT
of a computer system. These input/output devices are also known as peripherals since
they surround the CPU and memory of a computer system.
b) Output Devices: Output device receives information from the CPU and
presents it to the user in the desired from. The output is usually produced in
one of the two ways – on the display device, or on paper (hard copy).
Computer’s memory can be classified into two types; primary memory and secondary
memory.
RAM or Random Access Memory is the unit in a computer system. It is the place in a
computer where the operating system, application programs and the data in current use
are kept temporarily so that they can be accessed by the computer’s processor. It is said
to be ‘volatile’ since its contents are accessible only as long as the computer is on. The
contents of RAM are no more available once the computer is turned off.
ROM or Read Only Memory is a special type of memory which can only be read
and contents of which are not lost even when the computer is switched off. It typically
contains manufacturer’s instructions. Among other things, ROM also stores an initial
program called the ‘bootstrap loader’ whose function is to start the operation of computer
system once the power is turned on. Example of ROM is EEPROM, which is a
programmable ROM used for the computer BIOS, as shown in the picture below. Note.
Unlike RAM (random access memory), ROM is non-volatile, which means it keeps its
contents regardless of whether or not it has power.
b. Secondary Memory
Examples include DRAM, SDRAM, DIMM, SO-DIMM and VRAM, as well as terms such
as DDR3 and GDDR5. DRAM and SDRAM are simply more specific terms for
the RAM that you'll find in a modern computer (technically, SDRAM-Synchronous
Dynamic Random-Access Memory, is more accurate).
Hard Disk
Hard disks are made up of rigid material and are usually a stack of metal disks sealed in
a box. The hard disk and the hard disk drive exist together as a unit and is a permanent
part of the computer where data and programs are saved. These disks have storage
capacities ranging from 1GB to 1 TB and more. Hard disks are rewritable.
Compact Disk Compact Disk (CD) is portable disk having data storage
capacity between 650-700 MB. It can hold large amount of information such as
music, full-motion videos, and text etc. CDs can be either read only or read write
type.
Digital Video Disk Digital Video Disk (DVD) is similar to a CD but has larger
storage capacity and enormous clarity. Depending upon the disk type it can
store several Gigabytes of data. DVDs are primarily used to store music or
movies and can be played back on your television or the computer too. These
are not rewritable.
Software is the set of programs that make use of hardware for performing
various functions.
CHARACTERISTICS OF COMPUTERS
A computer performs five major operations or functions irrespective of its size and
make. These are
Functional Units:
a. Input Unit: This unit is used for entering data and programs into the computer system
by the user for processing.
b. Storage Unit: The storage unit is used for storing data and instructions before and
after processing.
c. Output Unit: The output unit is used for storing the result as output produced by the
computer after processing.
d. Processing: The task of performing operations like arithmetic and logical operations
is called processing. The Central Processing Unit (CPU) takes data and instructions
from the storage unit and makes all sorts of calculations based on the instructions given
and the type of data provided. It is then sent back to the storage unit. CPU includes
Arithmetic logic unit (ALU) and control unit (CU)
Registers: Stores the data that is to be executed next, "very fast storage area".
Lesson 2: PROGRAMING PROCESS
The programmer’s job can be broken down into six programming steps:
Programmer plans the steps to the program, deciding what steps to include and
how to order them (e.g. planning tour, planning party, etc.)
Flowcharts
Pseudocode
Objective
o Each computer knows only one language, Machine Language.
o High-level Languages must be translated into Machine Language
Need of compiler or interpreter
o Compiler catches every syntax error.
o When writing a program, a programmer might need to recompile the code
several times
o An executable program is created only when the code is free of syntax
error
Test
o Executing the program with some sample data
o Seeing whether or not the results are logically correct.
o Being tested with many sets of data carefully.
Once the program is tested adequately, it is ready for the organization to use.
Putting the program into production might mean simply running the program once
if it was written to satisfy a user’s request for a special list.
Lesson 3: FLOWCHART AND SYMBOLS
INTRODUCTION
ADVANTAGES OF FLOWCHART:
Input/Output
o Generalized Input/Output Block; reading data from an
input medium or writing data to an output medium. This
block should be used in situation were data is being
sent in and out of the processor via some sort of I/O
peripheral.
Process
o Any process step; an operation or group of operations
that cause a change in value, form or location of the
data. This can consist of arithmetic or logical operators
or even move commands.
Flow line
o Sequence of operations and direction of data flow;
arrowheads are required if linkage is not left-to-right or
top-to-bottom. Generally arrowheads are included to
avoid confusion.
Annotation
o Additional explanation or comments. This block is
used for providing additional information to any other
block in the flowchart.
Decision
o Decision-making or switching type of operation, usually
based on a comparison that determines which of a number of
paths should be followed.
Predefined Process
o One or more operation defined in more detail elsewhere,
such as in a booklet or on a different flowchart, but not on
another part of the flowchart in which this symbol appears.
Terminal
o Terminal points in a flowchart – stop, start or break in the line
of flow.
Connectors
o Entry to or exit from another part of the flowchart; if to or from
step is on another page then the page reference should also be
stated.
Other Flowcharting Symbols
GENERAL RULES FOR FLOWCHARTING
1. All boxes of the flowchart are connected with Arrows. (Not lines)
2. Flowchart symbols have an entry point on the top of the symbol with no other entry
points. The exit point for all flowchart symbols is on the bottom except for the Decision
symbol.
3. The Decision symbol has two exit points; these can be on the sides or the bottom and
one side.
4. Generally a flowchart will flow from top to bottom. However, an upward flow can be
shown as long as it does not exceed 3 symbols.
6. Subroutines and Interrupt programs have their own and independent flowcharts.
7. All flow charts start with a Terminal or Predefined Process (for interrupt programs or
subroutines) symbol.
Flowcharting uses symbols that have been in use for a number of years to represent the
type of operations and/or processes being performed. The standardized format provides
a common method for people to visualize problems together in the same manner. The
use of standardized symbols makes the flow charts easier to interpret; however,
standardizing symbols is not as important as the sequence of activities that make up the
process.
Sequence
If-then-else (Selection)
While (Repetition)
SEQUENCE
If-THEN-ELSE (Selection)
WHILE (Repetition)
VARIABLES
Types of Variables
There are two types of variable:
o Local variables are those that are
in scope within a specific part of the
program (function, procedure,
method, or subroutine, depending
on the programming language
employed).
o Global variables are those that are
in scope for the duration of the
programs execution. They can be
accessed by any part of the
program, and are read-write for all
statements that access them.
Variable - Reason
CONSTANT
INTRODUCTION
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.
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 Name Description
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.
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:
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.
basic math: +, -, *, /, ^, **, rem, mod, sqrt, log, abs, ceiling, floor
The following table briefly describes these built-in operators and functions. Full details
concerning these operators and functions can be found in the RAPTOR help screens.
+ addition 3+4 is 7
- subtraction 3-4 is -1
- negation -3 is a negative 3
* multiplication 3*4 is 12
Output Statement/Symbol
You can display multiple values with a single output statement by using the "Output
Expression" option and building a string of text using the string plus (+) operator. When
you build a single string from two or more values, you must distinguish the text from the
values to be calculated by enclosing any text in quote marks ("). In such cases, the
quote marks are not displayed in the output window. For example, the expression,
Notice that the quote marks are not displayed on the output device. The quote marks are
used to surround any text that is not part of an expression to be evaluated.
Your instructor (or a homework assignment) will often say “Display the results in a user-
friendly manner”. This means you should display some explanatory text explaining any
numbers that are output to the MasterConsole window. An example of "non-user-friendly
output" and "user-friendly output" is shown below.
Comments in RAPTOR
To add a comment to a statement, right-click your mouse over the statement symbol and
select the "Comment" line before releasing the mouse button. Then enter the comment
text into the "Enter Comment" dialog box, an example of which is shown to the right. The
resulting comment can be moved in the RAPTOR window by dragging it, but you
typically do not need to move the default location of a comment.
Programmer header – documents who wrote the program, when it was written,
and a general description of what the program does. (Add to the "Start" symbol)
Section description – mark major sections of your program to make it easier for a
programmer to understand the overall program structure.
Logic description – explain non-standard logic.
Sequential Control
Notice that you, as a programmer, have total control over which statements are
executed before others, merely by your placement of those instructions relative to each
other in the instruction sequence. It is your job as a programmer to determine the
statement that is needed and its placement. Writing the correct statement is one task.
Determining where to place that statement is equally important. As an example, when
you want to get and process data from the user you have to GET the data before you
can use it. Switching the order of these statements means that your program is trying to
use data that it hasn’t gotten yet.
Selection Control
There need not be a statement 2a or a statement 2b. Either path could be empty or
could contain several statements. It would be silly for both of them to be empty (or both
have the exact same statements), as your decision, Yes or No, would have no effect
(nothing different would happen based on the decision).
The exit condition may never be true. We’ll have some examples of Statement 2b
that later. You have to have some code, in statement 2a or statement
2b, that makes a change that turns the exit condition to true, without
that, if it starts out being false, it will remain false forever.As with the
generic selection example, any of the statements in the example could
Statement 3
be replaced by several statements.
Some loops are called infinite loops because the exit condition could never be
true. The three examples below are slight variations of the counter-controlled
loop example. Each of them has a problem which will cause the loop to be
infinite. See if you can spot the error in each piece of code below.
Typically one or more variables are used to control whether the iteration construct exits
or loops again. The acronym I.T.E.M (Initialize, Test, Execute, and Modify) can be used
to check whether the loop and loop control variable(s) are being used correctly. See if
you can spot what is wrong (I.T.E. or M.) with each of the code fragments below.