Chapter 4 Quiz Starting Out With C++ 013

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.

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

Chapter 4 Quiz Starting Out With C++ 011

In C++, you can only have one statement following a relational test?

a. true
b. false

Chapter 4 Quiz Starting Out With C++ 010

if (expression)
  statement;
else
  statement;

Does the above work in C++?

a. true
b. false

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

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

Chapter 4 Quiz Starting Out With C++ 007

(bonus question) How does C++ handle true or false with regards to storing these values. Mark all that apply, if any

a. only a 1 is equal to true.
b. only 0 is considered true.
c.  a 0 is considered false.
d. anything other than 0 is considered true.
e. None of the above, they are stored as T or F.

Remember the lecture from Monday on making decisions and you'll do fine.

Chapter 4 Quiz Starting Out With C++ 006

In the following, what is the value of the expression given that the value of x is 5?

x == 5

a. x
b. 5
c. false
d. true

Chapter 4 Quiz Starting Out With C++ 005

What does the ! (exclamation symbol) mean in c++?

a. It tells the compiler to check this condition first
b. It means not or the opposite of what the comparison is.
c. It is a shortcut so you don't have to enter 'true' or a relational comparison operator
d. None of the above

Chapter 4 Quiz Starting Out With C++ 004

What is the difference between = and == in C++?

a. They are the same but the == makes it more visible to the programmer
b. == is used to assign a value to a variable and = is used to compare.
c. = is used to assign a value to a variable.
d. == is used for comparison and = is used to assign

Chapter 4 Quiz Starting Out With C++ 003

How do you write "greater than or equal to" test in c++?

a. gte
b. > or =
c. >=
d. > && =