INDO ENGLISH SCHOOL
FUNDAMENTALS OF QBASIC: A PROGRAMMING LANGUAGE
CLASS-6 COMPUTER CHAPTER NO : 9
QUESTIONS GIVEN AT THE END OF THE CHAPTER AND THEIR ANSWERS
Prepared By: Ms. SUBHASHREE ROUT
I. Write down the symbols of the special characters.
NAME SYMBOL NAME SYMBOL
Hash # Semi-colon ;
Forward slash / Dollar sign $
Asterisk * Double quotes “”
Colon : Exclamation !
II. Complete the table with reference to arithmetical operators as shown below:
Operation Operand Format used in QBASIC
Multiplication X M*N
Addition + M+N
Division / M/N
Exponent ^ M^N
Subtraction - M-N
III. Write down the names of the following relational operators
Relational Meaning Operator Meaning
Operator
> Greater than <> Not equal
<= Less than or equal < Less than
to
= Equal >= Greater than or
equal to
IV. Name the three types of logical operators and also mention how they are used in QBASIC.
Logical Operator Format used in QBASIC
AND (A=B) AND (B=C)
OR (A=B) OR (B=C)
NOT NOT (A=B)
V. Convert the following mathematical expressions into QBASIC expressions.
Mathematical Expressions QBASIC Expressions
4X5+15 4*5+15
a + bc a + b*c
(ab + cd) (a *b + c*d) /2
2
Pqr P * q* r
a2+b3+c4 a ^2 + b^ 3 + c^ 4
VI. Rewrite the given instructions in QBASIC:
The product of p, q and r is divided by 100 p*q*r/100
M raised to the power 2 plus n raised to the power 3 m^2 + n^3
The sum of a and b is divided by the product of a and b a+b / a*b
Subtract 5 from m and the result is multiplied by 10 (m-5) *10
A is greater than or equal to B A>= B
The sum of p and q is multiplied by 2 2* ( p+q )
The sum of A and B is less than the product of A and B ( A +B ) < ( A*B)
Twice the product of A plus thrice the product of B is greater
2*A +3*B>=50
than or equal to 50
SUBJECTIVE:
I. Write the following questions:
1. What is meant by the language QBASIC?
Ans: QBASIC (Quick Beginners All Purpose Symbolic Instruction Code) is also a programming
language intended to replace GWBASIC .This language is best suited for beginners. It is user
friendly as well as all types of tasks like general programs, graphics etc. can be performed using
this language.
2. What are the features of QBASIC language?
Ans:
It is user-friendly like GWBASIC.
The syntax of the statements is very simple.
It is a compiler-based language.
It does not require specifying line numbers.
It works with numeric as well as non-numeric data.
It is useful for mathematical, scientific and engineering purposes as well.
3. What is meant by character sets? Name the different types of character sets.
Ans:
ALPHABETS: These include all the alphabets in uppercase i. e A to Z and lowercase a to z.
NUMBER: These include all the numbers from 0 to 9. All the numeric digits and their
combinations are allowed from 0 to 9.
SPECIAL CHARACTERS: In addition to alphabets and numeric, some set of special
characters are also used in BASIC programming. Like question mark, semi-colon, comma,
colon, dollar sign, double quotes.
4. What is an operator? Name the different types of operators.
Ans: We may need to perform various arithmetical / logical operations in a program. This can be
done with the help of operators. Operators are the symbols which are used to perform different
arithmetical or logical operations.
Arithmetical Operators
Relational Operator
Logical Operator
5. Define the following with two examples of each.
a. Arithmetical Operator: Arithmetical operators are used to perform mathematical
calculations in a program. These operators work in the same sequence in which they are used
in mathematics ( i.e., BODMAS)
b. Relational Operators: A relational operator is used to determine the relationship between
two or more operands. The relational operator checks the conditions and returns the result
in either ‘true’ or ‘false’ for further processing. Examples: less than, greater than, equal, Not
equal.
c. Logical Operators: Logical operators are needed to compare two or more expressions. These
operators give result in True or False, depending upon the outcome of the logical expressions.
6. What are the rules to write mathematical operators?
Ans:
The variables A and B cannot be multiplied by writing AB. They should be written as A*B.
The variable A multiplied by 4 should be written as A*4 not as A4.
Zero raised to the power of any number is insignificant.
Division by zero is an invalid statement.
II. CONSTANTS AND VARIABLES
EXERCISES:
OBJECTIVE:
I. Fill in the blanks:
1. Alphanumeric variables always end with a dollar sign.
2. Numeric constants include only numbers.
3. The maximum length of a variable is 12.
4. Alphanumeric/string constants are always enclosed in double quotes.
5. Variables always begin with alphabet.
6. Comma is not allowed while writing numeric constants.
II. State whether the following statements are True/ False:
1. A45 is a valid numeric variable. False
2. A+B is not a valid alphanumeric variable. False
3. Special characters are used in variables. False
4. Numeric constants are stored in numeric variables. True
5. 0.5495 is a valid numeric constant. True
6. Decimals are not allowed in numeric constants. False
III. Match the following.
1. Numeric constants v. can take part in mathematical
Operations.
2. Alphanumeric variables represent iii. must begin with an alphabet
3. Alphanumeric constants ii. Are always enclosed in “ “
4. A variable iv. String variables
5. Alphanumeric variables are called i. Alphanumeric constants
IV. Name them:
1. Two types of variables
a. Numeric b. Alphanumeric
2. Two types of constants
a. Numeric b. Alphanumeric/ string
V. Correct the following expressions:
1. B$= WORLD CUP 2007 ------ B$= “WORLD CUP 2007”
2. “DELHI PUBLIC SCHOOL”= D$------ “DELHI PUBLIC SCHOOL”=D
3. $$A= “ARYA PUBLISHING COMPANY”------A$=“ARYA PUBLISHING COMPANY”
4. P$= (A +B)2 --------- P = (A + B)2
5. 4B$= “ NEW DELHI”-------B$= “ NEW DELHI”
6. A= 4P + 5Q---------A= 4 + 5
7. AVG= ( 2A + 3B +4C) / 3---------A= (2 + 3 + 4 ) / 3
8. A *B = AB + CD--------AB
VI. Write down the appropriate variables for the following:
1. B$= “Understanding Information Technology”
2. ABC$ = A *B*C
3. A$= “15th August 1947”
4. AB$= ½ * A + ¼ * B
5. A= 11.99
SUBJECTIVE:
I. Define the following terms:
1. Variables: In contrast to constants, variables change their values at the time of execution. A
variable may be a single character or a set of characters. There are two types: a. Numeric variables
b. alphanumeric variables.
2. Constants: Constants are data items, the values of which do not change at the time of execution of
the program. For example : 75, -91
3. Numeric variables: These are the variables which can store numbers or numeric values. They can
also store integer and real type numeric values.
4. Alphanumeric variables: These variables are used to store alphabets, words and special characters
or their combinations. The set of characters to be stored must be put within double quotes i. e.
“….”
5. Alphanumeric constants: Any set of characters can be called a string / alphanumeric constant. They
do not change their value at the time of execution of the program. A set of characters must be
enclosed within double quotes “……”
6. Numeric constants: Numeric constants are the constants comprising of the digits. They may be
accompanied by a negative sign (-) or a decimal point. These constants are used for all kinds of
mathematical operations.
II. Give two differences between:
1. Numeric constants and Alphanumeric constants
Numeric constants: Numeric constants are the constants comprising of the digits. They may be
accompanied by a negative sign (-) or a decimal point. These constants are used for all kinds of
mathematical operations.
Alphanumeric constants: Any set of characters can be called a string / alphanumeric constant. They do
not change their value at the time of execution of the program. A set of characters must be enclosed
within double quotes “……”
2. Numeric variables and Alphanumeric variables
Numeric variables: These are the variables which can store numbers or numeric values. They can
also store integer and real type numeric values.
Alphanumeric variables: These variables are used to store alphabets, words and special characters
or their combinations. The set of characters to be stored must be put within double quotes i. e.
“….”
III. COMMANDS AND STATEMENTS:
EXERCISES:
OBJECTIVE:
I. Fill in the blanks:
1. The full form of QBASIC is Quick Beginners All Purpose Symbolic Instruction Code.
2. LET statement is used to assign a value to a variable.
3. The term used to correct errors in a program is called debugging.
4. F5 function key is used to execute a program in QBASIC.
5. REM is a non-executable statement.
6. The maximum number of characters in the primary name of a QBASIC file is 8 character.
7. Using exit commands, you can quit QBASIC and return to the desktop.
8. The extension of BASIC program file is .BAS.
9. Statements are the set of instructions to a program.
10. Save as option is used to store a program in the secondary memory for the future use.
II. Corrects the errors:
CLEAR CLS
LET A=15 INPUT A =10
TAKE B=10 LET B= 45
P= (A +B) ^2 P= (A X B) / 5 + B
DISPLAY P PRINT P
END STOP
Ans: CLS Ans: CLS
LET A=15 LET A=10
LET B=10 LET B= 45
P = (A + B) ^2 P= (A X B) / 5 + B
PRINT P PRINT P
END END
OUTPUT= 625 OUTPUT= 9
SUBJECTIVE:
I. Explain the meaning of the following commands/statements with reference to QBASIC.
1. New program: It allows the user to clear the working memory for fresh storage of the next
program.
2. Open program: 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.
II. Write short notes on:
1. RUN: This command is used in QBASIC to execute any program or to see the output of the
program. This can be done by pressing F5, a function key.
2. CLS: CLS means to clear the content of the program and the output screen.
3. LET: 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.
4. REM: REM statement is used to write remarks about any program which basically shows the
purpose of a program. It is a non-executable statement.
5. PRINT: PRINT statement is used to display any data, value, or message on the screen. PRINT
statement may be used with or without a variable.
III. Write down all the steps to perform the following tasks in QBASIC.
1. Write a new program:
Step 1: Click ‘QBASIC ‘icon. The QBASIC window opens. Otherwise, select the path and open the
QBASIC window.
Press ‘ESC’ key to clear the contents of the screen.
Select the ‘File’ menu and click the option ‘New Program’.
The QBASIC screen will be ready to write the program.
2. Save a program:
Step 1: Click ‘File’ and select ‘Save As’ from the drop-down menu.
Step 2: The ‘Save As’ window appears on the screen. Select a directory/drive from the box.
Step 3: write the file name in the ‘File Name ‘box.
Step 4: Finally, Click ‘OK’.
3. Get the hard copy of a program:
Step 1: First save the program.
Step 2: Click print option from file menu or press Ctrl+p.
Step 3: now hard copy will come out through printer.
4. Save the current program:
Step 1: Click ‘File’ and select ‘Save’ from the drop-down menu.
Step 2: The ‘Save’ window appears on the screen. Select a directory/drive from the box.
Step 3: write the file name in the ‘File Name ‘box.
Step 4: Finally, Click ‘OK’.
5. Quit QBASIC platform:
Step 1: Click ‘File’ and select ‘Exit’ from the drop-down menu.
Step 2: Press ‘Enter’ key.
IV. Distinguish between:
1. RUN and PRINT
RUN: This command is used in QBASIC to execute any program or to see the output of the
program. This can be done by pressing F5, a function key.
PRINT: PRINT statement is used to display any data, value, or message on the screen. PRINT
statement may be used with or without a variable.
2. Program screen and Output screen
Program screen: A screen for writing the program.
Output Screen: An output screen for showing the result of the program after execution.
V. Unsolved Program on LET and PRINT statements:
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………………………………
Ans:
CLS
LET A$= “Season’s Greeting”
LET B$= “Best Wishes for”
LET C$= “A Happy and Prosperous New Year”
LET D$= “Rourkela”
LET E$= “SANIYA RANA”
PRINT “Season’s Greeting:”; A$
PRINT “Best Wishes for:”;B$
PRINT “A Happy and Prosperous New Year:”;C$
PRINT “From:”;D$
PRINT “Name:”;E$
END
2. There are 28 boys and 22 girls in your class. Write a program in QBASIC to fine the percentage of
boys and girls in the class.
Ans:
CLS
LET B=28
LET G=22
LET T=50
LET P1=B/T*100
LET P2=G/T*100
PRINT P1, P2
END
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.
Ans:
CLS
LET B=15cm
LET H=10cm
LET A= ½*B*H
PRINT “Area=”; A
END
4. A Salesman sold 14 chairs at the rate of 275/- each and 3 tables at the rate of 650/-. Write a
program in QBASIC to calculate the total sale.
Ans:
CLS
LET C= 14 *275
LET D=3*650
LET T=C+D
PRINT “Chair, Table =”; C, D
Print “Total sale =”; T
END
5. Write a Program in QBASIC to calculate the area and circumference of a circle of the radius 14 cm.
Ans:
CLS
LET r= 14 CM
LET A= 22/7 *r*r
LET C= 2*22/7*r
PRINT “Area=”; A
PRINT “Circumference=”; C
END
VI. Home Assignment
1. Write a program in QBASIC to find the value of the given expression when a=10, b=5, c=2.
a. a^2 +b^3+c^4
CLS
LET a=10
LET b=5
LET c= 2
LET D=a*a +b*b*b+c*c*c*c
PRINT D
END
b. ( a + b) ^2
CLS
LET a=10
LET b=5
LET c= 2
LET D= (a + b) ^2
PRINT D
END
c. a^2 + b^2
CLS
LET a=10
LET b=5
LET c= 2
LET D= a^2 + b^2
PRINT D
END
d. ( a –b +c )^2
CLS
LET a=10
LET b=5
LET c= 2
LET D= ( a –b +c )^2
PRINT D
END
2. In a class of 60 students, 90% are present. Write a program in QBASIC to calculate the number of
students present and absent.
Ans:
CLS
LET S= 60
LET P=90/100*60
LET A=60-P
PRINT “Present =”; P
PRINT “Absent =”; A
END
3. The rate of petrol is 47.60/- per litre. You paid 250/- to the pump attendant and asked for 5litres 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.
Ans:
CLS
LET C=47.60*5
LET R= 250-C
PRINT “Cost of petrol=”; C
PRINT “Refund money =”; R
END
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.
Ans:
CLS
LET H=950
LET E=1200
LET C=1600
LET T= H+E+C
LET R= 4000-T
PRINT “Harry Potter Books:”; H
PRINT “English Dictionary:”; E
PRINT “Encyclopedia:” ; C
PRINT “Total Cost:”; T
PRINT “Refund Money:”; R
END
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.
Ans:
CLS
LET B=660
LET C=160
LET T=B+C
LET D= T*25/100
LET A=T-D
PRINT “Leather Bag:”; B
PRINT “Belt:”; C
PRINT “Total:”; T
PRINT “Discount:”; D
PRINT “Amount:” ; A
END
IV.INPUT STATEMENT
EXERCISES
OBJECTIVE:
I. State whether the following statements are True/False:
1. INPUT N$ will accept a string constant. True
2. A question mark is displayed on the screen while executing an INPUT statement. True
3. INPUT A, B, C will accept only one numeric constant. False
4. A numeric variable with the INPUT statement responds to a string constant. False
5. A message may be given along with an INPUT statement to make the program
user-friendly. False
6. Numeric or alphanumeric constants should not be used along with the INPUT
Statement. False
7. INPUT N$, M will accept one alphanumeric constant and one numeric constant. True
8. INPUT statement accepts the data value during execution of the program. True
9. There is no difference between LET and INPUT statement in QBASIC. False
10. INPUT “Information Technology “is a valid statement. False
II. Complete the program:
a.
CLS CLS
PRINT “Enter two numbers” PRINT “Enter two numbers”
INPUT………………… INPUT “Enter A, B”;
……………=A+B S =A+B
…………..=A*B P =A*B
PRINT “The sum of two number=”; S PRINT “The sum of two number=”; S
Print “The product of two numbers=”; P Print “The product of two numbers=”;
…………… END
CLS CLS
b.
INPUT “Enter the name of article”; N$ INPUT “Enter the name of article”; N$
INPUT “Enter the number of articles”; P INPUT “Enter the number of articles”; P
INPUT “Enter the price of article”; ……… INPUT “Enter the price of article”; Q
M= P*Q M= P*Q
PRINT “Name of the article is”; ………. PRINT “Name of the article is”; N$
PRINT “Total cost of the articles is”; …… PRINT “Total cost of the articles is”; M
END END
c.
CLS CLS
PRINT “What do you want to buy?” PRINT “What do you want to buy?”
PRINT “Enter T$ for toy PRINT “Enter T$ for toy
INPUT……………. INPUT “Enter how many”; N
PRINT “How many”: T$; “Want to buy” PRINT “How many”: T$; “Want to buy”
INPUT………………… INPUT “Want to buy”; T$
PRINT “I want to buy”; N; T$ PRINT “I want to buy”; N; T$
…………… END
d.
CLS CLS
PRINT “What is the cost of this pen?” PRINT “What is the cost of this pen?”
INPUT………………….. INPUT “Enter the cost of pen”; P
PRINT “How many pens do you want?” PRINT “How many pens do you want?”
INPUT ……………. INPUT “Enter the no of pen”; Q
T=P*Q T=P*Q
PRINT “Total cost = “; ………….. PRINT “Total cost = “; T
…………………. END
SUBJECTIVE:
I. Short Answer Questions:
1. What is the purpose of using INPUT statement in a program?
Ans: with the use of INPUT statement, you can enter any data to a numeric variable or an alphanumeric
variable at the time of execution. In other words, you can make your program user-friendly.
2. How does LET statement differ from an INPUT statement?
Ans: with the use of INPUT statement, you can enter any data to a numeric variable or an alphanumeric
variable at the time of execution. In other words, you can make your program user-friendly, which
cannot be done by LET statement.
3. Write down the syntax of:
a. INPUT statement with a numeric variable
INPUT<Numeric variable>
Example: INPUT N
b. INPUT statement with an alphanumeric variable
INPUT < Alphanumeric variable>
Example: INPUT A$
II. BASIC Programming:
1. Write a program in QBASIC to make a name striker which includes your name, class, roll no.,
subject and school using INPUT statement. Display the output in the given format:
Name: …………………
Class: …………………..
Roll No: ………………
Subject: ……………..
School: ………………
Ans:
CLS
INPUT “Enter name”; N$
INPUT “Enter class”; CL$
INPUT “Enter roll number”; R
INPUT “Enter Subject”; S$
INPUT “Enter School”; SCH$
PRINT “Name:”; N$
PRINT “Class:”; CL$
PRINT “Roll No:”; R
PRINT “Subject:”; S$
PRINT “School:”; SCH$
END
2. Write a program in QBASIC format to accept the length of a rod in millimetres and express the
same in centimetres and metres.
Ans:
CLS
INPUT “Enter length of the rod in millimetres”; M
C=M/10
S= M/1000
PRINT “Length of the rod in centimetre=”; C
PRINT “Length of the rod in meter =”; S
END
3. Write a program in QBASIC format to print the total amount paid to the shopkeeper for purchasing
the following items:
Number of exercise books =10
Number of brown paper rolls=4
Ans:
CLS
INPUT “Enter the number of exercise book”; E
INPUT “Enter the number of brown paper rolls”; R
T=E+R
PRINT “Total=”; T
END
4. Write a program in QBASIC to find the value of the given expressions after taking a suitable value
of a and b from the console:
i. a^ 2 +b^2
Ans:
CLS
INPUT “Enter the value of a and b”; a, b
A= a^2 +b^2
PRINT “The value of A =”; A
END
OUTPUT: Enter a=2, b=2
A= 2^2 +2^2
A=8
ii. a+b
ab
CLS
INPUT “Enter the value of a and b”; a, b
A= a+b
B=ab
C=A/B
PRINT “Value of A =”; A
PRINT “Value of B=”; B
PRINT “Value of C=”; C
END
OUTPUT: Enter a=2, b=2
A= 4, B= 4, C= 1
5. You want to calculate the total runs made by Sachin Tendulkar only in terms of centuries and half-
centuries in test matches. Write a program in the QBASIC format taking the numbers of centuries
and half-centuries as input. Display the total runs made by Sachin in Centuries and half-centuries
separately.
Ans:
CLS
INPUT “Enter the numbers of Centuries”; C
INPUT “Enter the number of Half-Centuries”; H
T1=C*100
T2=H*50
PRINT “Total runs made by Sachin Tendulkar in centuries=”; T1
PRINT “Total runs made by Sachin Tendulkar in Half-centuries=”; T2
END
6. In an examination, 20% students failed in English and 30% failed in maths. Write a program in
QBASIC format to find the total number of students who failed in both the subjects taking the total
number of students in the class as input.
Ans:
CLS
INPUT N
E= (20/100)*N
M= (30/100)*N
T=E+M
PRINT “Total=”; T
END
7. Write a program in QBASIC format to find the value of‘s’ in the given equations, taking the suitable
value of ‘u’, ‘v’ and ‘a’ as input.
S= v^2-u^2
2a
Ans:
CLS
INPUT “Enter the value of”; u, v, a
S= v*v-u*u
D= 2*a
E= S/D
PRINT “The value of:” S
END
8. You purchased a Computer textbook and an Oxford dictionary. The shopkeeper allows 10%
discount on the textbook and 20% discount on the dictionary. Write a program in QBASIC format
to calculate the total discount and the amount to be paid to the shopkeeper, taking price of the
books as input.
Ans:
CLS
INPUT “Enter the price of the Computer”; P1
INPUT “Enter the price of the dictionary”; P2
D1=10/100*P1
D2=20/100*P2
T=D1+D2
A1=P1-D1
A2=P2-D2
A=A1+A2
PRINT “The Total discount=”; T
PRINT “The amount=” ; A
END