0% found this document useful (0 votes)
60 views

Qbasic: BASIC Stands For Beginners All - Purpose Symbolic Instruction Code

jgjgkyjyjhhhfgfghhfjjjjjjdhhthhfghfhfjfgj

Uploaded by

krishnansh.s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Qbasic: BASIC Stands For Beginners All - Purpose Symbolic Instruction Code

jgjgkyjyjhhhfgfghhfjjjjjjdhhthhfghfhfjfgj

Uploaded by

krishnansh.s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

QBASIC

INTRODUCTION
BASIC stands for Beginners All – Purpose Symbolic Instruction code. QBASIC is a
high-level programming language that was developed by Microsoft as a simplified
version of the BASIC programming language. It was released in the 1980s and gained
popularity as a beginner-friendly language for learning programming concepts and
developing simple applications.
QBASIC was widely used in the early days of personal computers and served as an
entry point for many programmers. While it may not be as commonly used today, it still
holds educational value and provides a solid foundation for learning programming
concepts and logical thinking.

Features of QBASIC
 It is user-friendly language for beginners to start learning
programming concepts and develop simple applications.
 It has a simple and straight forward syntax.
 It provides capabilities for drawing shapes, lines, and text on the
screen, as well as playing sounds and music.
 It uses an interpreter.
 Debugging can be done easily.
Components of QBASIC

QBASIC comes with an Integrated Development Environment (IDE) that


provides a text editor for writing code, a debugger for finding and fixing
errors, and an interpreter for executing programs.
Title Bar: It displays the name of the application which is QBASIC. On
the right-hand side, we see the Minimize, Maximize and Close buttons.
Menu Bar: The menu bar has various menus such as File, Edit, View,
Search, Run, Debug, Options, Help.
Clicking on any of these will show you the commands under these menus.
Name of the Current Program: The name of the currently opened
program file is displayed at the top of the screen.
Status Bar: The status bar at the bottom of the screen displays a list of
shortcut keys to some commands.

Elements Of QBASIC Programming Language


QBASIC, as a programming language, consists of several key elements that
are used to write programs. Here are the main elements of QBASIC
programming:

 Keywords: QBASIC has a set of reserved words known as


keywords that have specific meanings in the language. These
keywords cannot be used as variable names or labels. Examples of
QBASIC keywords include PRINT, INPUT, IF, THEN, FOR,
NEXT, DO, LOOP, and DIM.
 Variables: Variables are used to store and manipulate data in a
QBASIC program. They are declared using the DIM statement
followed by the variable name and optionally the data type. For
example, DIM age AS INTEGER declares an integer variable
called "age". QBASIC supports different data types such as
INTEGER, SINGLE, DOUBLE, STRING, and BOOLEAN.
o Numeric Variable: Numeric variables store numeric data.
For example, DIM age = 30, here age is a numeric variable
which stores the constant value 30.
o String Variable: These variables are used to store a string of
characters. String variable names should always end with a $
sign. For example, name$="Radha", items$="eraser".
Rules of naming a variable
While naming variables we must follow the below mentioned rules:
• Both numeric and string variables must begin with alphabets.
• Variable names can contain numbers also but not at the starting position.
• The variable name must not have any space in between.
• Variable name must not contain any special characters.
 Constants: Constants are values that do not change during
program execution. They are assigned using the CONST statement
and are useful for storing fixed values that are used repeatedly in
the program.
 Operators: QBASIC supports various operators for performing
mathematical and logical operations. These include arithmetic
operators (+, -, *, /), comparison operators (=, <>, <, >, <=, >=),
logical operators (AND, OR, NOT), and string concatenation
operator (&).
 Expressions: QBASIC allows the combination of variables,
constants, and operators to form expressions. Expressions can be
used in assignments, calculations, and conditional statements. For
example, age = age + 1 is an expression that increments the value of
the "age" variable by 1.

COMMANDS/STATEMENTS
Here are some elementary QBASIC commands that are commonly used:

1. PRINT: Used to display output on the screen. It can display


constants, variables, or expressions on the screen.
For example: PRINT "Hello, World!"

To print a string always enclose it in double quotes but to print a number


simply write the number after the PRINT statement without quotation
marks.

Using Semicolon with PRINT


Using a semicolon with the Print command inserts a single blank
space in between the different values.
Using Coma with PRINT
A line on the QBASIC screen is separated into 5 zones, each with 14
spaces. We can use commas to put our text in different zones of the
line.
Leaving a Blank Line
To leave a blank line on the output screen, the print statement can be
written without any data or variable.

2. END: Used to indicate the end of the program.


For example:
PRINT "End of the program"
END

3. INPUT: Used to receive user input from the keyboard.


For example: INPUT "Enter your name: "; name$

If the user enters the wrong data, an error message "Redo from
Start" will be displayed and the user is allowed to enter the data
again.
Input statement also allows displaying a message to make the
program user friendly and to guide the user to enter correct data.
You can also enter multiple data and multiple variables in one
INPUT statement. In that case the variables must be separated by a
comma and the data entered must also be separated by a comma.
4. LET: Used to assign a value to a variable. Although LET is optional
and can be omitted, it is often included for clarity. For example:
LET x = 10

5. REM: REM command is used to put a comment line in your


program. It is like a program heading. This line is ignored by the
interpreter QBASIC and is not considered as an instruction.

6. CLS: It is a command used to clear the output screen. When we run


a program containing CLS command, it clears the output screen.

Control statements in QBASIC are used to control the flow of program


execution based on certain conditions or loops. They allow you to make
decisions, repeat a set of instructions, and alter the program's flow.
QBASIC provide some statements that can alter the flow of a sequence of
instructions. The statement which alters and transfers the flow of program
from one statement line to another are called control statements.

