[st10@nrs-labs 111lect08-2]$ funct_play
----------------------------------------------
Welcome to the 2014-03-14 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: n
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: circ_area
***** DESIGN RECIPE STEP 2.1: *****
Enter the signature comment for the function circ_area, using format:
circ_area : parameter_type parameter_type ... -> return_type
signature: circ_area : double -> double
Your signature for circ_area is:
--------------------------------------------------------
signature: circ_area : double -> double
--------------------------------------------------------
***** DESIGN RECIPE STEP 2.2: *****
Enter a purpose statement for the function circ_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 circle's radius, and returns the
area of that circle
q
Purpose statement:
---------------------------------------------------------------
purpose: expects a circle's radius, and returns the
area of that circle
---------------------------------------------------------------
***** DESIGN RECIPE STEP 2.3: *****
Enter the header for the function, using the format:
return_type circ_area (param_type param_name, ...)
Function header:
double circ_area(double radius)
Your header for circ_area is:
-------------------------------------------------
double circ_area(double radius)
-------------------------------------------------
***** DESIGN RECIPE STEP 3: *****
Enter at least one example call of function circ_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: circ_area(1) == 3.14159
circ_area(10) == 314.159
q
Examples:
---------------------------------------------------------------
Examples: circ_area(1) == 3.14159
circ_area(10) == 314.159
---------------------------------------------------------------
BEFORE you type in circ_area's body --- are there any
NEW named constants that you want to CREATE?
(answer y or n):
your reply: y
type in your new named constant declaration, using the format:
const const_type CONST_NAME = expression;
new declaration:
const double PI = 3.14159;
do you have another named constant declaration?
(enter y or n):
your reply: n
NOTE --- if a named constant was already declared for an
OLD function that circ_area calls, then it SHOULD be
visible for use in circ_area, too...
(at least, it should be the way that funct_play2 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 circ_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 circ_area's body is complete):
Enter body following the header:
double circ_area(double radius)
{
return PI * (radius * radius);
}
q
circ_area's body:
----------------------------------------------------------------
{
return PI * (radius * radius);
}
----------------------------------------------------------------
COMPILING circ_area.cpp...
-----------------------------------------------------------------
circ_area.cpp COMPILED! 8-)
Would you like to run circ_area_ck_expect?
(type y if so, n if not)
your answer: y
testing circ_area: true's should mean passed:
---------------------------------------
(circ_area(1) == 3.14159): true
(circ_area(10) == 314.159): true
Enter a C++ expression involving:
circ_area
...and type enter
(or type q to quit):
circ_area(1)
value of circ_area(1):
3.14159
Enter next C++ expression and type enter
(or type q to quit):
circ_area(10)
value of circ_area(10):
314.159
Enter next C++ expression and type enter
(or type q to quit):
q
Quitting funct_play ... goodbye.
[st10@nrs-labs 111lect08-2]$