{\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\mo10\dy2\hr1\min38}{\printim\yr2003\mo10\dy1\hr12\min44}{\version2}{\edmins1}{\nofpages4}{\nofwords1324}{\nofchars7549}{\*\company CNRS-HSU}{\nofcharsws9270}{\vern8269}}
\margl1440\margr1440\margt1400\margb720 \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale75\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 #5\tab \tab p. }
{\field{\*\fldinst {\fs16 \\page}}{\fldrslt {\fs16\lang1024\langfe1024\noproof 1}}}{
\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 Homework #5
\par DUE: Friday, October 10th, }{\b\ul Beginning}{\b  of Lab
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {
\par You are to work individually on this assignment.
\par 
\par You are }{\b not}{ required to use funct_play1, funct_play2, or expr_play2 for this assignment (although you are always welcome to, if you wish).
\par 
\par That means, you need to actually }{\b e-mail}{ to me the files that you create for this homework! Here is how we will accomplish this, for this class.
\par 
\par }{\b CS 131 Procedure for Turning in a Homework File by E-mail:
\par }\pard \s15\ql \fi-405\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {*\tab DO NOT turn in any homework files as attachments! Their text must be inserted within the e-mail message, as described here.
\par 
\par *\tab Say that you wish to turn in }{\b myHomeworkFile.cpp}{, currently residing on }{\b cs-server}{.
\par }\pard \s15\ql \fi-405\li825\ri0\nowidctlpar\aspalpha\faauto\rin0\lin825\itap0 {*\tab }{\b OPTION 1: (many thanks to James Hughes!)}{
\par }{\b \tab }{\b\f2 cat }{\i\f2 file}{\b\f2 .cpp | mail -s "}{\i\f2 file}{\b\f2 .cpp" st10@humboldt.edu -c }{\i\f2 your_email_addr}{\b 
\par }{
\par 
\par *\tab }{\b OPTION 2:}{
\par *\tab }{\b FIRST: to SAFELY transfer the file to axe.humboldt.edu:}{
\par }\pard \s15\ql \fi-405\li1260\ri0\nowidctlpar\aspalpha\faauto\rin0\lin1260\itap0 {*\tab type:
\par \tab }{\f2 sftp axe.humboldt.edu}{
\par }{\loch\af2 
\par }{*\tab You should be asked for your password }{\b on axe}{. (That's the same as your WebMail password...) Type it in, type enter key. If all is well, you should now see a }{\b sftp>}{ prompt --- you are now }{\b within}{
 the secure file-transfer protocol (sftp) program.
\par 
\par *\tab at the }{\b sftp> }{prompt, type:
\par \tab }{\f2 put myHomeworkFile.cpp}{
\par }{\loch\af2 
\par \tab }{...to send a copy of }{\b myHomeworkFile.cpp }{to axe. A message should appear saying that it is Uploading that file.}{\loch\af2 
\par }{
\par *\tab at the }{\b sftp>}{ prompt, type:
\par \tab }{\f2 quit}{
\par }{\loch\af2 
\par \tab }{...to leave the }{\b sftp}{ program, and return to regular operation on cs-server.}{\loch\af2 
\par }{
\par }\pard \s15\ql \fi-405\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {*\tab }{\b SECOND: to SAFELY mail the program AS REQUIRED to me:}{
\par }\pard \s15\ql \fi-405\li1260\ri0\nowidctlpar\aspalpha\faauto\rin0\lin1260\itap0 {*\tab open up a telnet or ssh (secure shell) session on }{\b axe.humboldt.edu}{.
\par 
\par *\tab type:
\par \tab }{\f2 pine st10}{
\par }{\loch\af2 
\par }{*\tab you are now in the }{\b pine}{ e-mail program. It should look pretty familiar, since it uses }{\b pico}{!
\par 
\par *\tab at }{\b CC:}{ , you should type }{\b your }{preferred e-mail address. }{\b 
It is important that you ALWAYS CC: to yourself a copy of ANYTHING that you send to me --- that is your "receipt" that it was sent, and I will ask you for this if there are any e-mail problems. If an 
e-mail message is lost, your CC'd copy will be accepted as having been turned in at the time of that CC'd message. Without it, you will NOT receive credit for the file within that message.}{
\par }{\b 
\par }{*\tab Using the arrow keys, move down to the }{\b Subject: }{line. At }{\b Subject:}{, you should type the }{\b name of the file}{ being turned in. So, here, you'd type:
\par \tab Subject : }{\b\f2 myHomeworkFile.cpp}{
\par }{\b\loch\af2 
\par }{*\tab Using the arrow keys again, move so that you are one line }{\b under}{ the line that says  }{\b ----- Message Text -----}{. This is called the, ah, message area.
\par 
\par \tab See how there is a command mentioned at the bottom, }{\b ^R Read File}{? That's what we are going to use now.
\par 
\par \tab Type the }{\b control key}{ and }{\b r}{ at the }{\b same}{ time. Near the bottom of your window, you'll now see:
\par 
\par \tab }{\b\f2 File to insert from home directory:}{
\par }{\b\loch\af2 
\par \tab }{Here, you will type the name of the file that you just sftp'd over from cs-server:}{\b\loch\af2 
\par }{\tab }{\f2 File to insert from home directory: }{\b\f2 myHomeworkFile.cpp}{
\par }{\loch\af2 \tab }{...and type Enter.}{\loch\af2 
\par }{
\par \tab Your file should be inserted, and you'll see a message near the bottom of the window saying }{\b Inserted XX lines}{.
\par 
\par *\tab Type the }{\b control key}{ and }{\b x }{at the }{\b same}{ time to }{\b send}{ your file to me. Near the bottom of the window, you will see:
\par \tab }{\f2 Send message?}{
\par }{\loch\af2 
\par \tab }{You should type }{\b y}{ in answer to this, to say, yes, send this message.}{\loch\af2 
\par }{
\par *\tab Message should be sent, you should shortly receive your CC'd copy, I should shortly receive your message, and all is well --- that homework file has been turned in! 8-)
\par 
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\b Homework Problems
\par }{
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {Consider the function }{\b workOut}{ from Homework #4. (Remember, a solution for it can be found on the course Blackboard site, under }{\b Some Solutions}{
, if you have misplaced yours or if you fear it wasn't completely correct.) Make sure that you have copies of }{\b workOut.h}{ and }{\b workOut.cpp}{ in your current directory as you work on the problems below. (You should have a }{\b workOut.h}{
 created by }{\b funct_play2}{.)
\par 
\par }{\b 1.\tab }{A }{\b count-controlled loop}{ is a loop that is controlled by a }{\b counter}{ so that it repeats a certain desired number of times. You can see an example of a count-controlled loop in the posted example }{\b countEx1.cpp}{.}{\b 
\par }{
\par \tab Write a }{\b main }{function in a file named }{\b counted1.cpp}{ that uses a classic-style }{\b count-controlled loop}{ to call }{\b workOut}{ 16 times, with the arguments }{\b 0}{ through }{\b 15}{. Note, then, that  we could say that }{\b 
program counted1}{ consists of the function }{\b main}{ within }{\b counted1.cpp}{ and the function }{\b workOut}{ (presumably within a file }{\b workOut.cpp}{).}{\b 
\par }{
\par \tab Before the }{\b first}{ call of }{\b workOut}{, write a statement or statements that will cause the following two lines to be printed to the screen:
\par \tab }{\b\f2 This is counted1 by <put your name here>}{
\par }{\b\loch\af2 \tab \hich\af0\dbch\af0\loch\f2 ----------------------------------------
\par }{\loch\af2 
\par }{\tab Each time your main function calls }{\b workOut}{, it should print to the screen a message (on its own line) that says:
\par \tab }{\b\f2 workOut(}{\i arg}{\b\f2 ) returns }{\i val_returned_by_that_workout_call}{
\par }{\i 
\par \tab }{After compiling this, testing it, and correcting it until it works properly, mail me a copy of your resulting }{\b counted1.cpp}{ }{\i as described above}{.}{\i 
\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 {\b 2.\tab }{#1 was practice writing a }{\b count-controlled loop}{ --- now, let's practice using a }{\b snetinel-controlled loop}{. }{\b 
\par }{
\par \tab A }{\b sentinel-controlled loop}{ repeats until the user enters a special }{\i non-data}{ }{\b sentinel}{ value, a value which signals that it is time to repeating. You can see an example of a sentinel-controlled loop in the posted example }{\b 
sentinelEx1.cpp}{.
\par 
\par \tab Write a }{\b main}{ function in a file named }{\b sentinel1.cpp}{(that's sentinel-one...) that uses a classic-style }{\b sentinel-controlled loop}{ to call }{\b workOut}{ until the user enters a number of slices of pizza of }{\b -3}{. 
\par 
\par \tab Before the }{\b first}{ request of a pizza-slice quantity, write a statement or statements that will cause the following two lines to be printed to the screen:
\par \tab }{\b\f2 This is sentinel1 by <put your name here>}{
\par }{\b\loch\af2 \tab \hich\af0\dbch\af0\loch\f2 -----------------------------------------
\par 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab Each time your main function calls }{\b workOut}{, it should print to the screen a message (on its own line) that says:
\par \tab }{\b\f2 workOut(}{\i arg}{\b\f2 ) returns }{\i val_returned_by_that_workout_call}{
\par }{\i 
\par \tab }{NOTE that }{\b workOut }{should NOT be called with the }{\b sentinel}{ value of }{\b -3}{ pizza slices --- AND you should not need an }{\b if-statement}{ within your loop to accomplish this. I expect you to practice the "classic" sentinel
 pattern discussed in lecture.}{\i 
\par }{
\par \tab After compiling this, testing it, and correcting it until it works properly, mail me a copy of your resulting }{\b sentinel1.cpp}{ }{\i as described above}{.}{\i 
\par }\pard \s15\ql \fi-435\li435\ri0\nowidctlpar\aspalpha\faauto\rin0\lin435\itap0 {
\par }{\b 3.\tab }{Of course, not all loops are neither classic count-controlled loops nor cla
ssic sentinel-controlled loops --- those are simply so common that all programmers need to be comfortable with them. Some are combinations or variations on those, or just different.}{\b 
\par }{
\par \tab Let's say we'd like a }{\b main}{ within a file }{\b testAll4.cpp}{. This main should  }{\b first}{ print a welcoming message to the screen, looking like this:
\par 
\par \tab }{\f2 This is testAll4 by <put your name here>}{
\par }{\loch\af2 \tab \hich\af0\dbch\af0\loch\f2 ----------------------------------------
\par 
\par \tab }{Then, it should  print a simple menu of options to the screen that looks like this:}{\loch\af2 
\par }{
\par \tab }{\f2 to test:\tab \tab please type:}{
\par }{\loch\af2 \tab \hich\af0\dbch\af0\loch\f2 -------------------------------
\par \tab \hich\af0\dbch\af0\loch\f2 profit\tab \tab p
\par \tab \hich\af0\dbch\af0\loch\f2 revenue\tab \tab r
\par \tab \hich\af0\dbch\af0\loch\f2 cost\tab \tab \hich\af0\dbch\af0\loch\f2 c
\par \tab \hich\af0\dbch\af0\loch\f2 attendees\tab \hich\af0\dbch\af0\loch\f2 a
\par \tab \hich\af0\dbch\af0\loch\f2 (or, to quit)\tab q
\par 
\par \tab \hich\af0\dbch\af0\loch\f2 your choice: 
\par 
\par \tab }{At this point, it should read in what the user types. }{\loch\af2 
\par }{
\par \tab If the user types }{\b\f2 p}{, }{\b\f2 r}{, }{\b\f2 c}{, or }{\b\f2 a, }{then it should ask the us
er for a ticket price, and then test the corresponding function with that ticket price, printing out a descriptive message including that result (formatted to two decimal places). Then it should print the menu again, and allow the user to enter their next
 choice. 
\par 
\par \tab If the user types }{\b  }{\b\f2 q}{, then the program should simply quit/stop.
\par 
\par \tab If the user types anything else (anything that is not  }{\b\f2 p}{, }{\b\f2 r}{, }{\b\f2 c}{, }{\b\f2 a}{, or }{\b\f2 q}{), then the main function should complain, print the menu again, and allow the user to enter their next choice.
\par 
\par \tab Now, be careful --- I've described how it should behave above, but the logic within your code may need to be slightly different (although with the same effect in operation). Consider: what needs to be repeated? What doesn't? }{\b Carefully}{
 consider your }{\b logic}{ --- what needs to be done, in what order --- before you start writing any C++ code.
\par 
\par \tab }{\b Additional requirements}{: 
\par }\pard \s15\ql \fi-435\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {*\tab if code is repeated in every body (or many bodies) within a series of nested if-else-ifs, then look to see if there are actions that can instead be done }{\b before}{
 or }{\b after}{ the series of nested if-else-ifs. (This is called }{\b abstracting out}{ the common actions.) Sometimes this might involve careful additional use of if statements.
\par 
\par *\tab you need to write a simple function }{\b isFunctAbbrev}{ (in }{\b isFunctAbbrev.cpp}{) that accepts a }{\b char}{ and returns }{\b true}{ if that char is }{\b p}{, }{\b r}{, }{\b c}{, or }{\b a}{, and returns }{\b false}{
 otherwise. Use it as appropriate (it should help with the above goal).
\par 
\par *\tab (if you think of other useful functions --- feel free to write and use them! Be sure to turn them in if you do so, also.)
\par }\pard \s15\ql \fi-435\li435\ri0\nowidctlpar\aspalpha\faauto\rin0\lin435\itap0 {\b 
\par }{\tab (small hint: what other functions does this }{\b main}{ call? So what #include statements must be within the file }{\b testAll4.cpp}{?)
\par 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\tab After compiling this, testing it, and correcting it until it works properly, mail me a copy of your resulting }{\b testAll4.cpp}{ and  }{\b isFunctAbbrev.cpp}{
 (and any other files containing additional functions, if you choose to write any) }{\i as described above}{.}{\i 
\par }\pard \s15\ql \fi-435\li435\ri0\nowidctlpar\aspalpha\faauto\rin0\lin435\itap0 {
\par }\pard \s15\ql \li-15\ri0\nowidctlpar\aspalpha\faauto\rin0\lin-15\itap0 {Remember --- when you are done with this homework, you should have sent me at least 4 e-mail messages, one each for }{\b counted1.cpp}{, }{\b sentinel1.cpp}{, }{\b testAll4.cpp}{
, and }{\b isFunctAbbrev.cpp}{.
\par }\pard \s15\ql \fi-435\li435\ri0\nowidctlpar\aspalpha\faauto\rin0\lin435\itap0 {
\par }}