KnowledgeBoat Logo
OPEN IN APP

Chapter 9 - Unit 3

Fundamentals of QBASIC: Commands and Statements

Class 6 - APC Understanding Computer Studies



Choose the correct option

Question 1

Which of the following is not a BASIC statement?

  1. PRINT
  2. LET
  3. RUN
  4. REM

Answer

RUN

Reason — RUN is a command that is used to execute a BASIC program.

Question 2

Which of the following commands is used to execute a BASIC program?

  1. FOR
  2. EXIT
  3. EXECUTE
  4. RUN

Answer

RUN

Reason — RUN command is used to execute a BASIC program.

Question 3

Which of the following is correct about LET keyword?

  1. It is optional for assignment statement.
  2. All basic statements start with this keyword.
  3. It helps to execute BASIC programs.
  4. It makes the programming logic easier.

Answer

It is optional for assignment statement.

Reason — LET is an optional statement. Every BASIC program need not use LET statement.

Question 4

Which of the following is the correct extension of QBASIC file?

  1. .Basic
  2. .EXE
  3. .BAS
  4. .BASIC

Answer

.BAS

Reason — All QBASIC programs are saved with the extension .bas.

Question 5

Which of the following commands is used to save a BASIC program?

  1. Save
  2. Save As
  3. Save New
  4. Save First

Answer

Save As

Reason — Save As command is used to save a BASIC program for the first time.

Fill in the blanks

Question 1

The full form of QBASIC is Quick Beginner's All-Purpose Symbolic Instruction Code.

Question 2

LET statement is used to assign a value to a variable.

Question 3

The term used to correct errors in a program is called debugging.

Question 4

F5 function key is used to execute a program in QBASIC.

Question 5

REM is a non-executable statement.

Question 6

The extension of BASIC program file is .bas.

Question 7

The maximum number of characters in the primary name of a BASIC file is eight.

Question 8

Using EXIT command, you can quit QBASIC and return to the desktop.

Question 9

Statements are the set of instructions to a program.

Question 10

Save As option is used to store a program in the secondary memory for the future use.

Identify the errors

Question 1

CLEAR
LET A = 15
TAKE B = 10
P = (A + B)2
DISPLAY P
END

Answer

CLS
LET A = 15
LET B = 10
P = (A + B) ^ 2
PRINT P
END

Question 2

CLS
INPUT A = 10
LET B = 45
P = (A x B) / 5 + B
PRINT P
STOP

Answer

CLS
LET A = 10
LET B = 45
P = (A * B) / 5 + B
PRINT P
END

Case-Study Based Questions

Question 1

Your teacher has given an assignment where the values of the variables are given as:

M=8; N=5; P=6; Q=3

(a) P * Q + M - N

(b) ( P + Q ) / ( P - Q )

(c) P ^ 2 + M / N

(d) M * N + P / 2

Find the result of each of the above expression.

Answer

(a) 21

(b) 3

(c) 37.6

(d) 43

Question 2

Your friend has doubt in writing some of the QBASIC expressions. Help him to write the expressions correctly for the following purposes:

(a) To divide the sum of p and q by the difference of p and q.

(b) To divide the product of a, b and c by their sum.

(c) To find the sum of m raised to the power 2 and n raised to the power 3.

(d) To subtract p from the sum of m and 5 and multiply the difference by 10.

Answer

(a) ( P + Q ) / ( P - Q )

(b) ( A * B * C ) / ( A + B + C )

(c) M ^ 2 + N ^ 3

(d) ( ( M + 5 ) - P ) * 10

Explain the meaning

Question 1

Explain the meaning of the following commands/statements with reference to QBASIC:

  1. New
  2. Open
  3. Save As
  4. Print
  5. Exit

Answer

  1. New — It allows the user to clear the working memory for fresh storage of the next program.
  2. Open — It allows the user to open an existing program which is already stored in the main memory of the computer.
  3. Save As — It allows the user to save the current program in the computer's memory for future use.
  4. Print — It allows the user to get a hard copy of the current program.
  5. Exit — It allows the user to quit QBASIC and return to the desktop.

Define the following

Question 1

RUN

Answer

This command is used in QBASIC to execute any program or to see the output of the program. This can also be done by pressing F5, a function key. The output of the program is displayed on the output screen.

Question 2

CLS

Answer

