### Q-Basic

QBASIC(Quick Beginner's All Purpose Symbolic Instruction Code)

Introduction;

઴ It is one of the easiest high level programming language.
઴ It allows the usage of english-like language and uses mathematical notation.
઴ It was developed in 1964 at Dartmouth College, U.S.A. by professors John Kemeny and Thomas Kurtz.
઴ Some of the versions of BASIC are GW-BASIC,QBASIC and VISUAL BASIC.
઴ QBSIC environment includes a full screen syntax checking, multi-file and multi windows 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 keyword or a mouse.

1)QBASIC is very easy-to-learn programming language.
2)QBASIC is free to download and it comes pre-installed in windows 95/98.
3)Suitable for mathematical and business application.
4)Best for beginners to understand the programming language.
5)It checks for errors in syntax automatically.
6)It is easy to debug.

1)QBASIC is not a well-structured programming language.
2)It is mostly used in education or training.
3)QBasic cannot generate executable codes.
4)It is not a professional language.

※ VISUAL BASIC;

઴ Visual basic is third generation event driven programming language and integrated development environment from Microsoft first release in 1991.
઴ Visual Basic was derived from BASIC and enables the rapid application development of graphical user interface(GUI) applications.

※ How to start Qbasic Program?

Step1:- First you have to turn your PC to Operating system to do some task and then to place the Qbasic folder(software in appropriate place).
Step2:- Double Click on the Qbasic folder.
Step3:- Double Click on the QBASIC.EXE file.
Step4:- Press the ESC key to get the welcome screen and then you see the Editor windows.

※ Format of Qbasic Statement:

Statement;
Every command or instruction in Qbasic is called a statement. Syntax;
The way in which a particular statement should be written is called the syntax of the statement.

All Qbasic program lines have the following Syntax;
[line-identifier][statement][:statement).... [comment]

CLS
LET Principal = 500
LET Interest Rate = 3
LET Time = 6
LET si = (Principal * Time * Interest Rate) / 100
PRINT "Interest="; si
END

※ Basic elements of Qbasic language are;

1)Character Set
2)Constants
3)Variables
4)Operators
5)Reserved words.

※ Constant:→ Constant is a value stored in a program which does not change during program execution. Based on the type of data, it is classified as numeric constant and string constant.

※ Numeric constant:→ Numeric constant is a sequence of positive or negative numbers(with or without decimal points) on which mathematical operations can be performed. Commas are not allowed in a numeric constant. Some of the valid numeric constant are 12,-11,33.85,334.

※ String constant:→ String constant is a set of alphanumeric or special character enclosed within double quotes(“”). Blanks space can also be used in a string. These types of data can not be used for mathematical operation but can be used for comparisons and references. Some of the valid string constants are "Programming","street1","12" etc.

※ Symbolic constant:→ Symbolic constant is used when a value is not expected to change during the execution of the program and the value is used to more than once in the program. The CONST statement is a non-executable statement that declares symbolic constants to use in place of numeric or string values. The general format of CONST is; CONST constname = expression [Constame=expression]

※ Variable:→ Variables are the storage locations in the computer's memory for storing data which enable programmers to write flexible program. It is referred to by a name and those value can be altered during program execution.

※ Rules for naming variables names;

Given below are certain points to remember when naming a variable;
1)Any variable name may be up to 40 character long.
2)Variable name must begin with a letter(A...Z, a... z).
3)Variable names can not contain characters other than letters, numbers, period, and the type declaration characters(\$,%,#,&, and !).
4)Variable names can not be Qbasic reserved words.
5)Variables may represent either numeric values or strings.
6)A variable name can not contain space.

※ Variable Declaration;
The variable declaration in QBASIC can be classified as:
1)As declaration Statement(Explicit declaration).
2)Type declaration Suffix(impllicit declaration).
3)DEF type declaration.

AS declaration Statement(Explicit declaration);
Defining the variable in a declaration type has the following form;
declare variablename AS type
where the "declare" can be either DIM, COMMON, REDIM (for arrays), SHARED, or STATIC and the "type" can be either INTEGER, LONG, SINGLE, DOUBLE, STRING, or a user-defined type.

Some example are as follows;
DIM nam AS STRING Variable-length string
nam = "Avishek"
DIM num1 AS INTEGER
num1 = 32767
DIM num2 AS SINGLE, num3 AS DOUBLE
num2 = 3.409
num3 = 3.23233223344555
DIM ad AS STRING, I AS LONG, J AS SINGLE
DIM r AS SINGLE, a AS SINGLE
DIM address AS STRING *5 fixed length

⚛ Type declaration Suffix(Implicit declaration)
Append one of the type-declaration suffixes to the variable name as given in the following;

Type declaration(Suffix) Data types
\$ String
% Integer
& Long Integer
# Double Precision
C Single Precision

Some Example are as follows;
n\$ = "RAM"
i% = 14.5
li& = 1234563
dp# = 998877665544332211.99887766 5544332211
sp! = 123.456789

※Operator: An operator is a symbol representing the operations they perform on operands in a program.

※Operands: The values on which the operators work are referred to a operands. An operand may be a variable or constant.

※Expression: An expression is a programming statement that has a value. It is composed of operators and operands.
Example;
CLS
a = 5
b = 6
c = a + b
PRINT c
END

※ QBASIC supports the following types of operators;
1)Arithmetic operator
2)Relational operator

⚛String Operator (Concatenation Operator);

※ Arithmetic Operators: Arithmetic operators are the operators that operate on numeric constant and variables. They are used to perform different types of mathematical operations. The syntax of arithmetic operator is;
Op1 arithmetic.operator Op2
The arithmetic operators supported by QBASIC are listed in following table;

Operator Descriptions Example
^ Exponential r=m^n
* Multiplies the operands r= m*n
/ Floating point division r=m/n
\ Integer division r=m\n
MOD Modulus division r= m MOD n
- Subtraction r = m -n

※ Relational Operator: Relational operators are used to compare two values of same type, either both numeric or both string. We often compare two quantities and depending on their relation, take certain decisions. The general format is:
Operand1 relational.operator Operand2 QBASIC supports six relational operators in all. These operators and their meaning are shown in following table;

Operator Meaning
= Is equal to
< Is less than
> Is greater than
<= Is less than or equal
>= Is greater than or equal
<> Is not equal to

When arithmetic expressions are used on either side of relational operator, the arithmetic expressions will be evaluated first and then the results compared. That is arithmetic operators have a higher priority over relational operator.
Relational expression are used in decision statements such as if and while to decide the course of actions of a running program.

※ Logical Operator: Logical operators are used to connect two or more relational expressions to evaluate a single value as True or False.
The general format is:
Operand1 logical.operator Operand2
QBASIC supports three logical operators in all. These operators and their meaning are shown in following table;

Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

※ String Operator(concatenation): An expression involving string variables and constants are called string expressions. Joining of two strings called concatenation of strings. The string are connected by the concatenation operator, which is the plus(+) sign.
For example;
A\$="IT"
B\$="Programming"
PRINT A\$+""+B\$

String comparisons are actually made by taking one character at a time from each string and comparing their ASCII code values. If the ASCII codes in each string are same, then the strings are equal..
During string comparisons, if the end of the one string is reached, the shorter string is said to be smaller. Spaces in either expression are also counted. String comparisons can be used to test string value to alphabetize strings.