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;

A

33.5

17
Q

What is the output of the following code?

float value;

value = 33.5;

cout ≤≤ “value” ≤≤ endl;

A

value

18
Q

What is the value of x after the following statements?

int x;

x = 0;

x = x + 30;

A

30

19
Q

Which of the following is not a valid identifer?

A) myInt

B) return

C) total3

D) myInteger

A

return

20
Q

What is the value of x after the following statements?

int x;

x = 15/4;

A

3.0

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

A

cin >>

24
Q

≤≤ is called the ________ operator

A

insertion

25
Q

Each time a loop body executes is known as an ________.

A

iteration

26
Q

A loop that always executes the loop body at least once is known as a

A

do-while

27
Q

When must we use braces to define the body of a conditional expression?

A

When there are multiple statements in the body.

28
Q

>> is known as the ________ operator.

A

extraction

29
Q

if-else statements that are inside other if-else statements are said to be

A

nested statements

30
Q

int myValue; is called a

A

variable declaration

31
Q

Variable names may begin with a number.

A

false

32
Q

The integer 0 is considered true.

A

false

33
Q

The body of a do-while loop always executes at least once.

A

true

34
Q

The opposite of less than is greater than.

A

false

35
Q

The body of a while loop may never execute

A

true

36
Q

Every line in a program should have a comment.

A

false

37
Q

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)

A

false

38
Q

The opposite of (x > 3 && x < 10) is (x < 3 && x > 10)

A

false