{\rtf1\ansi\ansicpg1252\uc1 \deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman{\*\falt Thorndale};}{\f2\fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}
{\f28\froman\fcharset238\fprq2 Times New Roman CE{\*\falt Thorndale};}{\f29\froman\fcharset204\fprq2 Times New Roman Cyr{\*\falt Thorndale};}{\f31\froman\fcharset161\fprq2 Times New Roman Greek{\*\falt Thorndale};}
{\f32\froman\fcharset162\fprq2 Times New Roman Tur{\*\falt Thorndale};}{\f33\froman\fcharset177\fprq2 Times New Roman (Hebrew){\*\falt Thorndale};}{\f34\froman\fcharset178\fprq2 Times New Roman (Arabic){\*\falt Thorndale};}
{\f35\froman\fcharset186\fprq2 Times New Roman Baltic{\*\falt Thorndale};}{\f44\fmodern\fcharset238\fprq1 Courier New CE;}{\f45\fmodern\fcharset204\fprq1 Courier New Cyr;}{\f47\fmodern\fcharset161\fprq1 Courier New Greek;}
{\f48\fmodern\fcharset162\fprq1 Courier New Tur;}{\f49\fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f50\fmodern\fcharset178\fprq1 Courier New (Arabic);}{\f51\fmodern\fcharset186\fprq1 Courier New Baltic;}}{\colortbl;\red0\green0\blue0;
\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;
\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\nowidctlpar\faauto\rin0\lin0\itap0 \fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 \snext0 Normal;}{
\s1\ql \li0\ri0\sb240\sa60\keepn\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \b\fs28\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext15 heading 1;}{\s2\ql \li0\ri0\keepn\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 
\b\fs20\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 \sbasedon0 \snext0 heading 2;}{\*\cs10 \additive Default Paragraph Font;}{\s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 
\snext15 Default;}{\s16\ql \li0\ri0\sa120\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext16 Text body;}{\s17\ql \fi-283\li567\ri0\sa120\nowidctlpar
\tx567\aspalpha\faauto\rin0\lin567\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon16 \snext17 Hanging indent;}{\s18\ql \li0\ri0\sb240\sa120\keepn\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 
\fs28\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext16 Heading;}{\s19\ql \fi-360\li360\ri0\nowidctlpar\aspalpha\faauto\rin0\lin360\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext19 List;}{
\s20\ql \fi-360\li720\ri0\nowidctlpar\aspalpha\faauto\rin0\lin720\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext20 List 2;}{\s21\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 
\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext21 header;}{\s22\ql \li0\ri0\sa120\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon16 \snext22 Table Contents;}{
\s23\qc \li0\ri0\sa120\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \b\i\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon22 \snext23 Table Heading;}{\s24\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 
\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext24 Index;}{\s25\qc \li0\ri0\sb240\sa60\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \b\fs32\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext26 Title;}{
\s26\qc \li0\ri0\sa60\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext16 Subtitle;}{\s27\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 
\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext27 footer;}{\s28\ql \li0\ri0\sb120\sa120\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \i\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon15 \snext28 caption;}{\*
\cs29 \additive \cf1\lang0\langfe255\langfenp255 Numbering Symbols;}{\*\cs30 \additive \cf1\lang0\langfe255\langfenp255 WW-Default Paragraph Font;}{\*\cs31 \additive \cf1\lang0\langfe255\langfenp255 \sbasedon30 page number;}}{\info{\author CNRS}
{\operator CNRS}{\creatim\yr2003\mo8\dy29\hr23\min17}{\revtim\yr2003\mo11\dy21\hr12\min51}{\printim\yr2003\mo11\dy21\hr8\min51}{\version3}{\edmins1}{\nofpages2}{\nofwords983}{\nofchars5604}{\*\company CNRS-HSU}{\nofcharsws6882}{\vern8269}}
\margl1083\margr1083\margt1404\margb709 \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale100\nolnhtadjtbl 
\fet0\sectd \sbknone\linex0\headery709\sectdefaultcl {\header \pard\plain \s21\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 \fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\fs16 CS 131 - Homework #11\tab \tab p. }
{\field{\*\fldinst {\fs16 \\page}}{\fldrslt {\fs16\lang1024\langfe1024\noproof 2}}}{
\par }{\fs16 Fall 2003
\par }}{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}
{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl8
\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}\pard\plain \s15\qc \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 
\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b CS 131 - Intro to Computer Science I - Fall 2003
\par LAB #11 EXERCISE and Homework #11
\par 
\par lab #11 exercise due: Friday, November 21st, END of lab
\par }\pard \s15\qc \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b HW #11 due: Friday, December 5th, }{\b\ul beginning}{\b  of lab
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b 
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
You will be working in teams on Lab #11 Exercise Problem #1, and individually on the remainder of this assignment; you will turn in Lab #11 Exercise Problem #1 on-paper, and you will turn in the specified files by e-mail (one file per e-mail message, with
 the contents included in the text and not as an attachment, and with a copy CC'd to yourself as your receipt) as you have been doing since CS 131 HW #6.
