KnowledgeBoat Logo
OPEN IN APP

Chapter 8

Developing Skills in QBASIC (Input & Conditional Statements)

Class 7 - APC Understanding Computer Studies



Choose the correct option

Question 1

Which of the following INPUT statements is valid to accept a number in QBASIC?

  1. Input 5N
  2. Input N
  3. Input N$
  4. Enter N

Answer

Input N

Reason — The syntax of INPUT statement to accept a number is Input <Numeric Variable>.

Question 2

Which of the following INPUT statements is incorrect to accept a string in QBASIC?

  1. Input NM$
  2. Input Name
  3. Input NM2$
  4. Input Name$

Answer

Input Name

Reason — Alphanumeric variable is specified by using a dollar sign ($) at the end of the variable name. Input Name is a statement to accept a number.

Question 3

Which of the following is not used as an operator in QBASIC?

  1. <>
  2. >=
  3. !=
  4. <=

Answer

!=

Reason — In QBasic, for not equal check, <> operator is used.

Question 4

Which of the following are not the decision-making statements in QBASIC?

  1. IF-THEN-ELSE
  2. ELSE-IF
  3. IF-THEN
  4. IF-ELSE

Answer

ELSE-IF

Reason — ELSE-IF is not a decision-making statement in QBASIC.

Question 5

Which of the following statements is not a QBASIC statement?

  1. Input
  2. Stop
  3. Let
  4. End

Answer

Stop

Reason — Input, Let and End are valid QBASIC statements.

State whether the following statements are True/False

Question 1

INPUT N$ will accept an alphanumeric constant.
True

Question 2

A question mark is displayed on the screen while executing an INPUT statement.
True

Question 3

INPUT A, B, C will accept only one numeric constant.
False

Question 4

INPUT N$, M will accept one alphanumeric constant and one numeric constant.
True

Question 5

INPUT statement accepts the data value during execution of the program.
True

Question 6

There is no difference between LET and INPUT statement in QBASIC.
False

Question 7

INPUT "Computer Studies" is a valid statement.
False

Fill in the blanks

Question 1

IF statement must accomplish with THEN statement in QBASIC programming.

Question 2

CLS command is used to clear the content of the Output screen.

Question 3

A function key to execute QBASIC programs is F5.

Question 4

END statement indicates that the program is over.

Question 5

Relational operators are used to compare the value of the variables.

Question 6

A command used to execute a QBASIC program is RUN.

Question 7

PRINT statement shows the output of a program during execution.

Case-Study Based Questions

Question 1

Aman has written a QBASIC program to accept two numbers and display the square of difference of the numbers (N1 - N2) when N1 > N2 otherwise, N2 - N1. The program is as shown below.

CLS
INPUT "Enter first number:"; N1$  : Line (a)
INPUT "Enter second number:"; 2N$ : Line (b)
IF N1>N2 THEN
D = N1 - N2
P=D^^2                            : Line (c)
PRINT "Value:", P
ELSE
D = N2 - N1
P=Dv2                             : Line (d)
PRINT "Value:", P
END

When he executed the above program, the system responded some errors in the statements marked with Line (a), Line (b), Line (c) and Line (d). Help Aman to eliminate these errors by writing the correct statements in Line (a), Line (b), Line (c), Line (d).

Answer

Line (a): INPUT "Enter first number:"; N1

Line (b): INPUT "Enter second number:"; N2

Line (c): P=D^2

Line (d): P=D^2

Short Answer Questions

Question 1

What is the purpose of using INPUT statement in a program?

Answer

INPUT statement is used to make the program user-friendly. With the use of INPUT statement, the user can enter any data to a variable at the time of execution.

When the INPUT command is used, the computer displays a question mark on the screen and asks the user to enter the data.

Question 2

What are the different types of conditional statements used in QBASIC programming? Name them.

Answer

There are two conditional statements used in QBASIC. They are as follows:

1. IF - THEN statement: This statement checks only the 'true' part of the program and comes to an end. It is used to check a condition and then perform any task based on the given condition.

Syntax:

IF <condition is true> THEN <Perform the task> 

Example:

IF A > 0 THEN PRINT "A IS POSITIVE"

2. IF - THEN with ELSE statement: This statement performs either of the two specified tasks based on a given condition whether it is 'true' or 'false'.

Syntax:

IF <condition is true> THEN <Task> ELSE <Another task>

Example:

LET A = 5
IF A >= 0 THEN PRINT "A IS POSITIVE" ELSE PRINT "A IS NEGATIVE" 

3. IF - ELSEIF statement: This statement allows us to check a secondary condition if the first condition is 'False'.

Syntax:

IF <condition 1 is true> THEN <task> 
ELSEIF <condition 2 is true> THEN <another task>
END IF

Example:

LET A=5
IF A >= 0 THEN PRINT "A IS POSITIVE" 
ELSEIF A < 0 THEN PRINT "A IS NEGATIVE"
END IF

Question 3

Name the different types of relational operators used in a conditional statement in QBASIC programming.

Answer

The different kinds of relational operators which are used in a conditional statement in QBASIC programming are:

  1. Less than ( < )
  2. More than ( > )
  3. Less than or equal to ( <= )
  4. Greater than or equal to ( >= )
  5. Not equal to ( <> )

