Ch.2 Flashcards

1
Q

What is the value of x after the following statements?

x= 0

x += 3.0*4.0

x -= 2.0

A

10.0

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

Given the following code fragment and the input value of 2.0, what output is generated?

float tax;

float total;

cout ≤≤ “enter the cost of the item\n”;

cin >> total;

if ( total >= 3.0)

{

tax = 0.10;

cout ≤≤ total + (total * tax) ≤≤ endl;

}

else

{

cout ≤≤ total ≤≤ endl; }

A

2.0

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

Given the following code fragment, which of the following expressions is always true?

int x;

cin >> x;

A) if( x = 1)

B) if( x == 1)

C) if((x/3) > 1)

D) if( x < 3)

A

if( x = 1)

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

Given the following code fragment and the input value of 4.0, what output is generated?

float tax;

float total;

cout ≤≤ “enter the cost of the item\n”;

cin >> total;

if ( total >= 3.0)

{

tax = 0.10;

cout ≤≤ total + (total * tax) ≤≤ endl;

}

else

{

cout ≤≤ total ≤≤ endl;

}

A

4.4

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

What is the value of x after the following statements?

int x;

x = x + 30;

A

garbage

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

What is the value of x after the following statements?

int x, y, z;

y = 10;

z = 3;

x = y * z + 3;

A

33

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

Which of the following is a valid identifier?

A) three_com

B) 3_com

C) 3com

D) 3-com

E) dollar$

A

three_com

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

Executing one or more statements one or more times is known as

A

iteration

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

Another way to write the value 3452211903 is

A

3.452211903e09

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

Given the following code fragment, what is the final value of y?

int x, y;

x = -1;

y = 0;

while(x <= 3)

{

y += 2;

x += 1;

}

A

8

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

Which of the following statements is NOT legal?

A) char ch = ‘b’;

B) char ch = ‘0’;

C) char ch = “cc”;

D) char ch = 65;

A

char ch = “cc”;

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

What is the output of the following code fragment?

int x = 0;

while( x < 5)

cout ≤≤ x ≤≤ endl;

x ++;

cout ≤≤ x ≤≤ endl;

A

5

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

What is the output of the following code?

cout << “This is a \” << endl;

A

Nothing, it is a syntax error.

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

What is the correct way to write the condition y < x < z?

A) ( (y < x) && z)

B) (y < x < z)

C) ((y > x) ∣∣ (y < z))

D) ((y < x) && (x < z))

A

((y < x) && (x < z))

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

Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?

A) cin >> myFloat;

B) cin >> “myFloat”;

C) cin >> myFloat >> endl;

D) cin << myFloat;

A

cin >> myFloat;

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

What is the output of the following code?

float value;

value = 33.5;

cout << value << endl;

17
Q

What is the output of the following code?

float value;

value = 33.5;

cout ≤≤ “value” ≤≤ endl;

18
Q

What is the value of x after the following statements?

int x;

x = 0;

x = x + 30;

19
Q

Which of the following is not a valid identifer?

A) myInt

B) return

C) total3

D) myInteger

20
Q

What is the value of x after the following statements?

int x;

x = 15/4;

21
Q

What is the correct conditional statement to determine if x is between 19 and 99?

A

(x >19 && x < 99)

22
Q

What is the opposite of ( x < 20 && x > 12)?

A

(x >=20 || x <= 12)

23
Q

The stream that is used for input from the keyboard is

24
Q

≤≤ is called the ________ operator

25
Each time a loop body executes is known as an \_\_\_\_\_\_\_\_.
iteration
26
A loop that always executes the loop body at least once is known as a
do-while
27
When must we use braces to define the body of a conditional expression?
When there are multiple statements in the body.
28
\>\> is known as the ________ operator.
extraction
29
if-else statements that are inside other if-else statements are said to be
nested statements
30
int myValue; is called a
variable declaration
31
Variable names may begin with a number.
false
32
The integer 0 is considered true.
false
33
The body of a do-while loop always executes at least once.
true
34
The opposite of less than is greater than.
false
35
The body of a while loop may never execute
true
36
Every line in a program should have a comment.
false
37
If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false? if( x \< 2 && w \< y)
false
38
The opposite of (x \> 3 && x \< 10) is (x \< 3 && x \> 10)
false