Ch.2 Flashcards
What is the value of x after the following statements?
x= 0
x += 3.0*4.0
x -= 2.0
10.0
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; }
2.0
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)
if( x = 1)
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;
}
4.4
What is the value of x after the following statements?
int x;
x = x + 30;
garbage
What is the value of x after the following statements?
int x, y, z;
y = 10;
z = 3;
x = y * z + 3;
33
Which of the following is a valid identifier?
A) three_com
B) 3_com
C) 3com
D) 3-com
E) dollar$
three_com
Executing one or more statements one or more times is known as
iteration
Another way to write the value 3452211903 is
3.452211903e09
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;
}
8
Which of the following statements is NOT legal?
A) char ch = ‘b’;
B) char ch = ‘0’;
C) char ch = “cc”;
D) char ch = 65;
char ch = “cc”;
What is the output of the following code fragment?
int x = 0;
while( x < 5)
cout ≤≤ x ≤≤ endl;
x ++;
cout ≤≤ x ≤≤ endl;
5
What is the output of the following code?
cout << “This is a \” << endl;
Nothing, it is a syntax error.
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))
((y < x) && (x < z))
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;
cin >> myFloat;
What is the output of the following code?
float value;
value = 33.5;
cout << value << endl;
33.5
What is the output of the following code?
float value;
value = 33.5;
cout ≤≤ “value” ≤≤ endl;
value
What is the value of x after the following statements?
int x;
x = 0;
x = x + 30;
30
Which of the following is not a valid identifer?
A) myInt
B) return
C) total3
D) myInteger
return
What is the value of x after the following statements?
int x;
x = 15/4;
3.0
What is the correct conditional statement to determine if x is between 19 and 99?
(x >19 && x < 99)
What is the opposite of ( x < 20 && x > 12)?
(x >=20 || x <= 12)
The stream that is used for input from the keyboard is
cin >>
≤≤ is called the ________ operator
insertion
Each time a loop body executes is known as an ________.
iteration
A loop that always executes the loop body at least once is known as a
do-while
When must we use braces to define the body of a conditional expression?
When there are multiple statements in the body.
>> is known as the ________ operator.
extraction
if-else statements that are inside other if-else statements are said to be
nested statements
int myValue; is called a
variable declaration
Variable names may begin with a number.
false
The integer 0 is considered true.
false
The body of a do-while loop always executes at least once.
true
The opposite of less than is greater than.
false
The body of a while loop may never execute
true
Every line in a program should have a comment.
false
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
The opposite of (x > 3 && x < 10) is (x < 3 && x > 10)
false