You may want to review the idea of a "Design Recipe" from the following wiki pages:
Before starting this lab:
Create a new subdirectory ~/cisc106/lab11, and make that your working directory.
The files for this lab are in the directory /www/htdocs/CIS/106/pconrad/07F/labs/lab11
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.
So you could skip it if you wanted to, and neither your instructor nor your TA would know.
Well, actually that's not entirely true.
We'd know if,
So, don't skip this step.
Previously, we've worked with M-files that define MATLAB functions.
In the lab11 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/07F/labs/lab11/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 lab11 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
As a reminder—when working with C++, we refer to a script file to mean what we called a diary file when working with MATLAB. Review the information about this in lab10.html if you need further clarification on this point.
Once the programs developed for this lab work, create a script file called lab11.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 lab11.zip
containing all the .cc
files in the directory lab11
.
The example is followed by an explanation. The part you type is in bold
.
strauss.udel.edu% pwd /www/htdocs/CIS/106/pconrad/07F/labs/lab11 strauss.udel.edu% cd .. strauss.udel.edu% pwd /www/htdocs/CIS/106/pconrad/07F/labs strauss.udel.edu% zip lab11.zip lab11/*.cc adding: lab11/areaOfRect.cc (deflated 48%) adding: lab11/rectPizza.cc (deflated 53%) adding: lab11/testAreaOfRect.cc (deflated 54%) strauss.udel.edu%
cd ..
to go one directory level higher than the one containing your .cc
files. zip lab11.zip lab11/*.cc
to
lab11
, containing all the files that end in .cc
from your current lab11
directory In your case, you should have five .cc files in all
This week, since we are using a zip file, you only have to submit two files:
lab11.zip
file (containing five C++ programs), andlab11.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) lab11.txt
diary file, correct filenames, etc.) (10 pts)