\documentstyle[html]{article}
\setlength{\textwidth}{6.6truein}
\setlength{\oddsidemargin}{-.2truein}
\setlength{\evensidemargin}{-.2truein}
\setlength{\textheight}{9truein}
\setlength{\topmargin}{-.4truein}
\setlength{\headsep}{.2truein}
\setlength{\footskip}{.3truein}
\begin{document}

\begin{center}
  {\Large \bf Structured Programming}\\
  \strut \\
  {Group:\ \hrulefill
   \ \ \ \ Captain:\ \hrulefill\hrulefill\hrulefill
   \ \ \ \ Recorder:\ \hrulefill\hrulefill\hrulefill
   \ \ \ \ Reflector:\ \hrulefill\hrulefill\hrulefill}
\end{center}

\begin{description}

\item[Motivation] \strut\hfill \\

  In order for a program to be adaptable to changing conditions, it
  must be able to take actions depending on whether certain conditions
  apply.

  In order for a program to do more work than it takes to write the
  program, it is essential that the program can repeat statements.

Understanding conditional execution and repeated statements will
make you a better programmer, hence a more desirable engineer.

\item[Objectives] \strut

  \begin{enumerate}
  \item Learn about \verb^if^ statements.
  \item Learn about logical expressions.
  \item Learn about \verb^for^ loops.
  \item Learn about \verb^while^ loops.
  \item Improve program neatness.
  \item Strengthen previous knowledge.
  \end{enumerate}

\item[Performance Criteria]  \strut

  \begin{enumerate}

  \item Success in modifying your previous program (first save it with
    a different name!) so that it first asks for the steel content of
    the part (instead of asking first for the cost of steel per unit
    weight.).  If there is no steel content, (in other words, if the
    user enters zero for the steel content of the part), the program
    {\em should not ask for the cost of steel}.  The same for the
    brass in the part. Remember, the intention is to reduce
    unnecessary work for the user.

    {\em Hint:} This program will require you to use \verb^if^
    statements.

    Have the program approved by the instructor before proceeding with
    the next program. (10\%)

  \item Success in modifying your previous program (first save it with
    a different name!) so that it provides a menu allowing the user to
    select between computing a part's material cost or quiting.  When
    the program is executed, the following menu appears:
\begin{verbatim}

            P    Compute the material cost of a part
            Q    Quit

    Choice: _