It is advised to see the output of a program on a clear screen. CLS command is used at the beginning of the program to allow the user to study the desired output of the program.

Question 3

LET

Answer

LET statement is used to assign a value to a variable. This statement can be used to assign a numeric or string constant to a variable.

Syntax:
LET <variable> = <constant or variable or expression>

Question 4

REM

Answer

REM statement is used to write remarks about any program which basically shows the purpose of a program. It is a non-executable statement. Hence, the computer will ignore the content of the REM statement at the time of execution.

Syntax:
REM <comment about the program>

Question 5

PRINT

Answer

PRINT statement is used to display any data, value, or message on the screen. It can be used to display a message, the value of variables or any statement with comma or a semi-colon.
For example:
PRINT "HELLO"
PRINT A, B

Write down all the steps to perform the following tasks in QBASIC

Question 1

Write a new program

Answer

To write a new program, follow these steps:

Step 1 — Click 'QBASIC' icon on the desktop or the taskbar.
OR
Click 'Start' and type QBASIC in the search box followed by clicking QBASIC app.
The QBASIC window opens on the screen.

Step 2 — Press 'ESC' key to clear the dialog box appearing on the screen.

Step 3 — Select the 'File' menu. Now, click the option 'New'.

The QBASIC screen will now be ready to write the program.

Question 2

Save a program

Answer

To save a program, follow these steps:

Step 1 — Click 'File' and select 'Save As' from the drop-down menu. The 'Save As' window appears on the screen.

Step 2 — Select a directory/drive where you want to store the file.

Step 3 — Write the file name in the 'File Name' box

Step 4 — Click 'OK'.

The file will be saved in the desired location.

Question 3

Get the hard copy of a program

Answer

To get the hard copy of a program, follow these steps:

Step 1 — Open the program whose hard copy is required.

Step 2 — Click 'File' and select 'Print' option from the drop down menu. Print window will appear.

Step 3 — Select the printer, page layout, number of copies required etc. and click 'Print' option.

The program will be printed.

Question 4

Save the current program

Answer

To save the current program, follow these steps:

Step 1 — Click 'File' menu.

Step 2 — Select 'Save' option from the drop down menu.

The current program file will be saved.

Question 5

Exit QBASIC platform.

Answer

To exit QBASIC platform, follow these steps:

Step 1 — Click 'File' and select 'Exit' from the drop down menu.

Step 2 — Press 'Enter' key.

Step 3 — If you have made any changes to the current program, the system will ask for confirmation from the user. Click 'Yes', 'No' or 'Cancel' according to your need.

QBASIC platform will close and return to the desktop.

Distinguish between

Question 1

RUN and PRINT

Answer

RUNPRINT
This command is used in QBASIC to execute a program or to see the output of the program.This command is used to display any data, value or message on the screen.

Question 2

Program Screen and Output Screen

Answer

Program ScreenOutput Screen
Program screen is used for writing or editing a program.Output screen shows the output of a program when the program is run.

Solutions to Unsolved Programs on LET & PRINT

Question 1

Write a program in QBASIC to greet your friend on the occasion of New Year by using PRINT statement. The output of the program is shown as:

Season's Greeting  
Best Wishes for  
A Happy and Prosperous New Year   
From:  
Name:   
Solution
PRINT "Season's Greeting"
PRINT "Best Wishes for"
PRINT "A Happy and Prosperous New Year"
PRINT "From:"
PRINT "Name: KnowledgeBoat"
Output
Season's Greeting
Best Wishes for
A Happy and Prosperous New Year
From:
Name: KnowledgeBoat

Question 2

There are 28 boys and 22 girls in your class. Write a program in QBASIC to find the percentage of boys and girls in the class.

Solution
Cls
Let B = 28
Let G = 22
Let T = B + G
Let PERB = B / T * 100
Let PERG = G / T * 100
Print "PERCENTAGE OF BOYS= "; PERB
Print "PERCENTAGE OF GIRLS= "; PERG
End
Output
PERCENTAGE OF BOYS= 56
PERCENTAGE OF GIRLS= 44

Question 3

The base and height of a triangle are 15 cm and 10 cm respectively. Write a program in QBASIC to calculate the area of the triangle.
(Hint: Area of a triangle = 1 / 2 * base * height)

Solution
Cls
Let B = 15
Let H = 10
Let A = 1 / 2 * B * H
Print "AREA OF THE TRIANGLE= "; A; "SQ CM"
End
Output
AREA OF THE TRIANGLE= 75 SQ CM

