Choose the correct option
Which of the following is not a BASIC statement?
Reason — RUN is a command that is used to execute a BASIC program.
Which of the following commands is used to execute a BASIC program?
Reason — RUN command is used to execute a BASIC program.
Which of the following is correct about LET keyword?
- It is optional for assignment statement.
- All basic statements start with this keyword.
- It helps to execute BASIC programs.
- It makes the programming logic easier.
It is optional for assignment statement.
Reason — LET is an optional statement. Every BASIC program need not use LET statement.
Which of the following is the correct extension of QBASIC file?
Reason — All QBASIC programs are saved with the extension .bas.
Which of the following commands is used to save a BASIC program?
- Save As
- Save New
- Save First
Reason — Save As command is used to save a BASIC program for the first time.
Fill in the blanks
The full form of QBASIC is Quick Beginner's All-Purpose Symbolic Instruction Code.
LET statement is used to assign a value to a variable.
The term used to correct errors in a program is called debugging.
F5 function key is used to execute a program in QBASIC.
REM is a non-executable statement.
The extension of BASIC program file is .bas.
The maximum number of characters in the primary name of a BASIC file is eight.
Using EXIT command, you can quit QBASIC and return to the desktop.
Statements are the set of instructions to a program.
Save As option is used to store a program in the secondary memory for the future use.
Identify the errors
LET A = 15
TAKE B = 10
P = (A + B)2
LET A = 15
LET B = 10
P = (A + B) ^ 2
INPUT A = 10
LET B = 45
P = (A x B) / 5 + B
LET A = 10
LET B = 45
P = (A * B) / 5 + B
Case-Study Based Questions
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.
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.
(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
Explain the meaning of the following commands/statements with reference to QBASIC:
- Save As
- New — It allows the user to clear the working memory for fresh storage of the next program.
- Open — It allows the user to open an existing program which is already stored in the main memory of the computer.
- Save As — It allows the user to save the current program in the computer's memory for future use.
- Print — It allows the user to get a hard copy of the current program.
- Exit — It allows the user to quit QBASIC and return to the desktop.
Define the following
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.
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.
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.
LET <variable> = <constant or variable or expression>
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.
REM <comment about the program>
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.
PRINT A, B
Write down all the steps to perform the following tasks in QBASIC
Write a new program
To write a new program, follow these steps:
Step 1 — Click 'QBASIC' icon on the desktop or the taskbar.
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.
Save a program
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.
Get the hard copy of a program
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.
Save the current program
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.
Exit QBASIC platform.
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.
RUN and PRINT
|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.|
Program Screen and Output Screen
|Program Screen||Output 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
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:
PRINT "Season's Greeting" PRINT "Best Wishes for" PRINT "A Happy and Prosperous New Year" PRINT "From:" PRINT "Name: KnowledgeBoat"
Season's Greeting Best Wishes for A Happy and Prosperous New Year From: Name: KnowledgeBoat
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.
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
PERCENTAGE OF BOYS= 56 PERCENTAGE OF GIRLS= 44
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)
Cls Let B = 15 Let H = 10 Let A = 1 / 2 * B * H Print "AREA OF THE TRIANGLE= "; A; "SQ CM" End
AREA OF THE TRIANGLE= 75 SQ CM
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.
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
TOTAL SALE = Rs. 5800
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)
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
AREA = 616 SQ CM CIRCUMFERENCE = 88 CM
Write a program in QBASIC to find the value of the given expressions when a = 10, b = 5, c = 2.
- a2 +b3 +c4
- (a + b)2
- a2 + b2
- (a - b + c)2
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
ANSWER OF EXPRESSION 1= 241 ANSWER OF EXPRESSION 2= 225 ANSWER OF EXPRESSION 3= 125 ANSWER OF EXPRESSION 4= 49
In a class of 60 students, 90% are present. Write a program in QBASIC to calculate the number of students present and absent.
Cls Let T = 60 Let PRESENT = 90 / 100 * 60 Let ABSENT = T - PRESENT Print "STUDENTS PRESENT= "; PRESENT Print "STUDENTS ABSENT= "; ABSENT END
STUDENTS PRESENT= 54 STUDENTS ABSENT= 6
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.
Cls Let RATE = 47.6 Let COST = 5 * RATE Let PAID = 250 Let REFUND = PAID - COST Print "MONEY REFUNDED = Rs. "; REFUND END
MONEY REFUNDED = Rs. 12
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.
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
TOTAL MONEY TO BE PAID = Rs. 3750 REFUND = Rs. 250
'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.
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
AMOUNT TO BE PAID = Rs. 615