\end{verbatim}

    When the user chooses ``P'', the program next asks him for the
    weights of steel and brass of the part, and the cost of those
    materials.  (Just like the old program.) Then it prints out the
    material cost of the part.  Then it prints ``Goodbye'' and
    terminates.

    When the user selects ``Q'', the program prints ``Goodbye'' and
    terminates.

    When the user enters anything else than ``P'' or ``Q'', the
    program rings the bell, (won't work on the PC) and prints an error
    message.  Then it prints ``Goodbye'' and terminates.

    {\em Hint:} There are {\it three} possibilities for the user's
    choice from the menu: (1) the user selects 'P' or 'p'; (2) the
    user selects 'Q' or 'q'; and (3) the user selects any other
    (wrong) key.  Use an \verb^if^ \verb^(...)^ \verb^{...}^
    \verb^else^ \verb^if^ \verb^(...)^ \verb^{...}^ \verb^else^
    \verb^{...}^ construct to process these three possibilities
    differently.

    {\em Hint:} What are the conditions behind the \verb^if^ and the
    \verb^else if^?

    {\em Hint:} What are the statements you {\em only} want to do if
    the user enters 'P' or 'p'?  In which part of the \verb^if^
    \verb^(...)^ \verb^{...}^ \verb^else^ \verb^if^ \verb^(...)^
    \verb^{...}^ \verb^else^ \verb^{...}^ ladder do they go? What are
    the statements you {\em only} want to do if the user enters 'Q' or
    'q'? What are the statements you {\em only} want to do if the user
    enters a wrong key?  In which part of the \verb^if^ \verb^(...)^
    \verb^{...}^ \verb^else^ \verb^if^ \verb^(...)^ \verb^{...}^
    \verb^else^ \verb^{...}^ ladder do they go?  What are the
    statements you {\em always} want to do?  Where do they go?

    Have the program approved by the instructor before proceeding with
    the next program. (20\%)

  \item Success in modifying your previous program (first save it with
    a different name!) so that it keeps repeating the menu until the
    user selects 'Q'.  This allows the program to find the material
    cost of more than one part.  (User presses 'P', program computes a
    part; menu repeats; user presses 'P' again, program computes
    another part; etcetera.)  Note that the menu should also repeat if
    the user presses a wrong key, after printing the error message.

    {\em Hint:} Use a \verb^while (...)^ \verb^{...}^ loop to keep
    repeating things.  What would be the condition to keep looping
    around in the \verb^while^?

    {\em Hint:} To find the start of the while, ask yourself: what is the
    first thing I want to do repeatedly?

    {\em Hint:} To find the end of the while, ask yourself: from what
    location should I jump back up?

    Try to avoid asking more than once for the cost of steel or brass.
    Do that by initializing these variables to zero.  Then simply do
    not ask for them again if they are already nonzero.

    Have the program approved by the instructor before mailing.
    Only mail the final of the three programs. (20\%)

  \item Program neatness, including lots of clear and meaningful
    comments, clear and meaningful variable names, and clear
    indentations. (20\%)

  \item The knowledge demonstrated by your definitions of the vocabulary.
    (10\%)

  \item The depth of understanding demonstrated by your answers to the
    critical thinking questions. (20\%)

  \end{enumerate}

\item[Resources]  \strut

  \begin{enumerate}
  \item Your class notes.
  \item The textbook.
  \item The online help facilities of Windows and the C++ compiler.
  \end{enumerate}

\item[Plan]  \strut

  \begin{enumerate}
  \item Skim through the lessons ``Teaching Your Program to Make
    Decisions'' and ``Repeating One or More Statements'' of the book.
  \item Modify your program, compile and execute it.
  \item Write and test the final program, calling it \verb^menu.cpp^.
  \item E-mail the program to the instructor and the group members.
  \item See what vocabulary you can define.
  \item See what critical thinking questions you can answer.
  \item Take the test and submit it.
  \end{enumerate}

\item[Vocabulary]  \strut

  Select the best answer:

  \begin{enumerate}

  \item Compound statements.
    \begin{enumerate}
    \item Statements enclosed between curly brackets, taking the place
      of a single statement.
    \item Statements having a combination of artihmetic operations.
    \item Statements having a condition in them.
    \end{enumerate}

  \item What are \verb^if^ statements?
    \begin{enumerate}
    \item Statements that only execute certain substatements if a
      condition is true.
    \item Statements that are executed repeatedly.
    \end{enumerate}

  \item What are logical expressions?
    \begin{enumerate}
    \item Expressions that can have only the values \verb^true^
      and \verb^false^.
    \item Expressions that are written in the logical order.
    \end{enumerate}

  \item Logical expressions
    \begin{enumerate}
    \item are like arithmetic expressions, but they evaluate to
      \verb^true^ or \verb^false^ instead of to a number.
    \item cannot be used inside the parentheses of \verb^if^
      statements.
    \item cannot be used inside the parentheses of \verb^else if^
      statements.
    \item cannot be used inside the parentheses of \verb^for^
      statements.
    \item cannot be used inside the parentheses of \verb^while^
      statements.
    \end{enumerate}

  \item Logical operators
    \begin{enumerate}
    \item combine logical values like arithmetic operators (+, -,
      *, /) combine numbers.
    \item cannot be used inside the parentheses of \verb^if^
      statements.
    \item cannot be used inside the parentheses of \verb^else if^
      statements.
    \item cannot be used inside the parentheses of \verb^for^
      statements.
    \item cannot be used inside the parentheses of \verb^while^
      statements.
    \end{enumerate}

  \item What does C++ do if you give it a number where it wants a true
    or false value?
    \begin{enumerate}
    \item It refuses to compile.
    \item It crashes during execution.
    \item It stupidly takes any nonzero value to be ``true", and zero
      to be ``false".
    \end{enumerate}

  \item \verb^if/else^ statement.
    \begin{enumerate}
    \item A way to execute different statements or compound statements
      for a series of possible conditions.
    \item A way to repeat statements multiple times.
    \item A way to execute one statement or compound statement
      if a condition is true, another if it is false.
    \end{enumerate}

  \item \verb^if/else if/.../else^ ladder.
    \begin{enumerate}
    \item A way to execute different statements or compound statements
      for a series of possible conditions.
    \item A way to repeat statements multiple times.
    \item A way to execute one statement or compound statement
      if a condition is true, another if it is false.
    \end{enumerate}

  \item \verb^for^ loops.
    \begin{enumerate}
    \item Allow you to repeat a statement or compound statement
      using a counter.
    \item Allow you to repeat a statement or compound statement
      until a condition is no longer true.
    \item Allow you to do both, but you should really use a
      \verb^while^ loop in the second case.
    \end{enumerate}

  \item \verb^while^ loops.
    \begin{enumerate}
    \item Allow you to repeat a statement or compound statement
      using a counter.
    \item Allow you to repeat a statement or compound statement
      until a condition is no longer true.
    \item Allow you to do both, but you should really use a \verb^for^
      loop in the first case.
    \end{enumerate}

  \end{enumerate}

\item[Critical Thinking Questions]  \strut

  Select the best answer:

  \begin{enumerate}

  \item What is the difference in results from the left and right
    program parts:
\begin{verbatim}
    if (1 == 2)                     if (1 == 2) {
       cout << "Strange ";             cout << "Strange ";
       cout << "Mathematics";          cout << "Mathematics";}
\end{verbatim}
    \begin{enumerate}
    \item \verb^Strange Mathematics^ / \verb^Strange Mathematics^.
    \item \verb^Mathematics^ / No output.
    \item No output / No output.
    \end{enumerate}

  \item Which program part which is correct:
\begin{verbatim}
    if (1 == 2)                     if (1 == 2)
       cout << "Strange ";             cout << "Strange ";
                                       cout << "Mathematics";
    else                            else
       cout << "Plain ";               cout << "Plain ";
       cout << "Mathematics";          cout << "Mathematics";
\end{verbatim}
    \begin{enumerate}
    \item Left.
    \item Right.
    \item Both are correct, but left is shorter.
    \end{enumerate}

  \item For \verb^if ... if ... else ...^, does the \verb^else^ belong
    to the first or second \verb^if^? (The dots are the conditions and
    statements or compound statements)
    \begin{enumerate}
    \item First.
    \item Second.
    \item This is not allowed.
    \end{enumerate}

  \item
    How could you safely reformulate the previous construct so
    that confusion is not possible?
    \begin{enumerate}
    \item \verb^if ... else if ... else ...^
    \item \verb^if ... else ... if ... else ...^
    \item \verb^if ... { if ... else ...}^
    \end{enumerate}

  \item Which program part produces correct output for any \verb^a, b^:
\begin{verbatim}
    if (a<b || a==b)                 if (a<b && a==b)
       cout << "a is not > b";          cout << "a is not > b";
    else cout << "a > b";            else cout << "a > b";
\end{verbatim}
    \begin{enumerate}
    \item Left.
    \item Right.
    \item Both.
    \end{enumerate}

  \item The condition \verb^a>b^ is equivalent to:
    \begin{enumerate}
    \item \verb^b<a^.
    \item \verb^b<a || b==a^.
    \item Both.
    \end{enumerate}

  \item The condition \verb^a<=b^ is equivalent to:
    \begin{enumerate}
    \item \verb^b>a || b==a^
    \item \verb^! (b<=a)^
    \item Neither
    \end{enumerate}

  \item The condition \verb^a<b^ is equivalent to:
    \begin{enumerate}
    \item \verb^b>a || b==a^
    \item \verb^! (b<=a)^
    \item Both.
    \end{enumerate}

  \item
    The expression \verb^a<1 || a>3 && a!=0^ is equivalent to:
    \begin{enumerate}
    \item \verb^a<1 || (a>3 && a!=0)^
    \item \verb^(a<1 || a>3) && a!=0^
    \end{enumerate}

  \item So, is the previous expression true when \verb^a^ is zero?
    \begin{enumerate}
    \item Yes.
    \item No.
    \item It is too soon to tell.
    \end{enumerate}

  \item What does the next program part write:
\begin{verbatim}
  for (i=2; i<5; i++) cout << i;
\end{verbatim}
    \begin{enumerate}
    \item 1 2 3 4 5
    \item 2 3 4 5
    \item 2 3 4
    \item 2 4
    \item 2
    \item 5
    \item 6
    \item Nothing.
    \end{enumerate}

  \item What does the next program part write:
\begin{verbatim}
    for (i=2; i<5; i++); cout << i;
\end{verbatim}
    \begin{enumerate}
    \item 1 2 3 4 5
    \item 2 3 4 5
    \item 2 3 4
    \item 2 4
    \item 2
    \item 5
    \item 6
    \item Nothing.
    \end{enumerate}

  \item What does the next program part write:
\begin{verbatim}
    for (i=2; i<5; i=i+2) cout << i;
\end{verbatim}
    \begin{enumerate}
    \item 1 2 3 4 5
    \item 2 3 4 5
    \item 2 3 4
    \item 2 4
    \item 2
    \item 5
    \item 6
    \item Nothing.
    \end{enumerate}

  \item What does the next program part write:
\begin{verbatim}
    for (i=2; i<5; i=i+3) cout << i;
\end{verbatim}
    \begin{enumerate}
    \item 1 2 3 4 5
    \item 2 3 4 5
    \item 2 3 4
    \item 2 4
    \item 2
    \item 5
    \item 6
    \item Nothing.
    \end{enumerate}

  \item What does the next program part write:
\begin{verbatim}
    for (i=5; i<5; i=i+3) cout << i;
\end{verbatim}
    \begin{enumerate}
    \item 1 2 3 4 5
    \item 2 3 4 5
    \item 2 3 4
    \item 2 4
    \item 2
    \item 5
    \item 6
    \item Nothing.
    \end{enumerate}

  \item How many exclamation marks does the next program part write:
\begin{verbatim}
    for (i=2; i<5; i--) cout << "!";
\end{verbatim}
    \begin{enumerate}
    \item None.
    \item One.
    \item Infinitely many.
    \end{enumerate}

  \item What does the next program part write:
\begin{verbatim}
    for (i=2; i>0; i--) cout << i;
\end{verbatim}
    \begin{enumerate}
    \item 0 1 2
    \item 2 1 0
    \item 2 1
    \item 1 0
    \item 1
    \item Nothing.
    \end{enumerate}

  \item
    Can you leave the initialization, test, and increment away from
    a \verb^for^ loop?  If so, what would happen?
    \begin{enumerate}
    \item No, this will not compile.
    \item Yes, but the statement in the loop will not execute even once.
    \item Yes, but I will lose credit for poor coding.
    \end{enumerate}

  \item
    What is the result of \verb^i=0;while (i<2) cout << i++;^?
    \begin{enumerate}
    \item This will not compile.
    \item 0 1 2
    \item 0 1
    \item 1 2
    \item 1
    \end{enumerate}

  \item
    What is the result of \verb^while (1==1) cout << '!';^?
    \begin{enumerate}
    \item The \verb^cout^ statement is not executed even once.
    \item It writes a single exclamation mark.
    \item It keeps writing exclamation marks until you manage to kill
      off the process.
    \end{enumerate}

  \item
    What is the result of \verb^while (1) cout << '!';^?
    \begin{enumerate}
    \item This will not compile, since a condition, not a number, is
      needed within the parentheses of the \verb^while^.
    \item The \verb^cout^ statement is not executed even once.
    \item It writes a single exclamation mark.
    \item It keeps writing exclamation marks until you manage to kill
      off the process.
    \end{enumerate}

  \item
    What is the result of \verb^while (0) cout << '!';^?
    \begin{enumerate}
    \item This will not compile, since a condition, not a number, is
      needed within the parentheses of the \verb^while^.
    \item The \verb^cout^ statement is not executed even once.
    \item It writes a single exclamation mark.
    \item It keeps writing exclamation marks until you manage to kill
      of the process.
    \end{enumerate}

  \end{enumerate}

\item[Exercises]  \strut
  \begin{enumerate}
  \item What sort of possible improvements would you see for your
    program?
  \end{enumerate}

\item[Evaluation]  \strut

  \begin{enumerate}
  \item Give two strengths of your group.
  \item Indicate two areas for improvement.
  \item What two new insights did your group obtain?
  \item Give two strengths of the class so far.
  \item Indicate two areas for improvement of the class.
  \item What two new insights did you obtain about the class?
  \end{enumerate}

\end{description}
\end{document}
