QBASIC is a high level
computer language published by Microsoft which stands for Quick Beginners All Purpose Symbolic Instruction Code. QBASIC environment includes a
full screen syntax checking, multi-file and multi-window editing, full
debugging facilities, pull-down menus, syntax-checking editor and a simple
yet a powerful menu structure that can be driven through either by a keyboard
or a mouse. Once you are in the QBASIC
environment you can edit, run, debug and rerun the program without switching programs.
environment you can edit, run, debug and rerun the program without switching programs.
Features
Some of the salient features
of QBASIC are as follows:
1.
Simplified grammar.
2.
Dynamic program
debugging.
3.
Facility for manipulation
of strings.
4.
Easy to learn and
understand.
5.
Provides clear and
friendly error messages.
Elements of QBASIC
Programming
The important elements
of QBASIC program are:
1. QBASIC character set
Character set is a
defined list of characters recognized by QBASIC
program. A character represents any letter, digit or any other sign. The QBASIC
has the following character set:
Alphabets : A to Z (small and capital letters)
Numbers : 0 to 9
Special characters : ; =
+ - * / ^ ( ) % $ # ! , . ‘ “ : & ? \
2. Keywords (Reserved
words)
Keywords
are the words that convey a special meaning to the language. These are reserved
for special purpose and must not be used as normal identifier names. Some of
the keywords are: REM, CLS, INPUT, LET, PRINT and END.
3. Variables
Variable is an area in the computer memory
and within a program that can be referred to by name and whose value can be
altered during program execution. It also provides a way of labeling data with
a descriptive name, so our programs can be understood more clearly by the
reader and ourselves. It is helpful to think of variables as containers that
hold information. Their sole purpose is to label and store data in memory.
Variables are of two types: numeric variable and string variable.
a) Numeric Variable: Numeric variable has a number as its value. It
must begin with an alphabet and the remaining characters, if used, may be
alphabets or digits or both. Numeric variables may be declared as:
i) Integers and long integers Variable
Integer variable is declared by using a percent
sign (%) as the last character of the variable name. Integers are stored as 2
bytes ranging in value from -32768 to +32767. Long integer variable is declared
by using an ampersand sign (&) as the last character of the variable name.
Integers are stored as 4 bytes ranging in value from -2147483648 to
+2147483647.
ii) Single Precision Variable
Single precision
variable is declared by using an exclamation sign (!) as the last character of
the variable name.
iii) Double
Precision Variable
Double precision
variable is declared by using a number sign (#) as the last character of the
variable name.
b) String Variable
String
variable represents numbers, alphabets and special characters. This variable
should :
- Begin with an alphabet.
- End with dollar sign ($).
- Be of more than one characters and numbers but no special characters are allowed.
String variable are of
two types:
a) Variable-length string
A string by default is
of variable length, which means that the size of the variable changes when the
length of the allotted string changes. Variable length strings are very
flexible.
b) Fixed-length String
Compared to variable
length strings, fixed-length strings are rigid. After their length is declared,
it does not change. If you attempt to store more text than its capacity completely,
the text gets trimmed from the right.
4. Constants
Constant is a value that cannot be altered by the program during normal
execution, i.e., the value is constant.
Constants are of two types: numeric constant and string constant.
a) Numeric constant
As the name suggests,
numeric constant contain numbers. It is a positive or negative number on which
mathematical operations such as addition, subtraction, multiplication,
division, etc.
b) String constant
String constant contains
alphanumeric characters enclosed in double quotation marks.
5. Operators and Expressions
An operator is a symbol
representing the operations they perform on operands in a program. The values on
which the operators work are referred to as operands.
An expression is a
programming statement that has a value. It is composed of operators and
operands. An operand may be a variable or a constant.
There are 4 types of
operators. They are:
a) Arithmetic Operators
Arithmetic operators are
used to perform operations such as addition, subtraction, division,
multiplication, negation and exponentiation.
b) Relational Operators
Relational operators are
used to evaluate and compare two values of the same type, either both numeric
or both string. The result of comparison is either TRUE or FALSE.
c) Logical Operators
Logical operators are used
to connect two or more relations (expressions that contain relational
operators) and return a true or false value, which is used to make decisions
regarding program flow.
d) Concatenation Operators
Concatenation operators
join multiple strings into a single string. QBASIC use the plus sign (+) as a
string concatenation operator.
QBASIC Statements
QBASIC Statement is an
instruction given to the computer to carry out an action. The statements can be
divided into four categories:
i.
Declaration Statement
ii.
Assignment Statement
iii.
Input/output Statement
iv.
Control Statement
REM Statement
The word REM stands for
REMarks. It is used to write comments in the body of the program. REM is a
non-executable statement. The general format of REM is:
REM <remark>
Or
<remark>
CLS Statement
The CLS statement
is used to clear the screen and it leaves the cursor at the top left corner of
the screen. The general format of CLS is:
CLS
LET Statement
The LET statement is an
assignment statement. It is used to assign the value of an expression to a
variable. LET is an optional keyword. The general format of LET is:
LET <variable> = < expression >
INPUT Statement
INPUT statement is used
to receive data items from the keyboard during program execution. The general
format of INPUT is:
INPUT [“definer”;] list of variables
READ…DATA Statement
The READ…DATA statement contains
the names of the memory locations to be used to store the information in. They
are used in the following form:
READ [variable 1, variable2,… ]
…
…
DATA [constant 1, constant2,…]
CONST Statement
CONST statement is a
non-executable statement that declares symbolic constants to be used in place
of numeric or string values. The general format of CONST is:
CONST constantname = expression [,
constantname = expression]
PRINT Statement
The PRINT statement is
used to display numeric or string data on the screen. A question mark (?) may
be used instead of the word PRINT. The general format of PRINT is:
PRINT [List of expressions] [, \ ;]
Or
? [List of expressions] [, \ ;]
LOCATE Statement
The LOCATE statement is
used to move the cursor to the specified position on the screen and determine
the height of the cursor. The general format of LOCATE is:
LOCATE [row][,[cursor][,[start][,stop]]]]
END Statement
The END statement tells
the computer that the program is over, and should stop reading lines. . The
general format of END is:
END
No comments:
Post a Comment