\par 
\par NOTE: you are always welcome to write additional auxiliary functions for homework problems --- do be sure to e-mail me such functions if you do so, however! Just also let me know which problem(s) they are for.
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\ul 
\par LAB #11 EXERCISE}{ - to be completed by the end of lab}{\b\ul 
\par }{\b 
\par 1.\tab }{This is going to be something a little different --- it will be handed out on paper at the beginning of lab.}{\b 
\par 
\par 2.\tab }{Consider }{\b factorial}{ --- you know, how }{\b 8! }{= }{\b 1*2*3*4*5*6*7*8}{.}{\b 
\par 
\par \tab }{Obviously, you can do this with a loop (and, actually, there is a direct formula, which beats the loop in terms of efficiency!) However, I cannot think of another simple re
cursive function to have you write, and I want you to try your hand at one as a simple example.
\par 
\par \tab You can do this recursively? Sure, because you can note that:
\par }\pard \s15\ql \fi-420\li840\ri0\nowidctlpar\aspalpha\faauto\rin0\lin840\itap0 {\loch\af2 \tab \hich\af0\dbch\af0\loch\f2 0! == 1
\par \tab \hich\af0\dbch\af0\loch\f2 1! == 1
\par \tab \hich\af0\dbch\af0\loch\f2 2! == 2 * (1!)
\par \tab \hich\af0\dbch\af0\loch\f2 3! == 3 * (2!)
\par \tab \hich\af0\dbch\af0\loch\f2 4! == 4 * (3!)
\par \tab \hich\af0\dbch\af0\loch\f2 ...
\par \tab \hich\af0\dbch\af0\loch\f2 n! == n * ((n-1)!)
\par 
\par }{Or, that for n>1, the factorial of n is equal to (n times (the factorial of (n-1))). 
\par }{\b 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab Write a }{\b recursive }{function }{\b fac}{, in file }{\b fac.cpp}{, that takes an }{\b int}{ as its parameter and returns the factorial of that }{\b int}{
, using a recursive approach. (For our purposes, have fac return -1 if its argument is less than 0, and 1 if its argument is equal to 0.) Add your name to the}{\b  next:}{ list when you are done, and I'll look over your function and test it using }{\b 
expr_play2}{.
\par }{\b 
\par }{Once you have successfully completed the above, you have successfully completed today's lab exercise.
\par }{\b 
\par }{\b\ul HOMEWORK #11:
\par }{\b 
\par }\pard \s15\ql \fi-435\li435\ri0\nowidctlpar\aspalpha\faauto\rin0\lin435\itap0 {\b 1.\tab }{Remember good ol' }{\b Point3}{ from HW #6 and HW #7? It is a class that defines a point in 3-dimensional space, and it was used in 131 HW #6 and 131 HW #7.}{\b 

\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\b 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b \tab }{You can find updated and cleaned-
up versions of this code --- that now uses type double throughout instead of float, and includes a 0-argument constructor --- in ~st10/131hw11_public. You can copy all of its contents to your current working directory with the command:
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par \tab }{\f2 cp ~st10/131hw11_public/* .}{
\par }{\loch\af2 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab (Please note the period at the end of the above command --- it's a shorthand for your current working directory's name...)
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par }\pard \s15\ql \fi-435\li435\ri0\nowidctlpar\aspalpha\faauto\rin0\lin435\itap0 {\tab Well, Point3 is just begging for some overloaded operators, isn't it?
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab We had function point3Add before, didn't we? We should really overload + to add two Point3 instances, and
 overload == to compare two Point3 instances. So, do so, modifying Point3.h and Point3.cpp from 131h11_public appropriately, making both overloaded operators member functions of class Point3.  Modif
y  test_Point3.cpp to test both of these new operators (note that a cleaned-up version of this is in 131hw11_public, also.)
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par }\pard \s15\ql \fi-405\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab You need to practice writing a friend function, too. Let's modify the updated dist function to instead be a friend function of Poi
nt3 --- and, to show you that this really gives this function access to Point3's "private parts", change all references to Point3 accessors to instead be direct references to Point3 member variables. (Note that the updated dist.cpp in 131hw11_public uses 
unchangeable pass-by-reference parameters for its object parameters that are not to be changed, as we discussed in lecture.)
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par }\pard \s15\ql \fi-405\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab To test your new overloaded operators and friend function, you may add tests to the test_Point3.cpp in 131hw11_public
. Note that I've included test_point3Add.cpp and test_dist.cpp in 131hw11_public, also; you may freely borrow code from these. (I won't require that you bring over the dynamic tests, however; you may if you wish, but they are not required this time.)

\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par }\pard \s15\ql \fi-435\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {E-mail to me your resulting versions of Point3.h, Point3.cpp, test_Point3.cpp, and dist.cpp.
\par 
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b 2.\tab }{Someone makes an executive decision that }{\b MyNode }{instance A should be considered to be "less than" }{\b MyNode}{
 instance B if its A's quant is less than B's quant.}{\b 
\par 
\par \tab }{Add an overloaded operator < as a member function to MyNode.h and MyNode.cpp, and add appropriate tests to test_MyNode.cpp for the new operator. (How many tests should you have, at minimum?)
\par }{\b 
\par 3.\tab }{You need a little more practice developing }{\b friend functions}{, too. }{\b 
\par 
\par \tab }{Let's create a function stringMyNode as a friend function for MyNode, that returns a string depiction of a MyNode passed to it consisting of quant: }{\i val }{cost: $}{\i val}{
 --- that is, if MyNode aNode has quant of 5 and cost of 3.97, then the following statement would be true:
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par \tab stringMyNode( aNode ) == "quant: 5 cost: $3.97"
\par 
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab 
Modify MyNode.h appropriately to accomplish this and implement stringMyNode (in file stringMyNode.cpp) as such a friend function. To make sure that it is clear that a friend function can 
see the "private parts" of its associated class, do not use any accessors or mutators of class MyNode within stringMyNode's implementation. And, modify test_MyNode.cpp to test the new friend function. (I do hope you can see some existing code within test_
MyNode.cpp that might be adapted very nicely for this purpose...)
\par }{\b 
\par 4.\tab }{Write a }{\b recursive}{ function }{\b areAllMoreThan}{ (in file }{\b areAllMoreThan.cpp}{) that takes a pointer to a MyNode and an integer minQuant and returns }{\b true}{
 if all of the nodes linked from this pointer have quantities more than minQuant, and returns }{\b false}{ otherwise. (What if the list is empty? It should return }{\b true}{
 --- if there are no nodes, none have a quantity that is less than or equal to minQuant...)}{\b 
\par 
\par }{\tab (That is, areAllMoreThan answers the question: are all of the quantities in this list more than the minimum quantity specified?)
\par }{\b 
\par }{\tab To receive credit, your solution must be properly recursive --- it must have at least one base (non-recursive) case, it must ha
ve at least one case in which it calls itself, and it must do so to a "smaller" version of the problem, such that you must eventually reach one of the "base" cases.
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab You need to provide a main function in a file named test_allAreMoreThan.cpp, also,  that 
tests your function. Note that it would be acceptable to modify test_sumCostsR.cpp for this purpose --- that's what I did...
\par }{\b 
\par }\pard \s15\ql \fi-15\li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {Throughout the homework, IF you create any helper functions, be sure to e-mail them to me along with your other homework files.
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b 
\par }\pard \s15\ql \li-15\ri0\nowidctlpar\aspalpha\faauto\rin0\lin-15\itap0 {When you are done with this homework, you should have sent me at least }{\b 10}{ e-mail messages, one each for:
\par }\pard \s15\ql \fi-405\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab }{\b Point3.h}{, }{\b Point3.cpp}{, }{\b test_Point3.cpp}{, and }{\b dist.cpp}{,
\par }{\b \tab MyNode.h, MyNode.cpp, test_MyNode.cpp, and stringMyNode.cpp,
\par \tab allAreMoreThan.cpp, test_allAreMoreThan.cpp}{\b\fs24 
\par }}