Vous êtes sur la page 1sur 29

CONTENTS:

Lesson 1: COMPUTER COMPONENTS AND OPERATIONS

Lesson 2: PROGRAMING PROCESS

Lesson 3: FLOWCHART AND SYMBOLS

Lesson 4: NAMING VARIABLES AND CONSTANT

Lesson 5: RAPTOR

-Parts of Raptor app

-Sequence

-Selection

-Loop
Lesson 1: COMPUTER COMPONENTS AND OPERATIONS

INTRODUCTION

A computer is a programmable machine designed to perform arithmetic and


logical operations automatically and sequentially on the input given by the user and
gives the desired output after processing. Computer components are divided into two
major categories namely hardware and software.

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.

Input / Output Devices

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.

a) Input Devices- An input device is any device that provides input to a


computer.
 Keyboard: The keyboard is very much like a standard typewriter keyboard
with a few additional keys. The basic QWERTY layout of characters is
maintained to make it easy to use the system. The additional keys are
included to perform certain special functions. These are known as function
keys that vary in number from keyboard to keyboard.
 Mouse: A device that controls the movement of the cursor or pointer on
a display screen.
 Trackball: A trackball is an input device used to enter motion data into
computers or other electronic devices. It serves the same purpose as a
mouse, but is designed with a moveable ball on the top, which can be
rolled in any direction.
 Touchpad: A touch pad is a device for pointing (controlling input
positioning) on a computer display screen. It is an alternative to the
mouse. Originally incorporated in laptop computers, touch pads are also
being made for use with desktop computers. A touch pad works by sensing
the user’s finger movement and downward pressure.
 Touch Screen: It allows the user to operate/make selections by simply
touching the display screen.
 Light Pen: Light pen is an input device that utilizes a light-sensitive
detector to select objects on a display screen.
 Magnetic ink character recognition (MICR): MICR can identify character
printed with a special ink that contains particles of magnetic material.
This device particularly finds applications in banking industry.
 Optical mark recognition (OMR): Optical mark recognition, also called mark
sense reader is a technology where an OMR device senses the presence or
absence of a mark, such as pencil mark. OMR is widely used in tests such
as aptitude test.
 Bar code reader: Bar-code readers are photoelectric scanners that read the
bar codes or vertical zebra strips marks, printed on product containers.
These devices are generally used in super markets, bookshops etc.
 Scanner: Scanner is an input device that can read text or illustration
printed on paper and translates the information into a form that the
computer can use. A scanner works by digitizing an image.

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).

 Monitor: is often used synonymously with “computer screen” or “display.”


Monitor is an output device that resembles the television screen. It may use a
Cathode Ray Tube (CRT) to display information. The monitor is associated
with a keyboard for manual input of characters and displays the information
as it is keyed in. It also displays the program or application output. Like
the television, monitors are also available in different sizes.
 Printer: Printers are used to produce paper (commonly known as
hardcopy) output. Based on the technology used, they can be classified as
Impact or Non-impact printers.
 Impact printers use the typewriting printing mechanism wherein a
hammer strikes the paper through a ribbon in order to produce output. Dot-
matrix and Character printers fall under this category.
 Non-impact printers do not touch the paper while printing. They use
chemical, heat or electrical signals to etch the symbols on paper. Inkjet,
Deskjet, Laser, Thermal printers fall under this category of printers.
 Plotter: Plotters are used to print graphical output on paper. It interprets
computer commands and makes line drawings on paper using multicolored
automated pens. It is capable of producing graphs, drawings, charts, maps
etc.
 Facsimile (FAX): Facsimile machine, a device that can send or receive
pictures and text over a telephone line. Fax machines work by digitizing an
image.
 Sound cards and Speaker(s): An expansion board that enables a
computer to manipulate and output sounds. Sound cards are necessary
for nearly all CD-ROMs and have become commonplace on modern personal
computers. Sound cards enable the computer to output sound through
speakers connected to the board, to record sound input from a microphone
connected to the computer, and manipulate sound stored on a disk.
Memory

Computer’s memory can be classified into two types; primary memory and secondary
memory.

a. Primary Memory can be further classified as RAM and ROM.

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

RAM is volatile memory having a limited storage capacity. Secondary/auxiliary memory


