\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 Object-Oriented 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 to handle more complex and larger programs, object oriented
  programming is needed.  It allows data to be protected and computer
  code to be reused better.  Much current code is written in an object
  setting, including C++, Windows, Java programs.

  Understanding object-oriented programming will allow you to
  understand modern computer codes better and thus make you a more
  well-rounded engineer.

\item[Objectives] \strut

  \begin{enumerate}
  \item Learn about arrays.
  \item Learn about objects.
  \item Learn about character strings.
  \item Improve program neatness.
  \item Strengthen previous knowledge.
  \end{enumerate}

\item[Performance Criteria]  \strut

  \begin{enumerate}

  \item Success in modifying your program so that an object replaces
    the \verb^part_process^ function.  In particular, create a class
    \verb^part_object^ with the following \verb^private^ data:
    \verb^steel_content^, \verb^brass_content^, and
    \verb^material_cost^.  The class should also have a \verb^public^
    function called \verb^process^ which does the same work as
    \verb^part_process^ did. Of course, \verb^process^ uses the
    private data of the object.

    In \verb^main^, create an object of type \verb^part_object^ called
    \verb^part^.  Use this object's \verb^process^ function to do the
    processing of a part when 'P' is selected from the menu. (25\%)

  \item Success in modifying your program so that the part object also
    includes the name of the part, \verb^part_name^, in its private
    data, and a function \verb^display^ in its public data.  Function
    \verb^display^ needs to print out the data of the part object on
    the screen.  Now in \verb^main^, {\em behind} the \verb^while^
    loop that processes the menu choices, print out: ``Thank you for
    using this program. The last part you processed was:''.  Then
    invoke \verb^part.display^ to display the latest part data.
    Finally write to the screen: ``Please come again.'' (25\%)

    {\em Hint:} To input the part's name, use the following code:
\begin{verbatim}
  cout << "Enter the part's name: " << flush;
  cin >> ws; cin.getline(part_name, sizeof(part_name));
\end{verbatim}

  \item The neatness, clarity, and simplicity of your implementation
    of your program. (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 course web page.
  \item The textbook, especially ``Storing Multiple Values in
    Arrays'', ``Understanding Character Strings'', and ``Starting
    with C++ Classes''.
  \item The online help facilities of Windows, Netscape or Internet
    Explorer, and the C++ compiler.
  \end{enumerate}

\item[Plan]  \strut

  \begin{enumerate}
  \item Skim through the lessons ``Storing Multiple Values in
    Arrays'', ``Understanding Character Strings'', and ``Starting with
    C++ Classes''.
  \item Do the programming tasks that are performance criteria.
  \item Define the vocabulary.
  \item Answer the critical thinking questions.
  \end{enumerate}

\item[Vocabulary]  \strut

  Select the best answer for all questions below:

  \begin{enumerate}

  \item Array
    \begin{enumerate}
    \item A data structure that allows a single storage location to
      store multiple values.
    \item A set of storage locations with a common name.
    \item A matrix.
    \end{enumerate}

  \item Index
    \begin{enumerate}
    \item A pointer to a memory location in an accessible part of the
      declared memory.
    \item An integer that selects a particular element of an array.
    \item A table of contents of a project.
    \end{enumerate}

  \item Character strings
    \begin{enumerate}
    \item An array of characters.
    \item A string of numbers.
    \item A string of letters and numbers.
    \end{enumerate}

  \item Object
    \begin{enumerate}
    \item A thing, such as a telephone.
    \item Code and data packaged together.
    \item An objection to code by the compiler.
    \end{enumerate}

  \item Classes.
    \begin{enumerate}
    \item The subdivision of C++ programming structures into groups of
      related constructs.
    \item The C++ implementation of objects.
    \item Courses you take at school.
    \end{enumerate}

  \item Member functions
    \begin{enumerate}
    \item Hmmmmmm....
    \item Functions that are member of a program
    \item Functions that belong to an object
    \end{enumerate}

  \item Private data.
    \begin{enumerate}
    \item A soldier's statistics
    \item A bathroom's statistics
    \item Data in an object that the object may use.
    \item Data in an object that the member functions of the object may use.
    \item Data in an object that \verb^main^ may use.
    \item Data in an object that \verb^main^ and the member functions
      of the object may use.
    \end{enumerate}

  \item Public data:
    \begin{enumerate}
    \item The government's statistics
    \item Data in an object that the object may use.
    \item Data in an object that the member functions of the object may use.
    \item Data in an object that \verb^main^ may use.
    \item Data in an object that \verb^main^ and the member functions
      of the object may use.
    \end{enumerate}

  \end{enumerate}

\item[Critical Thinking Questions]  \strut

  Select the best answer for all questions below:

  \begin{enumerate}

  \item \verb^float vector[3];^
    \begin{enumerate}
    \item declares storage for 3 floating point numbers.
    \item declares storage for 3 vectors.
    \item declares storage for 2 floating point numbers since the last
      one is NULL.
    \item declares storage for 2 vectors since the last one is NULL.
    \end{enumerate}

  \item \verb^int primes[3];^ \verb^primes[0]=1;^ \verb^primes[1]=2;^
    \verb^primes[2]=3;^ \verb^primes[3]=5;^
    \begin{enumerate}
    \item is legal.
    \item is illegal; \verb^primes[0]^ does not exist.
    \item is illegal; \verb^primes[3]^ does not exist.
    \item is illegal; only \verb^primes[3]^ exists.
    \item is illegal; an index is needed within the brackets, not an
      integer.
    \end{enumerate}

  \item To print out the primes from the previous question, use
    \begin{enumerate}
    \item \verb^cout << primes[3] << ' ';^
    \item \verb^if (i<=3) cout << primes[3] << ' ';^
    \item \verb^if (i<=3) cout << primes[i] << ' ';^
    \item \verb^for (i=0; i<3; i++) cout << primes[3] << ' ';^
    \item \verb^for (i=0; i<3; i++) cout << primes[i] << ' ';^
    \item \verb^i=0; while (i<3) cout << primes[++i] << ' ';^
    \item \verb^i=1; while (i<3) cout << primes[i++] << ' ';^
    \end{enumerate}

    The following program is intended to print out the primes ``1 2 3
    5 7 11 13 17 19 23'':
\begin{verbatim}
   #include <iostream.h>

   void print_primes(int array[], int size)
   {
       int i;
       for (i=0; i<size; i++) cout << array[i] << " ";
   }

   void main(void)
   {
       int primes[10] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23};
       print_primes(primes, 10);
   }
