Determine the value true or false of each of the boolean


Homework

Determine the value, true or false, of each of the following Boolean expressions. Assume the following two declarations have been made:

int count = 0, limit = 10, x, y;

1. (count == 0) && (limit < 20)

2. count == 0 && limit < 20

3. (limit > 20) || (count < 5)

4. !(count == 12)

5. (count == 1) && (x < y)

6. (count < 10) || (x < y)

7. !( ((count < 10) || (x < y)) && (count >= 0) )

8. ((limit / count) > 7) || (limit < 20)

9. (limit < 20) || ((limit/count) > 7)

10. ((limit/count) > 7) && (limit < 0)

11. (limit < 0) && ((limit / count) > 7)

12. (5 && 7) + (16) (answer is true)

13.) Write an if-else statement that ouputs the word Solvent, decreases the value of savings by expenses, and sets the value of expenses to 0, provided the savings is at least as large as the expenses. If, however, savings is less than expenses, the if-else statement simply outputs the word Bankrupt and does not change the value of any variables. The variables, expenses and savings, are both float.

14.) Write an if-else statement that outputs the word Warning provided that the value of the variable temperature is greater than or equal to 100, or the value of the variable pressure is greater than or equal to 200, or both. Otherwise, the if-else statement outputs the word OK.

15.) If 0 is considered false and all other integer numbers are considered true in C++, what is the output of the following cout statements? You can assume that x is set up in the program as an integer and has a value.
a.) if (x=0)
cout << "0 is true" << endl;
else
cout << "0 is false" << endl;

b.) if (1)
cout << "1 is true" << endl;
else
cout << "1 is false" << endl;
c.) if (-1)
cout << "-1 is true" << endl;
else
cout << "-1 is false" << endl;

16.) What output will be displayed from the following code if int x = 2;
cout << "Start" << endl;
if (x <= 3)
if (x!= 0)
cout << "Hello from the second if" << endl;
else
cout << "Hello from the else" << endl;
cout << "End" << endl;
cout << "Start again" << endl;
if (x > 3)
if (x!= 0)
cout << "Hello from the second if" << endl;
else
cout << "hello from the else" << endl;
cout << "End Again" << endl;

17.) What will be displayed from the following code if extra = 2, if extra = -37, and if extra = 0?
if ( extra < 0)
cout << "Small" << endl;
else if (extra == 0)
cout << "Medium" << endl;
else
cout << "Large" << endl;

18.) What output will be displayed from the following code if x =1, if x=3, if x=2, and if x =4?
switch (x+1)
{
case 1: cout << "Roast Beef" << endl; break;
case 2: cout << "Roast Worms" << endl; break;
case 3: cout << "Chocolate ice cream" << endl;
case 4: cout << "Onion ice cream" << endl; break;
default: cout << "Bon Appetit" << endl;
}

19.) What output is produced by the following code?
a.) int x = 10;
while (x > 0)
{
cout << x << endl;
x = x - 3;
}
b.) int x = 10;
do
{
cout << x << endl;
x = x - 3;
} while (x > 0);

c.) int x = -42;
do
{
cout << x << endl;
x = x - 3;
} while (x > 0);

d.) int x = 10;
while (x > 0)
{
cout << x << endl;
x = x + 3;
}
e.) int count = 3;
while (count-- > 0)
cout << count << " ";

f. ) int count = 3;
while (--count > 0)
cout << count << " ";

g.) int n = 1;
do
{
cout << n<< " ";
} while (n++ <= 3);

h.) int n = 1;
do
{
cout << n << " ";
} while( ++n <= 3);

j.) for (int count = 1; count < 5; count ++)
cout << (2 * count) << " ";

k.) for (int n = 10; n > 0; n = n- 2)
{
cout << "Hello ";
cout << n << endl;
}

l.) for (float sample = 2; sample > 0; sample -= 0.5)
cout sample << " ";

20.) Rewrite the following loops as for loops:
a.) int i = 1;
while (i <= 10)
{
if (i < 5 && i != 2)
cout << ‘X';
i ++;
}

b.) int i = 1;
while (i <= 10)
{
cout << ‘X';
i += 3;
}

c.) int m = 100;
do
{
cout << ‘X';
m += 100;
} while (m < 1000);

21.) Code a C++ loop that will write the word "Hello" to the screen 10 times.

22.) Code a loop that will read in a list of even numbers (such as 2, -4, 8, 6) and compute the total of the numbers in the list. The list is ended with a sentinel value so you must decide what would be a good sentinel value and declare it as such before the loop.

23.) What will print as a result of the following nested loops?
for (int n = 1; n <= 3; n++)
for (int m = 5; m >= 1; m--)
cout << n << " times " << m << " = " << n*m << endl;

24.) Code two nested loops in C++ that will produce the following output:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

25.) Write a function prototype and a function definition for a function that takes one argument of type float and returns the character value ‘P' if the argument is positive and returns ‘N' if the argument is zero or negative.
26.) Write a function definition for a function called even that takes one argument of type int and returns a bool value. The function returns true if the argument is an even number. Otherwise, it returns false.

27.) Write a function definition for a function called in_order that takes three arguments of type int and returns true if the arguments are in ascending order. Otherwise it returns false. For example, in_order(1,2,3) and in_order(1,2,2) return true. And in_order(1,3,2) returns false.

28.) What is the output produced by the following code segment?
#include
char mystery (int,int); what is this called???
int main ()
{
cout << mystery(10,9) << "ow" << endl;
return 0;
}
char mystery (int first, int second)
{
if (first >= second)
return ‘W';
else
return ‘H';
}

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Determine the value true or false of each of the boolean
Reference No:- TGS01495407

Now Priced at $30 (50% Discount)

Recommended (95%)

Rated (4.7/5)