Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Chapter -18

QBASIC Programming
Exercises
1. Answer the following questions
a. What is QBasic programming language?
QBasic stands for Quick Beginners All-purpose Symbolic Instruction Code. It is
a high-level programming language developed by Microsoft for beginners to
learn programming concepts. QBasic provides a simplified syntax and
environment, making it ideal for educational purposes and quick prototyping of
small-scale applications.
b) What are the elements of QBasic?
The elements of QBasic are:
 Variables: Used to store data values.
 Data Types: Such as integer, floating-point, string, and arrays.
 Operators: Including arithmetic, relational, logical, and bitwise operators.
 Control Structures: Such as IF-THEN, FOR-NEXT, DO-LOOP for decision
making and looping.
 Procedures and Functions: Allow for modular programming by defining
reusable code blocks.
 Input/Output Commands: To interact with users and display information on
the screen.
 Statements: Including assignment statements, input/output statements, and
control statements.
c) What are the different types of QBasic statements?
various types of QBasic statements are :
 Assignment Statements: Assign values to variables.
 Input/Output Statements: Read input from the user or display output to the
screen.
 Control Statements: Control the flow of program execution, such as IF-
THEN, FOR-NEXT, DO-LOOP.
 Subroutine/Function Definition Statements: Define reusable blocks of code.
 Error Handling Statements: Handle errors and exceptions during program
execution.
d) What is the extension of QBasic program file? Which key is used to run
QBasic program?
The extension of QBasic program files is typically ".BAS". To run a QBasic
program, F5 key is pressed after writing the code. This command initiates the
compilation and execution process in the QBasic environment.
e) Which operator is used to perform addition in QBasic?
The plus sign (+) is used to perform addition in QBasic, just like in many other
programming languages. For example, a + b would add the values of variables a
and b.
f) What are character set used in QBasic while programming?
In QBasic, the character set used for programming are:
 letters from A to Z (both uppercase and lowercase),
 numbers from 0 to 9,
 punctuation marks(special characters) such as !, @, #, $, and symbols like
&, *, etc.
2. Write a program for the following
a. To calculate the area of four walls of A room
b. Do calculate the area for circle
c. To calculate the volume of a cylinder
d. To calculate the circumference of a circle
e. To calculate the square and cube of the of a given number
f. To calculate the square and cube of the of a given number to calculate
the area and volume of a sphere
REM To calculate the area of four walls of a room. [A=2H(L+B)]
CLS
INPUT "Enter the height of the room: "; H
INPUT "Enter the length of the room: "; L
INPUT "Enter the breadth of the room: "; B
W1 = 2 * H * (L + B)
PRINT "Area of four walls of the room:", W1
END

2) REM To calculate the area of a circle.


CLS
CONST PI = 3.14159
INPUT "Enter the radius of the circle: "; R
A = PI * R^2
PRINT "Area of the circle:", A
END

3) REM To calculate the volume of a cylinder.


CLS
INPUT "Enter the radius of the cylinder: "; R
INPUT "Enter the height of the cylinder: "; H
V = PI * R^2 * H
PRINT "Volume of the cylinder:", V
END

4) REM To calculate the circumference of a circle.


CLS
INPUT "Enter the radius of the circle: "; R
C = 2 * PI * R
PRINT "Circumference of the circle:", C
END

5) REM To calculate the square and cube of a given number.


CLS
INPUT "Enter a number: "; N
S = N^2
C = N^3
PRINT "Square of the number:", S
PRINT "Cube of the number:", C
END

6) REM To calculate the area and volume of a sphere.


CLS
INPUT "Enter the radius of the sphere: "; R
A = 4 * PI * R^2
V = (4/3) * PI * R^3
PRINT "Surface area of the sphere:", A
PRINT "Volume of the sphere:", V
END

You might also like