[st10@nrs-labs lab8]$ funct_play
----------------------------------------------
Welcome to the 2016-10-13 version of funct_play!
----------------------------------------------
Are there any already-created C++ functions (in the current
working directory) which you would like to be able to use
within your new function?
(type y if so, n if not)
your answer: y
Enter the name of an already-created function (created in the
current directory), or q to quit:
function name: circ_area
Enter the next name of an already-created function (created
in the current directory), or q to quit:
function name: q
Is your new function already in a file in the local directory?
(answer y or n): n
--- Entering a new function ---
Enter the name for your new function:
Function name: ring_area
***** DESIGN RECIPE STEP 2.1: *****
Enter the signature comment for the function ring_area, using format:
ring_area : parameter_type parameter_type ... -> return_type
signature: ring_area : double double -> double
Your signature for ring_area is:
--------------------------------------------------------
signature: ring_area : double double -> double
--------------------------------------------------------
***** DESIGN RECIPE STEP 2.2: *****
Enter a purpose statement for the function ring_area,
"a brief comment of what the function is to compute" [HtDP,
p. 18]
(enter a line containing NOTHING but q and typing the Enter key
to show when your purpose statement is complete):
purpose: expects a ring's outer radius and the radius of
its "hole", and returns the area of that ring
q
Purpose statement:
---------------------------------------------------------------
purpose: expects a ring's outer radius and the radius of
its "hole", and returns the area of that ring
---------------------------------------------------------------
***** DESIGN RECIPE STEP 2.3: *****
Enter the header for the function, using the format:
return_type ring_area (param_type param_name, ...)
Function header:
double ring_area(double outer, double inner)
Your header for ring_area is:
-------------------------------------------------
double ring_area(double outer, double inner)
-------------------------------------------------
***** DESIGN RECIPE STEP 3: *****
Enter at least one example call of function ring_area
including input(s) and the expected output given those
input(s); for example,
my_funct(3, 4) == 12
my_funct(0, 0) == -3
(enter a line containing NOTHING but q and typing the Enter key
to show when you have entered all of your examples):
Examples: abs(ring_area(10, 1) - (314.159 - 3.14159)) < .001
abs(ring_area(2, 1) - ((3.14159*PI*PI) - 3.14159)) < .001
q
Examples:
---------------------------------------------------------------
examples: abs(ring_area(10, 1) - (314.159 - 3.14159)) < .001
abs(ring_area(2, 1) - ((3.14159*PI*PI) - 3.14159)) < .001
---------------------------------------------------------------
BEFORE you type in ring_area's body --- are there any
NEW named constants that you want to CREATE?
(answer y or n):
your reply: n
NOTE --- if a named constant was already declared for an
OLD function that ring_area calls, then it SHOULD be
visible for use in ring_area, too...
(at least, it should be the way that funct_play sets these up ---
we will discuss SCOPE later, and then perhaps discuss some
other const declaration placement options.
***** DESIGN RECIPE STEPS 4, 5 *****
Enter the template/body of the ring_area (the part following the header),
being sure to include the { and } that should enclose it.
(enter a line containing NOTHING but q and typing the Enter key
to show when ring_area's body is complete):
Enter body following the header:
double ring_area(double outer, double inner)
{
return circ_area(outer) - circ_area(inner);
}
q
ring_area's body:
----------------------------------------------------------------
{
return circ_area(outer) - circ_area(inner);
}
----------------------------------------------------------------
COMPILING ring_area.cpp...
-----------------------------------------------------------------
ring_area.cpp COMPILED! 8-)
Would you like to run ring_area_ck_expect?
(type y if so, n if not)
your answer: y
testing ring_area: true's should mean passed:
---------------------------------------
(abs(ring_area(10, 1) - (314.159 - 3.14159)) < .001): true
(abs(ring_area(2, 1) - ((3.14159*PI*PI) - 3.14159)) < .001): false
Enter a C++ expression involving:
ring_area
circ_area
...and type enter
(or type q to quit):
q
Quitting funct_play ... goodbye.
[st10@nrs-labs lab8]$