is storage other than the RAM. These include devices that are peripheral and are
connected and controlled by the computer to enable permanent storage of programs and
data. Secondary storage devices are of two types; magnetic and optical. Magnetic
devices include hard disks and optical storage devices are CDs, DVDs, Pen drive, Zip
drive etc.

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.

A. System software - is responsible for controlling, integrating, and managing the


individual hardware components of a computer system so that other software
and the users of the system see it as a functional unit without having to be
concerned with the low-level details such as transferring data from memory to
disk, or rendering text onto a display. Generally, system software consists of an
operating system and some fundamental utilities such as disk formatters, file
managers, display managers, text editors, user authentication (login) and
management tools, and networking and device control software.

B. Application software - is used to accomplish specific tasks other than just


running the computer system. Application software may consist of a single
program, such as an image viewer; a small collection of programs (often called a
software package) that work closely together to accomplish a task, such as a
spreadsheet or text processing system; a larger collection (often called a
software suite) of related but independent programs and packages that have a
common user interface or shared data format, such as Microsoft Office, which
consists of closely integrated word processor, spreadsheet, database, etc.; or a
software system, such as a database management system, which is a collection
of fundamental programs that may provide some service to a variety of other
independent applications.

Difference of System Software and Application Software


System Software Application Software
Computer software or just
software is a general term
primarily used for digitally stored Application software, also
data such as computer programs known as an application or an
and other kinds of information "app", is computer software
read and written by computers. designed to help the user to
App comes under computer perform specific tasks.
software though it has a wide
scope now
1) Microsoft Windows 1) Opera (Web Browser)
Example:
2) Linux 2) Microsoft Word (Word
3) Unix Processing)
4) Mac OSX 3) Microsoft Excel
5) DOS (Spreadsheet software)
4) MySQL (Database Software)
5) Microsoft PowerPoint
(Presentation Software)
6) Adobe Photoshop
(Graphics Software)
Generally, users do not Users always interact with
Interaction: interact with system software as it application software while doing
works in the background. different activities.
System software can run Application software cannot
Dependency: independently of the application run without the presence of the
software system software.

CHARACTERISTICS OF COMPUTERS

The characteristics of computers that have made them so powerful and


universally useful are speed, accuracy, diligence, versatility and storage capacity.

Speed performing voluminous and repetitive


jobs.
Computers work at an incredible
speed. A powerful computer is capable Versatility
of performing about 3-4 million simple
instructions per second. Computers are versatile
machines and are capable of performing
Accuracy any task as long as it can be broken
down into a series of logical steps. The
In addition to being fast, presence of computers can be seen in
computers are also accurate. Errors that almost every sphere – Railway/Air
may occur can almost always be reservation, Banks, Hotels, Weather
attributed to human error (inaccurate forecasting and many more.
data, poorly designed system or faulty
instructions/programs written by the
programmer).
Storage Capacity
Diligence
Today’s computers can store
Unlike human beings, computers large volumes of data. A piece of
are highly consistent. They do not information once recorded (or stored) in
suffer from human traits of boredom and the computer, can never be forgotten
tiredness resulting in lack of and can be retrieved almost
concentration. Computers, therefore, instantaneously.
are better than human beings in
COMPUTER ORGANIZATION

A computer system consists of mainly


four basic units; namely input unit, storage
unit, central processing unit and output
unit. CPU further includes arithmetic logic
unit and control unit.

A computer performs five major operations or functions irrespective of its size and
make. These are

 It accepts data or instructions as input,


 It stores data and instruction
 It processes data as per the instructions,
 It controls all operations inside a computer, and
 It gives results in the form of output.

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)

 Arithmetic Logic Unit: All calculations and comparisons, based on the


instructions provided, are carried out within the ALU. It performs arithmetic
functions like addition, subtraction, multiplication, division and also logical
operations like greater than, less than and equal to etc.
 Control Unit: Controlling of all operations like input, processing and output are
performed by control unit. It takes care of step by step processing of all
operations inside the computer.

 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:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

UNDERSTAND THE PROBLEM

 Programmers must first understand what it is the user wants


 To understand the problem, you must analyze it
 Really understanding the problem may be one of the most difficult aspects of
programming
o The description of what the user needs may be vague
o The user may not even really know what he or she wants
o Users who think they know what they want frequently change their minds
after seeing sample output

PLAN THE LOGIC

