got some noob c++ questions that hope someone can help me with

---The statement

while ( --counter >= 1 )
counter % 2 ? cout << "A" : cout << "B";

cannot be rewritten as:

a.  while ( --counter >= 1 )
   if ( counter % 2 )
      cout << "A";
   else
      cout << "B";.
b.  while ( counter >= 1 )
   if ( counter % 2 )
      cout << "A";
   else
      cout << "B";.
   --counter;
c.  while ( counter > 1 )
{
   --counter;

   if ( counter % 2 )
      cout << "A";
   else
      cout << "B";
}.

--- In a switch structure:
a. A break is required after each case.
b. Multiple actions do not need to be enclosed in braces.
c. A default case is required.
d. A break is required after the default case.

---Which of the following is false?
a. break and continue statements alter the flow of control.
b. continue statements skip the remaining statements in current iteration of the body of the loop in which they are embedded.
c. break statements exit from the loop in which they are embedded.
d. continue and break statements may be embedded within all C++ control statements.

.---Which of the following is false?
a. The effects of break and continue statements can be achieved by structured programming techniques.
b. break and continue statements can perform faster than their corresponding structured techniques.
c. Many programmers feel that break and continue violate structured programming.
d. You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.

thanks so much if can help,

Edited 3 Years Ago by Reverend Jim: Fixed formatting

How about you tell us what you think the answers are, and why the other choices are not correct, and we'll help you to understand any that you got wrong.

>> You should always try to write the fastest, smallest code possible before attempting to make it simple and correct

LOL...

How about you tell us what you think the answers are, and why the other choices are not correct, and we'll help you to understand any that you got wrong.

well for the first one i think, that is c....because the counter is is only > then 1 not >= 1

for number two i pretty sure it is b. mutilpe actions do not need to be enclosed in braces
-but am not 100 percent sure

for number 3 i think it is D: contune and break sattemets may be embedded within all c++ control statements
- i did process of elimantion but this still for some reason seems true to me


last one figured out

2 and 3 I believe you have right.

Number 1, on the other hand, takes a bit more analysis.

because the counter is is only > then 1 not >= 1

is looking at the problem wrong. You need to look at the whole problem.

Consider that counter is 2 coming into this bit. What value will it be when it gets to the code in the loop body, and how many times will the loop execute?

The initial sample decrents to 1, that passes the test, and 1 is evaluated. Loop condition then decrements to 0, test fails.

Trace through the alternatives - which give the same result and which one doesn't?

This article has been dead for over six months. Start a new discussion instead.