Mainly, there are two types of control statements in QBASIC. They are:

1) Branching Statement: Branching Statement also further divided into two types:
i) Conditional Branching Statement
 IF ... THEN
 IF ... THEN ... ELSE
 IF ... THEN ... ELSE IF
 SELECT CASE
ii) Unconditional Branching Statement
 GOTO

2) Looping Statement
i) FOR ... NEXT
ii) WHILE ... WEND
iii) DO LOOP

IF ... THEN Statement


It is the simplest form of the control statements which executes a block of statements
only if the given expression or condition is true. If the condition is false, then the IF
block will skip, and execution continues with the rest of the program.
Syntax:

IF [conditional expression] THEN [statement block]


OR
IF [conditional expression] THEN
[statement]
END IF
Example: 1

CLS
INPUT "Enter your marks : "; m
IF m >= 35 THEN PRINT "You are passed !!"
IF m < 35 THEN PRINT "You are failed .."
END

IF ... THEN .... ELSE Statement


It is a common control statement which is used to execute multiple statements
depending on a condition. It is also called two-way decision statement. In this statement
if the condition is true the statements after THEN will be executed and if the condition
is false, the statements in the ELSE block will be executed.
Syntax:

IF [conditional expression] THEN


[statement 1]
ELSE
[statement 2]
END IF

Example 1

CLS
INPUT "Enter your marks "; m
IF m >= 35 THEN
PRINT "You are passed !!"
ELSE
PRINT "You are failed .."
END IF
END

IF ... THEN ... ELSEIF Statement


If we have more than one condition, at that time we use IF ... THEN ... ELSEIF
statement. It is also called a multi-way decision statement.
Syntax:

IF [condition] THEN
[statement 1]
ELSEIF
[statement 2]
ELSEIF
[statement n]
........................
.......................
ELSE
[statement n]
END IF

Example 1

CLS
INPUT "Enter your percentage "; p
IF p >= 80 THEN
div$ = "Distinction"
ELSEIF p >= 60 THEN
div$ = "First Divistion"
ELSEIF p >= 40 THEN
div$ = "Second Division"
ELSEIF p >= 35 THEN
div$ = "Third Division"
ELSE
div$ = "Fail"
END IF
PRINT "Division ::: "; div$
END

Introduction to Looping Statement


The process of repeating or doing same task many times until the given condition is true
is called looping or iteration. There are different looping statements are used in
QBASIC such as FOR ... NEXT, WHILE .... WEND, DO ... LOOP, etc. It allows a
specified group of statements to be executed a certain number of times while certain
condition is true. Among these looping statements FOR ... NEXT is the most common
and popular looping statement.

FOR ... NEXT Loop


The FOR ... Next is a most popular and mostly used looping statement which is used to
execute the set of statements repeatedly for a given number of times.
Syntax:

FOR = TO STEP n
[statements]
NEXT

Example 1
WAP to print the natural numbers from 1 to 10.

CLS
FOR x = 1 TO 10
PRINT x;
NEXT x
END
Example 2
WAP to print even numbers from 1 to 20

CLS
FOR i = 2 TO 20 STEP 2
PRINT i;
NEXT i
END
Example 3
WAP to print your name 10 times

CLS
FOR i = 1 TO 10
PRINT "Your Name"
NEXT i
END

Objective Questions: -
A. Multiple choice questions:
a. This statement is used to terminate or end the program.
i. Input ii. End iii. CLS
b. This command is used to clear the output screen.
i. REM ii. END iii. CLS
c. This command is like a program heading.
i. Input ii. REM iii. END
d. A line number on the QBASIC screen is separated into ______.
i. 2 zones ii. 5 zones iii. 7 zones
e. This variable is used to store a string of characters.
i. Numeric ii. String iii. Constants
B. Fill in the blanks:
a. ___________ are the data values used in a Basic program.
b. ___________ is a version of BASIC.
c. AND/ OR are the _______________ operators.
d. ___________ variable store numeric data.
C. Answer the following questions:
a. What do you understand by QBASIC?
b. Why is QBASIC environment called an IDE?
c. What are constants? Explain how a constant is declared in
QB?
d. What is the importance of QBASIC?
e. What is Input statement? Mention its syntax.
f. What is iteration?
g. How is if else different from if else if statement?
h. Explain the role of step while using for next statement.

Programming Based Questions:


1. Write a program to calculate the sum of two numbers and display
the result.
2. Write a program to convert temperature from Fahrenheit to Celsius.
3. Write a program to calculate the area of a rectangle given its length
and width.
4. Write a program to calculate the area and circumference of a circle.
5. Write a program to accept a student’s name and three subject marks.
Calculate and display his aggregate marks.
6. Write a program to accept a number and check if it is an even
number or not.
7. Write a program to read cost price and selling price of a commodity
and evaluate and display the profit percentage or loss percentage.
8. Write a program to read a number and check if it is a single digit
number, double digit or more. Display a remark accordingly.
9. Write a program to find the largest among three numbers.
10.Write a program to check if a given number is prime or not.
11.Write a program to calculate the factorial of a given number.
12.Write a program to reverse a given string.
13.Write a program to print numbers from 20 to 1 in descending order.
14.Write a program to display the multiplication table of a given
number.
15.Write a program to print the first N terms of the Fibonacci series
using a loop.
16.Write a program to calculate the sum of all the numbers from 1 to N
using a loop.
17.Write a program to find the sum of the digits of a given number
using a loop.
18.Write a program to reverse a given number using a loop.
19.Write a program to find the sum of all the even numbers between 1
and 100.
20.Write a program to check if a given string, is a palindrome.

You might also like