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;