Qbasic
Introduction:
QBASIC stands for Quick Beginners All Purpose Symbolic Instruction Code. This programming language was developed by Bill Gates and Paul Allen.QBasic is an integrated development environment (IDE) and interpreter for a variety of dialects of BASIC which are based on QuickBASIC. Code entered into the IDE is compiled into an intermediate representation (IR), and this IR is immediately executed on demand within the IDE.
Features of QBASIC
- It is a user-friendly language.
- It uses a simple syntax to write programs.
- It provides a Windows-based platform to write programs.
- Debugging can be easily done.
- It is a compiler-based language.
Character sets in QBASIC
- Alphabets
- Number
- Special symbol eg.(@, #, $, % , etc.)
Operators
Operators are some symbols that perform logical and arithmetical calculations or operations. Which, arithmetical operations means addition, subtraction, multiplication, division, etc., and logical operation means the comparison of values. There are altogether three types of operators. They are:
- Arithmetical Operators eg. (+, -, *, etc.)
- Logical Operators eg. ( AND, OR, NOT, etc.)
- Relational Operators eg. (>, <, <=, >=, etc.)
Constant and Variable Data
Constant data are the values that don't change at the time of execution. There are two types of constant data. They are:
1. Numeric Constant eg. (integers, rational numbers, etc.)
2. Alpha-numeric Constant eg. (strings($) like "hello", "hi", etc.)
Variable data are the values that don't change at the time of execution. There are two types of constant data. They are:
1. Numeric Variable eg.( they start with alphabet like A=10, B=5, etc.
2. Alphanumeric Variable eg. ( they start with alphabet then "$" sym like A$="hi", B$="my", etc)
Commands and Statements
Commands are single word that tells the computer what to do. Some examples of commands in QBASIC are CLS, RUN, SAVE, etc. Statements are the set of instructions in a program. Some examples of statements in QBASIC are REM, INPUT, PRINT, etc. There are two types of statements they are executable statements i.e. REM and non-executable statements i.e. PRINT.
Writing Programs in QBASIC
Some simple programs:
Input
CLS
REM "To add and subtract two numbers"
Let A = 10 + 5
Let B = 10 - 5
Print"Sum =";A
Print "Difference =";B
END
Output
Sum = 15
Difference = 5
___________________________________________________________________________________
Input
CLS
REM "To multiply and divide two numbers"
Let A = 10/2
Let B = 10*2
Print"Product =";B
Print"Quesint =";A
END
Output
Product = 20
Quesint = 5
___________________________________________________________________________________
Input
CLS
REM" To calculate simple interest"
Let P = 100000
Let T = 3
Let R = 10
Let I = (P*T*R)/100
Print"Principle =";P
Print"Time =";T
Print"Rate =";R
Print"Interest =";I
END
Output
Principle = 100000
Time = 3
Rate = 10
Interest = 30000
___________________________________________________________________________________
Input
CLS
REM "To find area and volume"
Let L = 10
Let B = 5
Let H = 3
Let A = L*B
Let V = L*B*H
Print"Length =";L
Print"Breadth =";B
Print"Height =";H
Print"Area =";A
Print"Volume =";V
End
Output
Length = 10
Breadth = 5
Height = 3
Area = 50
Volume = 150
________________________________________________________________________
Input
CLS
REM"To display your details"
A$ = "Samip Rana"
B$ = "BNNP 8"
C$ = "15 years"
D$ = "SOSHGS Surkhet"
Print"Name: "; A$
Print"Address: "; B$
Print" Age: "; C$
Print"School's name: "; D$
END
Output
Name: Samip Rana
Address: BNNP 8
Age: 15 years
School's name: SOSHGS Surkhet
Note:- Plus>+, Minus>-, Multiply>*, Divide>/
Converting mathematical expression into QBASIC expression
Mathematical expression
1). x2+y2
2).x4+y3+z2
QBASIC expression
1). x^2 + y^2
2). x^4 + y^3 + z^2
Programs using the INPUT statement
Program 1
CLS
REM "To input registration number and name"
INPUT"Registration number"; A
INPUT"Name"; B$
Print"Registration number: "; A
Print"Name: "; B$
END
Conditional Statements
Those statements that are valid only in specific condition is called conditional statements. For example IF, ELSE, THEN, ELSEIF, etc. An example of a program using conditional statements.
CLS
REM "Using Conditional Statements"
Input "Any number"; A
IF A>0 Then Print "It is positive"
IF A<0 Then Print "It is negative"
END
CLS
REM "Using Conditional Statements"
Input "Any two numbers"; A, B
If A>B Then Print "A is greater than B"
If B>A Print "B is greater than A"
END
Comments
Post a Comment