This lab will be very similar to lab07, but we'll do it in C++ instead of in MATLAB.
You may want to review the idea of a "Design Recipe" introduced in lecture of Monday October 16:
Here is also a Wiki Page for the "Design Recipe" idea, but written in C++
Before starting this lab:
Create a new subdirectory ~/cisc106/lab10, and make that your working directory.
If you are not sure how to do this, then review the instructions from lab03, steps 1a through 1d.
There are two ways to copy the files for this week's lab. Read over both methods before deciding which one to use.
/www/htdocs/CIS/106/pconrad/06F/labs/lab10
Consult step1b of lab07 if you need a refresher about how to do this.
The work you do in step 2 of this lab is only for practice and learning. There is nothing to turn in from this step of the lab.
By now, I'm guessing you already know why. (Look back at lab04 step 2, lab05 step 2, and lab06 step 2 if you still need this pounded into your head.)
Previously, we've worked with M-files that define MATLAB functions.
In the lab10 directory, there is an example of a C++ files that defines a function: areaOfRect.cc
Take a look at this C++ source file. To test it out, we need to take several steps. We'll talk more about these steps in lecture, but you have enough here to get started:
areaOfRect.o
CC -c areaOfRect.cc
CC -c testAreaOfRect.cc CC -c rectPizza.cc
CC areaOfRect.o testAreaOfRect.o -o testAreaOfRect CC areaOfRect.o rectPizza.o -o rectPizza
./testAreaOfRect
You can also use g++
, but you have to use either all CC
or all g++
. Within a given directory or project, you have to choose one compiler and stick with it. (You switch compilers half-way, but if you do, you need to use the rm
command to delete all the .o
files, and recompile everything from the beginning.)
Look at the code inside all three files:
Then try the steps outlined above, to see if you can produce the following output:
strauss.udel.edu% CC -c areaOfRect.cc strauss.udel.edu% CC -c testAreaOfRect.cc strauss.udel.edu% CC areaOfRect.o testAreaOfRect.o -o testAreaOfRect strauss.udel.edu% ./testAreaOfRect Test 1...passed Test 2...passed strauss.udel.edu% CC -c rectPizza.cc strauss.udel.edu% CC areaOfRect.o rectPizza.o -o rectPizza strauss.udel.edu% ./rectPizza Please enter length of pizza: 10 Please enter width of pizza: 5 Please enter price of pizza: 7.99 Price per square inch is 0.16 strauss.udel.edu%
Look at the files myMin.cc
and testMyMin.cc
:
myMin.cc
defines a function which computes the minimum element in an array of integers testMyMin.cc
does regression testing on this function.In a later stage, you'll be asked to develop your own files myMax.cc
and testMyMax.cc
which are similar to these files, except that myMax.cc
computes the maximum element in an array.
However, we'll be a lot less free with the explanation of how to do Steps 3 and 4! That is for you to figure out on your own. So ask questions at step 2 if you don't understand. Once you do, you are ready to tackle some problems on your own.
Hopefully, you can do this on your own—it is a good test of whether you understood what you did at the earlier step. But just in case you need help, you can click the link below to reveal the answer:
http://www.udel.edu/CIS/106/pconrad/06F/labs/lab10/compileMyMin.txt
Write an C++ file, using the first three steps of the "Design Recipe" steps, that defines a function that computes the area of a disc (e.g. a pizza).
It may be useful to consult the Wiki Page about Design_Recipes in C++ for additional help on how to proceed.
When your function is complete and it tests continue to the next step to test it, thus completing step 4 of the design recipe.
Using the example programs testMyMin.cc
and testAreaOfRect.cc
as a model, write a regression test script for areaOfDisc.cc
. Use your examples that you came up with in step 2 of the design recipe.
Refine your C++ source files areaOfDisc.cc
and testAreaOfDisc.cc
until all the tests pass.
Using the example program rectPizza.cc
as a model, write an interactive driver called roundPizza.cc
that uses your areaOfDisc.cc
function to compute the price per square inch for a round pizza.
Important Instructions (deductions will be made for failing to follow these instructions)
areaOfDisc
to do that computation. Learning how to separate out these two parts of the software is one of the main things you are supposed to be learning from this exercise.roundPizza.cc
file
Use the Design Recipe to design a function myMax()
and store it in a file called myMax.cc. This function should take an array of integers, and the number of integers in that array, and return the maximum number in that vector. It should operate in a manner similar to the myMin.cc
function provided in the lab10 directory, which you may use as a model.
Following the steps outlined previously develop a regression testing file called testMyMax.cc
to do regression testing on the function you developed in step 4a.
If you aren't sure what to do, review step 2
A special note should be made about the use of the words script file in this lab.
When working with MATLAB, the word script file refers to a special kind of M-file, namely one that just contains a sequence of MATLAB commands to be carried out in order to solve a problem. We distinguish script files from the M-files that define functions.
We talk about diary files as the files where we keep a record of what we did in a particular MATLAB session
However, when we work with C++, when we refer to a script file, we are talking about a record of our work, i.e. the same thing we call a diary file when working with MATLAB.
Please make a note of this!
Once the programs developed for this lab work, create a script file called lab10.txt
in which you type out each of the C++ files you developed in steps 3 and 4, and also demonstrate that they work properly.
areaOfDisc.cc
testAreaOfDisc.cc
roundPizza.cc
areaOfDisc.cc
with roundPizza.cc
and run the resulting executable myMax.cc
testMyMax.cc
The following example shows how to create a zip file called lab10.zip
containing all the .cc
files in the directory lab10
.
The example is followed by an explanation. The part you type is in bold
.
strauss.udel.edu% pwd /www/htdocs/CIS/106/pconrad/06F/labs/lab10 strauss.udel.edu% cd .. strauss.udel.edu% pwd /www/htdocs/CIS/106/pconrad/06F/labs strauss.udel.edu% zip lab10.zip lab10/*.cc adding: lab10/areaOfRect.cc (deflated 48%) adding: lab10/rectPizza.cc (deflated 53%) adding: lab10/testAreaOfRect.cc (deflated 54%) strauss.udel.edu%
cd ..
to go one directory level higher than the one containing your .cc
files. zip lab10.zip lab10/*.cc
to
lab10
, containing all the files that end in .cc
from your current lab10
directory In your case, you should have five .cc files in all
For lab07, you had to submit seven files in all—the six M-files, and then the one diary file lab07.txt.
But this week, since we are using a zip file, you only have to submit two files:
lab10.zip
file (containing five C++ programs), andlab10.txt
file (the script file with all the runs)areaOfDisc.cc
(20 pts) testAreaOfDisc.cc
(10 pts) roundPizza.cc
(10 pts) myMax.cc
(20 pts) testMyMax.cc
(10 pts) lab10.txt
diary file, correct filenames, etc.) (10 pts)