Test 2 Flashcards

1
Q

T or F? In an && operation, if the first operand is true the result is true.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

T or F? In an && operation, if the first operand is false the result is false.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

T or F? In an || operation, if the first operand is true the result is true.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

T or F? In an && operation, if both operands are true the result is true.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

T or F? In an || operation, if the first operand is false the result is false.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

T or F? In the evaluation of a logical expression, ! has priority over the && and || operations.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T or F? In the evaluation of a logical expression, parentheses have higher priority than logical operators.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

T or F? In the evaluation of a logical expression, arithmetic operators have higher priority than relational and logical operators.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

T or F? In the evaluation of a relational expression, relational operators have lower priority than logical operators.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. expr1 && expr2 || expr3

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. expr1 || expr2 && expr3

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. !expr2 && expr1 || expr4

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. !expr2 && (expr1 || expr3)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. !(expr1 && expr3) || expr1

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. a > b || b < c && d > b

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. !(a < b && c >d) || c < d

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. a <= b || !b < c && d > a

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. a > c && !d < c || (a > b && b

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. a >= c

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. b < d

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. a * b / 2 >= c + d / 5 + 2

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. a - b <= c + d - 4

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Write code for the following selection structure flowchart.

A

if(c1)

{

if(c2)

stmt3;

else

stmt2;

}

else

stmt1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

T/F? A relational expression assigns values to the operands, which make it true.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

T/F? When a relational operator has two characters such as >= or <= or != there should not be any spaces between them.

A

True

26
Q

T/F? In a relational expression with arithmetic operations, arithmetic operations are performed before the relaitonal operations.

A

True

27
Q

T/F? A relational expression may compare operands of any data type.

A

False

28
Q

T/F? Relational expressions are used to make logical choices in branching control structures.

A

True

29
Q

T/F? Relational expressions evaluate to 0 or 1.

A

True

30
Q

T/F? Relational expressions are also called conditions.

A

True

31
Q

var1(false) && var2(false)

A

False

32
Q

var1(false) && var2(true)

A

False

33
Q

var1(true) && var2(false)

A

False

34
Q

var1(true) && var2(true)

A

True

35
Q

var1(false) || var2(false)

A

False

36
Q

var1(false) || var2(true)

A

True

37
Q

var1(true) || var2(false)

A

True

38
Q

var1(true) || var2(true)

A

True

39
Q

Write the flowcharts and the code for the selection structure for the statement:

If x is greater than 25, add 20 to y.

A

if(x > 25)

y += 20;

40
Q

Write the flowcharts and the code for the selection structure for the statement:

If z is less than 15, add x to y.

A

if(z < 15)

y += x;

41
Q

Write the flowcharts and the code for the selection structure for the statement:

If n is 40, input values to l, m, and r.

A

if(n == 40)

scanf(“ %d %d %d %d”, &l, &m, &r)

42
Q

Write the flowcharts and the code for the selection structure for the statement:

If p is greater than or equal to r, increment r by 1.

A

if(p >= r)

r++;

43
Q

Write the segment of C code for the following:

If the compression stress is greater than 50,000, execute the following code.

printf(“stress = %8d\n”, stress);

printf(“This stress si greater 50000\n”);

A

if(stress > 50000)

{

printf(“stress = %8d\n”, stress);

}

44
Q

Write the segment of C code for the following:

If the number of cars sold per month by XYZ Motor Company is greater than 10,000, add a 5% bonus to employees’ monthly paychecks.

A

if(sales > 10000)

pay = pay + 0.05 * pay;

45
Q

Write the segment of C code for the following:

If the monthly sales of an employee exceeds $50,000, award a 10% bonus, if it exceeds $100,000 award a 15% bonus, if it exceeds $150,000, award a 20% bonus. If it is less than $10,000 there will be no bonus.

A

if(sales > 150000)

pay = pay + 0.20 * pay;

else

{

if(sales > 100000)

pay = pay + .15 * pay;

else

{

if (sales > 50000)

pay = pay + .10 * pay;

}

}

46
Q

T/F?

In a for loop the initialization, condition, and the increment are all in the header.

A

True

47
Q

T/F?

A for loop can count by 10.

A

True

48
Q

T/F?

In a for loop the index can be incremented or decremented.

A

True

49
Q

T/F?

for loops can be nested one inside the other.

A

True

50
Q

T/F?

When two for loops are nested, the loop variables myst be distinct.

A

True

51
Q

T/F?

In a for loop stement, more than one variable can be initialized, by using a comma (,) operator.

A

True

52
Q

What is the error?

for(i = 0; i < 10; i++);

A

should not be a semicolon at the end

53
Q

What is the error?

for(i = 10; i < 0; i++)

A

loop will not execute as termination condition is false

54
Q

What is the error?

for(i = 0; i < 10; i–)

A

loop will not terminate as termination condition is larger than initial value and index i is being decremented

55
Q

What is the error?

for(i = 0; i < 10, i++)

A

”,” where there should be a “,”

56
Q

What is the error?

for(i = 0; i < 10; i++)

for(i = 0; i < 10; i++)

A

nested inner and outer loops use the same index variable

57
Q

What is the error?

for(i = 0; i < 10; i++)

for(j = 0; j < 8; j++)

for(i = 0; i < 5; i ++)

A

nested inner and outer loops use the same index variable

58
Q

What is printed in the following simple for loops?

for(i = 0; i < 4; i++)

printf(“Inside for loop i = %d\n”, i);

printf(“Outside for loop i = %d\n”, i);

A

Inside for loop i = 0

Inside for loop i = 1

Inside for loop i = 2

Inside for loop i = 3

Outside for loop i = 4

59
Q

What is printed in the following simple for loops?

for(i = 5; i > 0; i-)

printf(“i = %d\n”, i);

printf(“Outside for loop i = %d\n”, i);

A

i = 5

i = 4

i = 3

i = 2

i = 1

Outside for loop i = 0

60
Q

What is printed in the following simple for loops?

for(i = 0, sum = 0; i < 4; i++)

{

sum += i;

printf(“Inside loop i = %d\n”, i);

}

printf(“Outside loop i = %d\n”, i);

printf(“Sum = %d\n”, sum);

A

Inside loop i = 0

Inside loop i = 1

Inside loop i = 2

Inside loop i = 3

Outside loop i = 4

Sum = 6