0% found this document useful (0 votes)
108 views2 pages

C - Lab4 - Eng - Ruqaih Salman Final 2022

This document contains exercises on C++ logical and relational operators from Lab 4. The exercises include: 1) Marking statements using logical and relational operators as true or false. 2) Evaluating expressions using logical and relational operators. 3) Determining if expressions using variables and logical/relational operators evaluate to true or false. 4) Finding the output of statements using variables, logical/relational operators, and output statements. 5) Identifying which options are relational operators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views2 pages

C - Lab4 - Eng - Ruqaih Salman Final 2022

This document contains exercises on C++ logical and relational operators from Lab 4. The exercises include: 1) Marking statements using logical and relational operators as true or false. 2) Evaluating expressions using logical and relational operators. 3) Determining if expressions using variables and logical/relational operators evaluate to true or false. 4) Finding the output of statements using variables, logical/relational operators, and output statements. 5) Identifying which options are relational operators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C++

Lab4 Exercises

1. Mark the following statements as true or false.


.jnt jj.wlll 4 ->j7i jlLuil
a. The result of a logical expression cannot be assigned to an int variable.

‘ if (score>=60); if j p b! ‘ one-way selection


,IAJU jf OjUc.
b. In a one-way selection, if a semicolon is placed after the expression in an if statement as if
(score>=60);, the expression in the if statement is always true..

.else oif ojUc. JSJ jjSj ji 4^


c. Every if statement must have a corresponding else. />***"'*'

• jf ojluc. JJJUII
d. The expression in the if statement: always evaluates to true.

if (score = 30)

grade = 'A';

.'ch> = 'Z J 'ch <’A 13I false J) ('ch> = 'A' && ch <= 'Z) :j^li A
e. The expression: (ch >= 'A' && ch <= ’Z’) evaluates to false if either ch < ’A' or ch >= ’Z’.

f. Suppose the input is 5. The output of the code is: Num is zero
Num is zero .5

x 131 Jajis' ,(jj£j !(x > 0)


g- The expression !(x > 0) is true only if x is a negative number.
.Ajilaia(J<aljC- |!= | j | | ‘ ++ C

h. In C++, both ! and != are logical operators.


2. Evaluate the following expressions:

a. 5 + 6 == 3 + 7
b. 2 * 6 - 4 >= 9 - 1
c. ’U’ >= r
d. 'A' <= ’a'

t 6.28/3 <3-1.2
•false true Aulllll dijl£ I3I lx

Lab4 By Eng: Ruqaih Salman


[email protected] 1
C++
Lab4 Exercises

3. Suppose that x, y, and z are int variables, and x = 10, y = 15, and z = 20. Determine whether the following
expressions evaluate to true or false.
(
oiCuis 1311» .z = 20 j y = 15 j x = 10 ‘ int ^j'z j y j xJJS'
.false -true
a. !(x > 10)
b. x <= 5 || y < 15
C. (x != 5) && (y != z)
d. x >= z || (x + y >= z)
e. (x <= y - 2) && (y >= z) || (z - 2 != 20)

4. Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z = 7, and w = 1. What is the output of the following
statements?
oijLxli gli u ,w = 1 jz = 7jy = 4jx = 3 ub ‘ int ^WjZjyjXcJ
a. cout « ”x == y: ’’ « (x == y) « endl;
b. cout << "x != z: " << (x != z) << endl;
C. cout << "y == z - 3: ” << (y == z - 3) << endl;
d. cout << "!(z > w): ’’ << !(z > w) << endl;
e. cout << ”x + y < z: ” << (x + y < z) << endl;

5. Which of the following are relational operators?


^(relational operators) je. SjLe.
a. <
b. <=

d. :
e. <>

Lab4 By Eng: Ruqaih Salman


[email protected] 2

You might also like