Programmer plans the steps to the program, deciding what steps to include and
how to order them (e.g. planning tour, planning party, etc.)

The two most common tools:


 flowcharts : pictorial representation
 Pseudocode : English-like representation

Flowcharts

A pictorial representation of the logical steps it takes to


solve a problem.
 Uses Standardized Symbols
 Utilize Formula Notation
 Typically Read from Top to Bottom or from Left
to Right on a Page
PLAN THE LOGIC (Cont.)

Pseudocode

An English-like representation of the logical steps it takes to solve a problem.


 pseudo – a prefix that means false
 Short English-Like Statements
 Not Standardized
 Proper use of indentation
 Example:

CODE THE PROGRAM

 Writing the program in one of more than 400 programming languages


o Pascal, Assembly Language, C, C++, Java…..
 Concentrate on the syntax of the language
o Exact instruction, symbol, …. ?
 Some very experienced programmers
o Successfully combining the logic planning and the actual instruction
writing, or coding of the program, in one step
o Writing a cinema scenario

TRANSLATE THE PROGRAM

 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 THE PROGRAM

 Why does it need to be tested?


o Syntax Errors : by compile
o Logical Errors : by test
TEST THE PROGRAM (Cont.)

 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.

PUT THE PROGRAM INTO PRODUCTION

 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

The flowchart is a diagram which visually presents the flow of


data through processing systems. This means by seeing a flow chart
one can know the operations performed and the sequence of these
operations in a system. Algorithms are nothing but sequence of
steps for solving problems. So a flow chart can be used for
representing an algorithm. A flowchart, will describe the operations
(and in what sequence) are required to solve a given problem. You
can see a flow chart as a blueprint of a design you have made for
solving a problem.

ADVANTAGES OF FLOWCHART:

 Flowchart is an excellent way of communicating the logic of a program.


 Easy and efficient to analyze problem using flowchart.
 During program development cycle, the flowchart plays the role of a blueprint,
which makes program development process easier.
 After successful development of a program, it needs continuous timely
maintenance during the course of its operation. The flowchart makes program or
system maintenance easier.
 It is easy to convert the flowchart into any programming language code.

BASIC FLOWCHART SYMBOLS


Basic Flowchart Symbols Cont.

 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.

5. Connectors are used to connect breaks in the flowchart. Examples are:

 From one page to another page.


 From the bottom of the page to the top of the same page.
 An upward flow of more than 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.

8. All flowcharts end with a terminal or a contentious loop.

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.

Important technique for developing flowcharts:

 Use a standardized flowcharting template, with clearly recognizable symbols.


Follow ANSI recommendations for symbol use.
 Do not crowd or clutter the flowchart, ensure proper spacing between symbols.
 Number the pages of your flowchart sequentially. Specifically the title of program,
the date and the author on each separate page.
 Chart the main line of data flow in the system or program first, then incorporate
detail in later flowchart.
 Write within symbols avoid using too many words. If necessary use the
annotation symbol.
 Choose wording to suit the anticipated readers of the flowchart.
 Be legible, neatness counts.
 If flowchart becomes complex use connector symbols to reduce the number of
flow lines.
 Collect incoming and outgoing flow lines so that the number of lines entering or
leaving a symbol are minimized.
 Use the flowchart as a guide when coding; change it when necessary to ensure
the flowchart reflects the steps implemented in the code.
 Cross-reference portion of the flowchart to the source language code.
 Be consistent with the level of detail shown in the flowchart. Do not chart every
detail, but do not leave out important details.
 Put yourself in the position of the reader; try to anticipate the reader’s problems
in understanding the flowchart.

BASIC FLOWCHART STRUCTURE

 Sequence
 If-then-else (Selection)
 While (Repetition)

SEQUENCE

 The SEQUENCE process is just a series of processes


carried out one after the other.
 Most programs are represented at the highest level by the
sequence, possible with a loop from end back to the beginning.

If-THEN-ELSE (Selection)

 The If-THEN-ELSE process logically completes the binary


decision block by providing two separate processes.
 One of the processes will be carried out in the each path
from the binary decision.
 This is also called SELECTION.
BASIC FLOWCHART STRUCTURE Cont.

WHILE (Repetition)

 The WHILE process is allow for the representation of a


