CMPSC 201 - Ch. 4 Worksheet #1 Name -

 

1. Describe the output of this program:

#include <iostream>
using namespace std;

int main( )
{
    int a = 3;
    int b = 4;
    int c = 8;

    if (a < b)
          cout << "a is less than b" << endl;
    else
          cout << "b is less than a" << endl;
          cout << "b is less than c" << endl;

    return 0;
}

2. What is the value of the following possible if statement control expressions where a = 1, b = 2 & c = 3.
Write out the word TRUE or FALSE.

a/ (a < b || c = = 2)

b/ (a < b && c == 2)

c/ (3 < b + a)

d/ (b < 1 || a > 0 && b < 0)

e/ (!(b > a))

 

3. Write an if else statement that displays the message "finished" if the value of the variable numberOfTimes is greater than or equal to 5. Otherwise, the message "not finished" displays.




 

4. Evaluate the following expression where a = 5 and b = 6:

(a < b || (!b) && 6 >= b && (b < 3 || a))