Let's analyze the following statement assuming that y is 6.
if ( y = 7 )
cout << " y is 7. How lucky of you. ";
else
cout << "y is not 7. Sorry about that.";
What will be the result of this section of code.
a. cout << "y is not 7. Sorry about that.";
b. cout << " y is 7. How lucky of you. "; //will always execute regardless of the value of y
c. y=7 is an assignment and not a comparison will not compile
d. I was texting in class and have no absolutely no idea.
e. This will compile but completely skip both statements.
Answers for C++ Course using "Starting out with C++ : from control structures through objects" by Tony Gaddis. 7/8th ed. I used the Pearson myprogramminglab to complete the homework. Here are my solutions/answers for the exercises/labs so please use the test bank as a GUIDE if you're stuck. Let me know if you find a better solution to a problem or any of the programming challenges. Thanks in advance for your support! Send in missing programming challenges to cplusplus.answers@gmail.com
Chapter 4 Quiz Starting Out With C++ 012
Putting a semicolon after the if (expression) is a common mistake and will lead to a compiler error
if (x>y);
temp++;
a. false
b. today's compilers are smart enough and will remove the semi-colon
c. you'll get a warning message but the compiler knows what you mean
d. true
if (x>y);
temp++;
a. false
b. today's compilers are smart enough and will remove the semi-colon
c. you'll get a warning message but the compiler knows what you mean
d. true
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 011
In C++, you can only have one statement following a relational test?
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 010
if (expression)
statement;
else
statement;
Does the above work in C++?
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 009
How do you write an "if" statement in C++? Which sample below is the best
a.
if (x >y) then
{
tmp++;
}
b.
if ( x >y )
tmp++;
c.
if x>y
tmp++
else
tmp--;
d.
None of the above. They won't compile
a.
if (x >y) then
{
tmp++;
}
b.
if ( x >y )
tmp++;
c.
if x>y
tmp++
else
tmp--;
d.
None of the above. They won't compile
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 008
What is the value of the relation expression below, given that x is 5 and y is 1. z is a bool.
z = x < y;
a. true
b. false
c. 1
d. 0
e. None of the above, you can't assign result of expression, only test it
z = x < y;
a. true
b. false
c. 1
d. 0
e. None of the above, you can't assign result of expression, only test it
Exericse Number
Chapter 04,
Quiz
Subscribe to:
Posts (Atom)