C++ Decision Statements Assignmentdoc

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

C++ Decision Statements Assignment

Student Name: _____________


PRE-FINAL
Assignment

Highlight the correct answer.

Email the answers: to georgewaperi.spc@gmail.com


(subject: Decision statement)

1. Convert the English expression below to C++ expression:

a) weight is greater than 100


b) a is not equal to 0
c) apple and orange are not the same
d) a is between 0 and 100 inclusive
e) answer is neither 'Y' nor 'y'

2. Which C++ logical expression correctly determines whether x and y are greater
than z?
a) (x && y > z )
b) (x > z ) && (y > z )
c) ( y > z ) && ( x > z )
d) all of the above
e) both b and c.

3. Evaluate the following C++ expression assuming i=5, j=10, k=15 and tell the
value (true/false).

i == k / j

4. Evaluate the following C++ expression assuming i=5 and k= 15 and tell the
value (true/false).

k%i<k/i

5. Evaluate the following C++ expression assuming x= true, y = false, z= true and
tell the value (true/false).

!z || (y || !x)

Compiled by GDW Page 1


C++ Decision Statements Assignment

6. If p is a Boolean variable, which of the following logical expressions always has


the value true?

a) p && p
b) p || p
c) p && !p
d) p || !p
e) both b and d.
7. If the int variables i, j, and k contain the values 4, 5, and 20, respectively, and
flag is false, what is the value of the following logical expression?

!( i <= (j * k) || !flag )
a) 9
b) 20
c) 29
d) true
e) false

8. If the int variables i, j, and k contain the values 4, 5, and 20, respectively, what is
the value of the following logical expression:

( i + j != k && i * j > k )
a) 9
b) 20
c) 29
d) true
e) false

9. What is the output of the following code fragment assuming x is 5?

x=6
if (x>=6)
cout<< "Yes";
cout<<"No";

a) Yes
b) No
c) Yes
No
d) No output; no error
e) No output; compile-time error
Compiled by GDW Page 2
C++ Decision Statements Assignment

10. What is the output of the following code fragment assuming num is 10?

num = 10
if (num == 20)
cout<<"apple";
cout<<"orange";

a) apple
b) orange
c) apple
orange
d) No output; no error
e) No output; compile-time error

11. After execution of the following code, what will be the value of y?

x = 10
y = 20
if (x <= 10)
x = x + 10
y = y + 20

a) 10
b) 20
c) 30
d) 40
e) 50

12. After execution of the following code, what will be the value of x?

x = 10
if (x != 10)
x = 100
cout<<x;

a) 10
b) 20
c) 100
d) 110
e) Compile-time error

Compiled by GDW Page 3

You might also like