Question 4

A salesman sold 14 chairs at the rate of ₹ 275 each and 3 tables at the rate of ₹ 650 each. Write a program in QBASIC to calculate the total sale.

Solution
Cls
Let C = 14
Let COSTC = C * 275
Let T = 3
Let COSTT = T * 650
Let TOTAL = COSTC + COSTT
Print "TOTAL SALE= Rs. "; TOTAL
END
Output
TOTAL SALE = Rs. 5800

Question 5

Write a program in QBASIC to calculate the area and circumference of a circle with a radius of 14 cm.
(Hint: Area of a circle = 22/7 * r2, Circumference = 2 * 22/7 * r)

Solution
Cls
Let R = 14
Let A = 22 / 7 * R * R
Let C = 2 * 22 / 7 * R
Print "AREA= "; A; "SQ CM"
Print "CIRCUMFERENCE= "; C; "CM"
End
Output
AREA = 616 SQ CM
CIRCUMFERENCE = 88 CM 

Assignment

Question 1

Write a program in QBASIC to find the value of the given expressions when a = 10, b = 5, c = 2.

  1. a2 +b3 +c4
  2. (a + b)2
  3. a2 + b2
  4. (a - b + c)2
Solution
Cls
Let A = 10
Let B = 5
Let C = 2
Let EXP1 = A * A + B * B * B + C * C * C * C
Let EXP2 = (A + B) ^ 2
Let EXP3 = A * A + B * B
Let EXP4 = (A - B + C) ^ 2
Print "ANSWER OF EXPRESSION 1= "; EXP1
Print "ANSWER OF EXPRESSION 2= "; EXP2
Print "ANSWER OF EXPRESSION 3= "; EXP3
Print "ANSWER OF EXPRESSION 4= "; EXP4
END
Output
ANSWER OF EXPRESSION 1= 241
ANSWER OF EXPRESSION 2= 225
ANSWER OF EXPRESSION 3= 125
ANSWER OF EXPRESSION 4= 49

Question 2

In a class of 60 students, 90% are present. Write a program in QBASIC to calculate the number of students present and absent.

Solution
Cls
Let T = 60
Let PRESENT = 90 / 100 * 60
Let ABSENT = T - PRESENT
Print "STUDENTS PRESENT= "; PRESENT
Print "STUDENTS ABSENT= "; ABSENT
END
Output
STUDENTS PRESENT= 54
STUDENTS ABSENT= 6

Question 3

The rate of petrol is ₹ 47.60 per litre. You paid ₹ 250 to the pump attendant and asked for 5 litres of petrol to be filled in the tank. Write a program in QBASIC to calculate the cost of petrol and the amount of money refunded.

Solution
Cls
Let RATE = 47.6
Let COST = 5 * RATE
Let PAID = 250
Let REFUND = PAID - COST
Print "MONEY REFUNDED = Rs. "; REFUND
END
Output
MONEY REFUNDED = Rs. 12

Question 4

In a book fair, you purchased the following books:

Harry Potter Books : ₹ 950
English Dictionary : ₹ 1200
Encyclopedia : ₹ 1600

You gave an amount of ₹ 4000 to the shopkeeper. Write a program in QBASIC to calculate the total amount to be paid to the shopkeeper and the money refunded by him.

Solution
Cls
Let HPB = 950
Let ED = 1200
Let EN = 1600
Let TOTAL = HPB + ED + EN
Let AMT = 4000
Let REFUND = AMT - TOTAL
Print "TOTAL MONEY TO BE PAID = Rs. "; TOTAL
Print "REFUND = Rs. "; REFUND
End
Output
TOTAL MONEY TO BE PAID = Rs. 3750
REFUND = Rs. 250

Question 5

'LEXPO' announces 25% discount on all leather items. You purchased a leather bag that costs ₹ 660 and a belt priced ₹ 160. Write a program in QBASIC to calculate the amount to be paid to the shopkeeper.

Solution
Cls
Let LB = 660
Let B = 160
Let TOTAL = LB + B
Let DISC = 25 / 100 * TOTAL
Let AMT = TOTAL - DISC
Print "AMOUNT TO BE PAID = Rs. "; AMT
End
Output
AMOUNT TO BE PAID = Rs. 615
PrevNext