Programming Terms-QBASIC

By: Zyoti Bhattarai
2018-Feb-18

Programming Language:

Programming language is defined as a language that helps human to provide instruction to the computers. It is used in developing softwares which in turn are translated into the machine readable form by respective language translator and then are executed by the machine.

QBASIC:

QBASIC is a high level programming language. It uses an interpreter to convert the high level program codes into machine code and also executes the statetement lines.

There are different elements of QBASIC programming that makes up the program. Those elements are; Characterset, Variables, Constants, Operators, Exressions and Statements.

Characterset:

Characterset of QBASIC is a set of characters that can be used to write a program. The QBASIC characterset includes;

  1. Alpahbets from a-z(both uppercase and lower case)
  2. Digits from 0-9
  3. Special symbols(type declaration symbols, operators and others)

Variables:

Programs are likely to use values to do some processing tasks. The values are stored in computer memory atleast during the processing on data. Variables are the named storage locations in computer memory that store data to be used in programs. It is named variable as its value may vary during the execution of program.

In QBASIC, variables are of two major types; Numeric and String.

  1. Numeric variables: Numeric variables are those variables which store numeric values(number with or without decimal points and negation) on which mathematical calculations can be done. Numeric variables are further divided into four sub types; Integer, Long Integer, Single Precision(7-digit, with or without decimal points0 and Double precision(15-digit, with or without decimal point). The type declaration symbol used for each of these sub types are %, &, ! and # respectively. By default, the numeric variable is of single precision type.

  2. String Variable: String variables are those variables which store string of characters. These variables are identified by a $ sign during the implicit declaration of variable in QBASIC.

Declaration of variable:

Variables in QBASIC can be declared in two different ways; Implicit and Explicit

  1. Implicit declaration: Implicit declaration is the default method of declaring variable in QBASIC. Using this method, we can declare variable at the time of assigning value to the variable. One should take care of type declaration symbol during the declaration and use of variable. One can use LET statement to declare variables implicitly but LET statement is not mandatory in newer versions of QBASIC.
  2. Explicit declaration: Explicit declaration of variable is done before the use of variables. DIM statement is used to declare variables explicitly in QBASIC. Eg: DIM a AS INTEGER, DIM b AS STRING, etc. Its not mandatory to use type declaration symbol while declaring variables explicitly. Also, as all variables are declared at the top, programmers are less prone to use same variable name for different purpose.

 

Local and Global Variables:

In QBASIC(Modular Programming), based on the scope, variables can be categorized into two different types;

  1. Local Variable: Local variable is the variable defined in any module which can't be accessed from any other module. In QBASIC, variables are local by default. For Eg: LET x=10, DIM x AS DOUBLE
  2. Global Variable: Global variable is the variable defined in module(generally main module) which can be accessed from any module in a program. In QBASIC, variables are declared global by using statements like COMMON SHARED and DIM SHARED. For Eg: COMMON SHARED P, DIM SHARED R(10)

Special Variables:

  1. Counter: Counter is a variable which is used to count the occurance of particular condition in a program. It can also be used to count the number of repetition in a loop.
  2. Accumulator: Accumulator is a variable which accumulates the value in a loop. A variable storing sum of 50 natural numbers can be named an accumulator.
  3. Flag: Flag is a variable which is used in program to check whether certain condition appeared or not. For Eg: IF C=3 THEN F=1. Here, F is flag whose.

Constants:

Constants are defined as the values used in programs that donot change during the execution of program. Constants are also categorised into two different types; Numeric and String. Numeric constants are numbers with or without decimal points or negation and String constants are the collection of string(alphabet, number or symbol) enclosed by double inverted comma. Constants can also be saved under a name which are called symbolic constants or literal constants. CONST statement is used to declare the constants in QBASIC programming. For Eg: CONST pi=3.14.

 


Operators:

Operator is the symbol or a command that is used to perform operation on operands(values or variables) in program. There are different types of variables supported by QBASIC.

  • Arithmetic operator: Arithmetic operators are those operators which helps program perform mathematical calculations in data. Below is the list of Arithmetic operators used in QBASIC;
Name of operator Symbol
Exponent    ^
Division     /
Integer Division(returns quotient without decimal points     \
Modular Division(Returns remainder)     MOD
Multiplication     *
Addition     +
Subtraction      -
  • Relational Operator: Relational operators are the symbols that are used to compare two values of same type. Examples of relational operator are:- >,<,>=,<=,= ,< >(not equale to). Relational operators gives logical(boolean) result. i.e. One among Yes or No(True or False). For. Eg: x>15, y$<>"E".
  • Logical Operator: Logical operators are the operators which are used to derive the result from one or more relational operators. Logical operators also provide result among "TRUE" or "FALSE",i.e. BOOLEAN or LOGICAL result. Logical operators used in QBASIC are AND, OR and NOT.
    • AND: AND operator is a logical operator that returns "TRUE" result only when all relational expression result in "TRUE" and returns "FALSE" if one or more relational expressions result in "FALSE". Truth table of AND operator is shown below;
      Truth Table "AND"
      Expression 1 Expression 2 Expression 1 AND Expression 2
      FALSE FALSE FALSE
      FALSE TRUE FALSE
      TRUE FALSE FALSE
      TRUE TRUE TRUE

       

    • OR: OR operator is the logical operator that returns "TRUE" when any relational expression results in "TRUE" and returns "FALSE" only when all the relational expressions return "FALSE". The truth table of OR operator is given below;
      Truth Table "OR"
      Expression 1 Expression 2

      Expression 1 OR Expression 2

      FALSE FALSE FALSE
      FALSE TRUE TRUE
      TRUE FALSE TRUE
      TRUE TRUE TRUE

       

    • NOT: NOT operator is a logical operator which reverses the result of relational expression. NOT operator is used with single operand. Truth Table of NOT operator is given below;
      Truth Table NOT
      Expression 1 NOT Expression 1
      FALSE TRUE
      TRUE FALSE

Modular Programming:

Modular programming is a programming technique in which the program is divided into multiple self-dependent modules. The advantages in adapting modular programming technique are listed below;

  1. Easy Development: Coding, Testing, Debugging and Modification of program becomes easier in small modules.
  2. Job Distribution: Single program can be distributed among various programmers.
  3. Reusability: Modules used in one program can be used in other programs if needed.

In QBASIC, two different types of modules can be used; Sub Procedure and Function Procedure. The following table explains about them with the differences;

Sub Procedure Function Procedure
- It is a block of program that performs a set of task. - It is a block of program that performs one particular task.
- It doesn't return any value. - It returns value.
- It doesn't have any datatype. - It has datatype.
- It is called using a CALL statement. - It is called wherever the function name is mentioned.

Parameters:

Parameters are defined as the values or variables passed from a calling module to a called module. Parameters are generally categorized into two different types;

  1. Formal Parameters: Formal parameters are those which are used to reserve the memory location to be occupied by the values used in program. These are used in Declare statement as well as in the sub module.
  2. Actual Parameters: Actual parameters are those which are passed to submodule during call. Actual parameters are also known as Real parameters or Arguments. These parameters are used with calling statement.

There are two different ways of passing arguments to sub modules;

  1. Pass by reference: In pass by reference method, we pass the memory address of the value to the sub module. Since the original address is sent, changes made in subprocedure are also reflected in the calling procedure. In QBASIC, the default method of passing argument is 'Pass by Reference' method. Eg: CALL ADD(C,D) or PRINT AREA(C,D)
  2. Pass by value: In pass by value method, instead of passing the memory address, the copy of value is sent to the sub module. Any changes made in subprocedure are not reflected in calling procedure. In QBASIC, passing of parameters by value is done by enclosing the parameters by an extra pair of paranthesis. For Eg: CALL ADD((C),D). Here, C is passed by value and D is passed by reference.



Author: Jyoti Bhattarai

Address: Maitidevi, Kathmandu

an IT student

leave a comment