Question 4

Write down the syntax of:

(a) INPUT statement with a numeric variable.

(b) INPUT statement with an alphanumeric variable.

(c) IF - THEN

(d) IF - THEN - ELSE

Answer

(a) The syntax of INPUT statement with a numeric variable is as follows:

INPUT <numeric variable>

(b) The syntax of INPUT statement with an alphanumeric variable is as follows:

INPUT <alphanumeric variable>

(c) The syntax of IF - THEN statement is as follows:

IF <condition is true> THEN <Perform the task> 

(d) The syntax of IF - THEN - ELSE statement is as follows:

IF <condition is true> THEN <Task> ELSE <Another task>

Question 5

Draw the construct of:

(a) IF-THEN-ELSE

(b) IF-THEN-ELSEIF with ELSE

Answer

(a) Construct of IF-THEN-ELSE is shown below:

...............
...............
IF <Condition> THEN
Task 1
ELSE
Task 2
END

(b) Construct of IF-THEN-ELSEIF with ELSE is shown below:

...............
...............
IF <Condition> THEN
...............
Task to do
ELSEIF <condition> THEN
...............
Task to do
...............
ELSE
PRINT <statement>
ENDIF
END

Solve the following programs

Question 1

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:

(a) a2 + b2

(b) (a+b) / ab

Answer

QBASIC Program

Cls
Input "Enter value of a "; a
Input "Enter value of b "; b
Let ans = a * a + b * b
Print "Value of expression 1 = "; ans
Let ans = (a + b) / (a * b)
Print "Value of expression 2 = "; ans
End

Output

Enter value of a ? 4
Enter value of b ? 5
Value of expression 1 = 41
Value of expression 2 = .45

Question 2

In an examination, 90% students passed in English and 80% passed in Maths. Write a program in QBASIC to find the total number of students who failed in both the subjects taking the total number of students in the class as input.

Answer

QBASIC Program

Cls
Input "Enter the total strength of the class "; onroll
Let e = 10 / 100 * onroll
Let m = 20 / 100 * onroll
Let total = e + m
Print "Number of students who failed in both the subjects ="; total
End

Output

Enter the total strength of the class ? 50
Number of students who failed in both the subjects = 15

Question 3

Write a program in QBASIC to find the value of 's' in the given equation, taking the suitable value of 'u' , 'v' and 'a' as input.

s = (v2 + u2) / 2a

Answer

QBASIC Program

Cls
Input "Enter the value of u"; u
Input "Enter the value of v"; v
Input "Enter the value of a"; a
Let s = (v * v + u * u) / (2 * a)
Print "Value of s = "; s
End

Output

Enter the value of u ? 20
Enter the value of v ? 30
Enter the value of a ? 5
Value of s = 130

Question 4

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 to calculate the total discount and the amount to be paid to the shopkeeper, taking price of the books as input.

Answer

QBASIC Program

Cls
Input "Enter price of Computer book "; cb
Input "Enter price of dictionary "; d
Let d1 = 10 / 100 * cb
Let d2 = 20 / 100 * d
Let discount = d1 + d2
Print "Total discount = Rs. "; discount
Let cost = cb + d - discount
Print "Amount to be paid = Rs. "; cost
End

Output

Enter price of Computer book ? 500
Enter price of dictionary ? 1000
Total discount = Rs. 250
Amount to be paid = Rs. 1250

Question 5

Write a program in QBASIC to accept three angles of a triangle. The program will check whether the triangle is possible or not and display the message accordingly.

Answer

QBASIC Program

Cls
Input "FIRST ANGLE"; A
Input "SECOND ANGLE"; B
Input "THRID ANGLE"; C
Let SUM = A + B + C
If SUM = 180 Then Print "TRIANGLE IS POSSIBLE" Else Print "TRIANGLE IS NOT POSSIBLE"
End

Output

FIRST ANGLE? 40
SECOND ANGLE? 80
THIRD ANGLE? 30
TRIANGLE IS NOT POSSIBLE

Question 6

Write a program in QBASIC to enter your name and the marks obtained in English (E), Maths (M), Physics (P), Chemistry (CH) and Biology (B). Calculate the average marks. If the average marks is 90% or more you will get 'Achievement Card' Otherwise, 'No Achievement Card'. Display the output with name along with the message.

Answer

QBASIC Program

Cls
Input "ENTER NAME"; N$
Input "ENTER MARKS IN ENGLISH"; E
Input "ENTER MARKS IN MATHS"; M
Input "ENTER MARKS IN PHYSICS"; P
Input "ENTER MARKS IN CHEMISTRY"; CH
Input "ENTER MARKS IN BIOLOGY"; B
Let S = E + M + P + CH + B
Let AVG = S / 5
Print "NAME - "; N$
If AVG >= 90 Then
    Print "Achievement Card"
ELSE
    Print "No Achievement Card"
ENDIF
End

Output

ENTER NAME? Ruchika
ENTER MARKS IN ENGLISH? 92 
ENTER MARKS IN MATHS? 98 
ENTER MARKS IN PHYSICS? 95 
ENTER MARKS IN CHEMISTRY? 93 
ENTER MARKS IN BIOLOGY? 96 
NAME - Ruchika
Achievement Card
PrevNext