Ch 16 Expressions and Operators
1. Fill in the blanks:
a. Different types of expressions supported by QBASIC are logical,
………. and …….
b. Different types of operators of QBASIC are ……., ........, .... and ....
c. 'OR' is a ................. operator.
d. '<>' is a........................operator.
e. '\, * are............. operators.
f. T$="RAM"+"SHYAM" is an example of……..
g.7>4 AND 7> 9 is an example of…....operation.
h. 5*5 is an example of.............operation.
i. PRINT 7>4 AND 8>3 produces output……
a. arithmetic and string b. Arithmetic, Relational, Logical and string c. logical d. relational e. arithmetic f. string operator g. relational h. arithemtic i. minus one (-1) i.e. TRUE
2. Write 'T' for the correct and 'F' for the false statements:
a. Combination of variables, operators and data is called an expression.
b. "+" symbol can be used for arithmetic as well as string operations.
c.A relational expression returns logical values.
d. "AND" operator returns "O", if all the given conditions are true.
e. "OR" operator returns "-1", if all the given conditions are true.
f. "NOT" operator reverses the result of a logical expression.
g. Mathematical operators can be disguised.
3. Evaluate the following expressions:
|
Expressions |
Outputs |
|
PRINT (5+7) - ( 4 +
2 ) |
6 |
|
PRINT ( 4 +2 ) ^ 2 /
(2+2) |
9 |
|
PRINT 3+2\2 +1 |
5 |
|
PRINT 3^2 MOD 3+1 |
1 |
|
PRINT (3+3) > 3
AND (9+1) > 12 AND 34 > 30 |
False(0) |
|
PRINT 3 MOD 2 = 1 OR
3 ^ 2 = 6 OR (8 * 2 ) = 30 |
True(-1) |
|
PRINT “AB” + “plus”
+ “XY” |
ABplusxy |
4.Answer the following questions:
a. Define an expression. Give an example.
A string or numeric constant, a variable or a combination of constants and
variables with operators is said to be expression. Example: Print 7*6+5
b. What are operators? Name the operators supported by QBASIC.
The symbols, which are used for mathematical calculations, logical and string operations are called operators. The operators supported by QBASIC are as follows:
- Arithmetic Operator
- Relational Operator
- Logical Operator
-String Operator
c. What is arithmetic expression? Give an example.
An expression, which contains values , variables and operators that return a single numeric value after operations, is called arithmetic expression. Example: Print 7*6+5
d. What is logical expression? Give an example.
A logical expression contains values and operations which are evaluated by QBASIC
and returns one of two logical values (true or false), which are also called
Boolean values. Example : Print 6>5
e. What are arithmetic operators? Write them in hierarchy.
Arithmetic or Mathematical operators are symbols, which are used for mathematical operations.
|
Arithmetic Operators |
Symbol |
Order of Priority |
|
Expressions inside
the brackets |
( ) |
First |
|
Exponentiation |
^ |
Second |
|
Negation (Minus sign
before value) |
- |
Third |
|
Multiplication and
Division |
* , / |
Fourth |
|
Integer Division |
\ |
Fifth |
|
Modulo Arithmetic |
MOD |
Sixth |
|
Addition &
Subtraction |
+ , - |
Seventh |
f. What is the use of logical operators? Explain with examples.
Logical operator is used to combine two or more logical or relational expressions and
return a single “ True ” or “ False ” value. QBASIC evaluates the expressions
and return “ -1 ” for a true and “ 0 ” for a false result.
g. Write truth table of "AND","OR" and "NOT"operators.
|
Truth Table of AND Operator |
|||
|
Condition |
Operator(AND) |
Condition |
Result |
|
FALSE (0) |
AND |
FALSE (0) |
FALSE (0) |
|
FALSE (0) |
AND |
TRUE (-1) |
FALSE (0) |
|
TRUE (-1) |
AND |
FALSE (0) |
FALSE (0) |
|
TRUE (-1) |
AND |
TRUE (-1) |
TRUE (-1) |
|
Truth Table of OR Operator |
|||
|
Condition |
Operator(OR) |
Condition |
Result |
|
FALSE (0) |
OR |
FALSE (0) |
FALSE (0) |
|
FALSE (0) |
OR |
TRUE (-1) |
TRUE (-1) |
|
TRUE (-1) |
OR |
FALSE (0) |
TRUE (-1) |
|
TRUE (-1) |
OR |
TRUE (-1) |
TRUE (-1) |
|
Truth
Table of NOT Operator |
|
|
Condition |
Result |
|
FALSE
(0) |
TRUE
(-1) |
|
TRUE
(-1) |
FALSE
(0) |
h. What is string concatenation? Give an example.
The act of combining strings is called string concatenation. For Example: PRINT “ AB ” + “ plus ” +
“ XY ” After String Concatenation: ABplusXY