\end{verbatim}


  \item In the above program,
    \begin{enumerate}
    \item the name ``\verb^array^'' in \verb^print_primes^ must be
      replaced by ``\verb^primes^''.
    \item the name ``\verb^array^'' in \verb^print_primes^ could be
      replaced by ``\verb^primes^''.
    \item the name ``\verb^array^'' in \verb^print_primes^ cannot be
      replaced by ``\verb^primes^''.
    \end{enumerate}

  \item In the parameter list in the definition of \verb^print_primes^,
    \begin{enumerate}
    \item 10 must be inserted within \verb^[]^.
    \item 10 can be inserted within \verb^[]^.
    \item 10 cannot be inserted within \verb^[]^.
    \end{enumerate}

  \item In the definition of \verb^print_primes^ above, the loop
\begin{verbatim}
   for (i=0; i<size; i++) cout << array[i] << " ";
\end{verbatim}
    \begin{enumerate}
    \item should be
\begin{verbatim}
   for (i=1; i<=size; i++) cout << array[i-1] << " ";
\end{verbatim}
    \item should be
\begin{verbatim}
   i=0; while (i<size) cout << array[i++] << " ";
\end{verbatim}
    \item could be any of these
    \end{enumerate}

  \item In the declaration of the array of primes, 10 primes are stored.
    \begin{enumerate}
    \item That is OK.
    \item That is wrong; the last storage location must be NULL.
    \item That is OK; the first storage location is numbered \verb^[0]^;
      NULL is stored in location \verb^[10]^
    \item That is wrong; the first storage location is numbered \verb^[0]^,
      but the last location is \verb^[9]^; there is no place for NULL.
    \end{enumerate}

  \item The call \verb^print_primes(primes, ...^
    \begin{enumerate}
    \item is OK.
    \item should be \verb^print_primes(primes[], ...^
    \item should be \verb^print_primes(primes[0], ...^
    \item should be \verb^print_primes(primes[10], ...;^
    \end{enumerate}

  \item The 10 in \verb^print_primes(primes, 10);^
    \begin{enumerate}
    \item is OK.
    \item should be 9.
    \item should be 11.
    \end{enumerate}

  \item Which declaration is incorrect:
    \begin{enumerate}
    \item \verb^char the_great[3]="LvD";^
    \item \verb^char the_great[4]="LvD";^
    \item \verb^char the_great[5]="LvD";^
    \item \verb^char the_great[]="LvD";^
    \end{enumerate}

  \item For that example, \\
    \verb^for (i=0; the_great[i]; i++) cout << the_great[i] << ' ';^
    \begin{enumerate}
    \item will not compile: a condition is needed after the first
      semi-colon.
    \item prints out ``LvD''
    \item prints out ``L v D ''
    \end{enumerate}

  \item For that example, \verb^for (i=0; the_great[i]; i++);^
    \begin{enumerate}
    \item does nothing, the statement is empty.
    \item outputs ``LvD'' to the screen.
    \item counts the number of letters in ``LvD''.
    \item counts one more.
    \end{enumerate}

  \item \verb^for (digit='0', i=0; digit<='9'; digit++) string[i++]=digit';^
    \begin{enumerate}
    \item is wrong; you cannot increment characters.
    \item puts the characters '0' through '9' in the first ten positions of
      \verb^string^.
    \item Creates the character string ``0123456789''.
    \end{enumerate}

  \item Does \verb^name[0]='L'; name[1]='v'; name[2]='D'^ set the
    string \verb^name^ equal to ``LvD''?
    \begin{enumerate}
    \item No, you need to close the string ``LvD'' with
      \verb^name[3]=NULL^.
    \item Yes.  The computer will add NULL to the end of the string
      automatically.
    \end{enumerate}

    Consider the following class declaration:
\begin{verbatim}
    class student_object
    {
    private:
       char name[30];
       float GPA;
       void input_name(void);
       void input_GPA(void);
    public:
       void input_data(void);
       void cout_name(void) {cout << name;};
       float get_GPA(void) {return GPA;};
    }
\end{verbatim}

  \item Class \verb^student_object^
    \begin{enumerate}
    \item is illegal.  An object is a THING, not a person.
    \item is legal.
    \end{enumerate}

  \item \verb^void input_name();^
    \begin{enumerate}
    \item is illegal; a function cannot be within brackets.
    \item is the definition of a private member function of class
      \verb^student_object^.
    \item is the prototype of a private member function of class
      \verb^student_object^.  The function definition will be
      elsewhere.
    \end{enumerate}

  \item \verb^void cout_name();^
    \begin{enumerate}
    \item is illegal; a function cannot be within brackets.
    \item is the definition of a public member function of class
      \verb^student_object^.
    \item is the prototype of a public member function of class
      \verb^student_object^.  The function definition will be
      elsewhere.
    \end{enumerate}

  \item Variable \verb^GPA^ can be used
    \begin{enumerate}
    \item by function \verb^main^.
    \item by the member functions of \verb^student_object^
    \item by both
    \item by neither
    \end{enumerate}

  \item Function \verb^get_GPA^ can be used
    \begin{enumerate}
    \item by function \verb^main^.
    \item by the member functions of \verb^student_object^
    \item by both
    \item by neither
    \end{enumerate}

  \item Inside \verb^main^, the declaration \verb^student_object^
    \verb^student1,^ \verb^student2;^
    \begin{enumerate}
    \item is wrong.  You can declare things to be \verb^float^,
      \verb^int^, or \verb^char^, but not \verb^student_object^!
    \item creates storage for two floating point numbers.
    \item creates two students which must have the same name and GPA.
    \end{enumerate}

  \item Inside \verb^main^, \verb^cin >> student_object.GPA;^
    \begin{enumerate}
    \item is correct.
    \item is illegal; \verb^student_object^ is just a description:
      you first need to create an actual \verb^student_object^.
    \end{enumerate}

  \item  Inside \verb^main^, \verb^cin >> student1.GPA;^
    \begin{enumerate}
    \item is illegal: GPA is private.
    \item is correct: private data can be used inside \verb^main^.
    \item is correct: private data can be used inside \verb^main^
      since \verb^student_object^ \verb^student1^ was created by
      \verb^main^.
    \end{enumerate}

  \item Inside \verb^main^, to print out \verb^student1^'s name, use:
    \begin{enumerate}
    \item \verb^cout << student1.name;^
    \item \verb^cout << student1.name[];^
    \item \verb^student1.cout_name();^
    \item \verb^cout << student1.cout_name();^
    \end{enumerate}

  \item Inside \verb^main^, to print out \verb^student2^'s GPA, use:
    \begin{enumerate}
    \item \verb^cout << GPA;^
    \item \verb^cout << student2.GPA;^
    \item \verb^student2.get_GPA();^
    \item \verb^cout << student2.get_GPA();^
    \end{enumerate}

  \item Inside a function with prototype \verb^void^
    \verb^process_student^ \verb^(student_object^ \verb^student)^ the
    statement \verb^if (student.GPA > 2.) cout << ``Good student'';^
    \begin{enumerate}
    \item is legal.
    \item is illegal.
    \end{enumerate}

  \item Inside a function with prototype \verb^void^
    \verb^process_student^ \verb^(student_object^ \verb^student)^ the
    statement \verb^if (student.get_GPA > 2.) cout << ``Good student'';^
    \begin{enumerate}
    \item is legal.
    \item is illegal.
    \end{enumerate}

  \end{enumerate}

\item[Exercises]  \strut

  \begin{enumerate}

  \item Change the program so that the parts can include aluminum.
    Make all appropriate changes. {\em Hint:} Learn the search and cut
    and paste features of your editor.

  \item Change the program so that it includes an inventory (how much
    is in stock) of each part. The user should be able to display
    or change the inventory. {\em Hint:} Read the program carefully.

  \item In the menu, print out the values of \verb^aluminum_cost^ and
    \verb^steel_cost^ in dollars and cents, in the form
    \verb^$ddd.cc^.  But if they are still undefined (the same value
    they were initialized at), print ``Undefined''. Test your program
    with \$1.00, \$1.2345 (to print as \$1.23), \$10.00, \$12.3456,
    and \$0.0345.  {\em Hint:} Use the I/O manipulator
    \verb^setiosflags(ios::fixed)^ to set non-scientific notation.
    This one is used the same way as other I/O manipulators that
    are discussed in the book. It is turned off by
    \verb^resetiosflags(ios::fixed)^.

  \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.
  \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}