conditional loop structure within a program.
 The decision to execute the process is the loop is made
prior to the execution of the process.
 This is also called REPETITION.
Lesson 4: NAMING VARIABLES AND CONSTANT

VARIABLES

 A symbol or name that stands for a value.


 A variable is a value that can change.
 Variables provide temporary storage for information that will be needed during
the lifespan of the computer program (or application)

 Variables store everything in your program.


 The purpose of any useful program is to modify variables.
 In a program every, variable has:
o Name (Identifier)
o Data Type
o Size
o Value

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.

Rules in Naming a Variable

 There a certain rules in naming variables (identifier).


 They are:
o It should use only alphabets, number and underscore ( _ )
o It should not begin with a number and must have at least one alphabet.
o It should not be a reserved word.
Rules in Naming a Variable Cont.
 Examples of reserved word:

main long if do continue

short else return const int

double break void while char

 Examples of valid identifier (variable)

x number1 a123 number_2 _xyz

 Examples of invalid identifier (variable)

Variable - Reason

print main space not allowed

123number name should not begin with number

main reserved word

CONSTANT

 The opposite of a variable is a constant.


 A constant is a value that never changes.
 Because of their inflexibility, constants are used less often than variables in
programming.
 A constant can be :
o a number, like 25 or 3.6
o a character, like a or $
o a character string, like "this is a string"
Lesson 5: RAPTOR

INTRODUCTION

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.

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.

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 Name Description

input Allow the user to enter data. Each data


INPUT statement value is stored in a variable.

assignment Change the value of a variable using


PROCESSING statement some type of mathematical calculation.

procedure Execute a group of instructions defined


call in the named procedure. In some
cases some of the procedure
PROCESSING
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.

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.

An operator or function directs the computer to perform some computation on data.


Operators are placed between the data being operated on (e.g. X/3) whereas functions
use parentheses to indicate the data they are operating on (e.g. sqrt(4.7) ). When
executed, operators and functions perform their computation and return their result. The
following lists summarize the built-in operators and functions of RAPTOR.

basic math: +, -, *, /, ^, **, rem, mod, sqrt, log, abs, ceiling, floor

trigonometry: sin, cos, tan, cot, arcsin, arcos, arctan, arccot

miscellaneous: random, Length_of

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.

Operation Description Example

+ addition 3+4 is 7

- subtraction 3-4 is -1

- negation -3 is a negative 3

* multiplication 3*4 is 12

/ division 3/4 is 0.75

^ exponentiation, raise a number to a 3^4 is 3*3*3*3=81


power
** 3**4 is 81
rem remainder (what is left over) when 10 rem 3 is 1
the right operand divides the left
mod operand 10 mod 4 is 2

sqrt square root sqrt(4) is 2

log natural logarithm (base e) log(e) is 1

abs absolute value abs(-9) is 9

ceiling rounds up to a whole number ceiling(3.14159) is 4

floor rounds down to a whole number floor(9.82) is 9

sin trig sin(angle_in_radians) sin(pi/6) is 0.5

cos trig cos(angle_in_radians) cos(pi/3) is 0.5

tan trig tan(angle_in_radians) tan(pi/4) is 1.0

cot trig cotangent(angle_in_radians) cot(pi/4) is 1

arcsin trig sin-1(expression), returns radians arcsin(0.5) is pi/6

arcos trig cos-1(expression), returns arccos(0.5) is pi/3


radians

arctan trig tan-1(y,x), returns radians arctan(10,3) is 1.2793

arccot trig cot-1(x,y), returns radians arccot(10,3) is 0.29145

random generates a random value in the random * 100 is some value


range [1.0, 0.0) between 0 and 99.9999

Length_of returns the number of characters in Example ← "Sell now"


a string variable Length_of(Example) is 8

Procedure Call Statement/Symbol

A procedure is a named collection of programming statements that accomplish a task.


