(IX) Ch-16 Expressions and Operators

1. Fill in the blanks: 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. State true or false: a. True b. True c. True d. False e. True f. True g. False 3. Evaluate the following expressions:
ExpressionsOutputs
PRINT (5+7) - ( 4 + 2 )6
PRINT ( 4 +2 ) ^ 2 / (2+2)9
PRINT 3+2\2 +15
PRINT 3^2 MOD 3+11
PRINT (3+3) > 3 AND (9+1) > 12 AND 34 > 30False(0)
PRINT 3 MOD 2 = 1 OR 3 ^ 2 = 6 OR (8 * 2 ) = 30True(-1)
PRINT “AB” + “plus” + “XY”ABplusxy
4. Answer the following questions: a. Define an expression. Give an example. Answer: 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. Answer: 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. Answer: 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. Answer: 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. Answer: 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 ArithmeticMODSixth
Addition & Subtraction+ , - Seventh
f. What is the use of logical operators? Explain with examples. Answer: 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
ConditionOperator(AND)ConditionResult
FALSE (0)ANDFALSE (0)FALSE (0)
FALSE (0)ANDTRUE (-1)FALSE (0)
TRUE (-1)ANDFALSE (0)FALSE (0)
TRUE (-1)ANDTRUE (-1)TRUE (-1)
Truth Table of OR Operator
ConditionOperator(OR)ConditionResult
FALSE (0)ORFALSE (0)FALSE (0)
FALSE (0)ORTRUE (-1)TRUE (-1)
TRUE (-1)ORFALSE (0)TRUE (-1)
TRUE (-1)ORTRUE (-1)TRUE (-1)
Truth Table of NOT Operator
ConditionResult
FALSE (0)TRUE (-1)
TRUE (-1)FALSE (0)
h. What is string concatenation? Give an example. Answer: The act of combining strings is called string concatenation. For Example: PRINT “ AB ” + “ plus ” + “ XY ” After String Concatenation: ABplusXY