Calling a procedure suspends execution of your program, executes the instructions in
the called procedure, and then resumes executing your program at the next statement.
You need to know two things to correctly use a procedure: 1) the procedure's name and
2) the data values that the procedure needs to do its work, which are called arguments.
RAPTOR attempts to minimize the number of procedure names you need to memorize
by displaying any procedure name that partially matches what you type into the "Enter
Call" window. For example, after entering the single letter "d," the lower portion of the
window will list all built-in procedures that start with the letter "d". The list also reminds
you of each procedure's required arguments. In the example to the right, the lower box is
telling you that the "Draw_Line" procedure needs 5 data values: the x and y coordinates
of the starting location of the line, (x1, y1), the x and y coordinates of the ending location
of the line, (x2, y2), and the line's color. The order of the argument values must match
the arguments defined by the procedure. For example, Draw_Line(Blue, 3, 5, 100, 200)
would generate an error because the color of the line must be the last argument value in
the argument list.

Output Statement/Symbol

In RAPTOR, an output statement displays a value to the MasterConsole window when it


is executed. When you define an output statement, the "Enter Output" dialog box asks
you to specify three things:

 Are you displaying text, or the results of an expression (computation)?


 What is the text or expression to display?
 Should the output be terminated by a new line character?
The example output statement on the right will display the text, "The sales tax is" on the
output window and terminate the text with a new line. Since the "End current line" is
checked, any future output will start on a new line below the displayed text.

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,

"Active Point = (" + x + "," + y + ")"

will display the following if x is 200 and y is 5:

Active Point = (200,5)

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.

Non-user-friendly output User-friendly output

Example output: 2.5678 Example output: Area = 2.5678 square inches

Comments in RAPTOR

The RAPTOR development environment, like many other programming languages,


allows comments to be added to your program. Comments are used to explain some
aspect of a program to a human reader, especially in places where the program code is
complex and hard to understand. Comments mean nothing to the computer and are not
executed. However, if comments are done well, they can make a program much easier
to understand for a human reader.

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.

There are three general types of comments:

 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

So far, controlling which statement is executed next has been


incredibly easy. In the programs you have written so far, you
controlled which statement is executed next by ordering them
one after the other. Essentially you placed each statement in
the order that you wanted them to be executed. The first
statement of a program that is executed is the first statement
after the Start statement. Once that statement is finished
executing (i.e. the semantics associated with that statement
have been accomplished), then the statement immediately
following that statement is executed. Once the second
statement is executed, the third is executed, and then the fourth,
and so on until the End is reached. As you can see by the inset
diagram, the arrows linking the statements depict the execution
flow. If you have 20 programming statements in the instruction
section, then when your program runs successfully, it will
execute those 20 statements in order and then quit.

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

The algorithm you are developing may need to do


some actions based upon a decision. For
example, an algorithm that is evaluating a formula
can check to see if a number is negative before
taking the square root of that number and then
proceed differently depending on whether the Statement 1
result will be a normal number or a complex
number. Another example is processing grades.
If the grade is above 90%, an A is assigned to the
student, between 80% and 90%, a B is assigned Decision
to the student, and so on.

A selection-control statement controls whether or


not a collection of code is executed or which
Statement 2a Statement 2b
collection of code is executed. In the inset
diagram, the diamond shape represents a decision
that when executed could result in an answer of
Yes or No (True or False). Depending on what the
answer is, the flow of control will follow the Statement 3
appropriate path. In the example, either statement
2a or statement 2b will be executed. One of them
will be executed, but not both. However,
regardless of which statement 2 was executed,
statement 3 will always be executed.

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).

Cascading Selection statements


Sometime you are not making a selection between two alternatives, but making a
decision amongst multiple alternatives. If this is the case, you need to have multiple
selection statements. For example, if you are assigning a grade (A, B, C, D, or F) you
need to select between the multiple choices. The following RAPTOR program includes
multiple selection statements. If you follow the control logic, you can see how the
selections cascade (as in water cascading over a series of falls).
Iteration Control (Loop)

An iteration control statement controls how many times a block of code


is executed. Often you need to execute some code until a condition
occurs. As you may not know in advance how many times you will Statement 1
need to execute the code, you can’t simply cut and paste the code a
specific number of times. Even if you did know how many times the
code would repeat, copying it that many times is not a good idea, as
any error in your code would be replicated that many times as well.

In the diagram on the right, statement 1 and statement 2a are always


Statement 2a
executed. If the exit condition is true, then the loop exits and statement
3 is executed. If the exit condition is false the statement 2b and then
statement 2a are executed and the exit condition is checked again. As Exit
Condition
long as the exit condition is false, statement 2b and then statement 2a
will be executed again and again.

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.

Vous aimerez peut-être aussi