Please send questions to
st10@humboldt.edu .
Macintosh-194:131lect09-1 smtuttle$ expr_play
----------------------------------------------
Welcome to the 03-03-10 version of expr_play!
----------------------------------------------
Are there any already-created C++ functions (in the current
working directory) which you would like to be able to use
within C++ expressions?
(type y if so, n if not)
your answer: y
*********************************************************
NOTE: to test a function A, you need to give the names
of ALL functions that A uses, as well as those that
THEY use --- otherwise, the tests will fail.
(that is, you may have to give all functions in the
PROGRAM...)
**********************************************************
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
Enter a C++ expression involving:
circ_area
...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 expr_play ... goodbye.
Macintosh-194:131lect09-1 smtuttle$ funct_play2
----------------------------------------------
Welcome to the 03-03-10 version of funct_play2!
----------------------------------------------
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 contract for the function ring_area, using format:
ring_area : parameter_type parameter_type ... -> return_type
Contract: ring_area : double double -> double
Your contract for ring_area is:
--------------------------------------------------------
Contract: 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 the outer radius of a ring and the radius
of the ring's "hole" -- its outer and inner
radii, if you will -- and produces the arrea
of the ring
q
Purpose statement:
---------------------------------------------------------------
Purpose: expects the outer radius of a ring and the radius
of the ring's "hole" -- its outer and inner
radii, if you will -- and produces the arrea
of the 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_rad, double inner_rad)
Your header for ring_area is:
-------------------------------------------------
double ring_area(double outer_rad, double inner_rad)
-------------------------------------------------
***** 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(100, 10) - 31101.8) < .1
ring_area(10, 0) == circ_area(10) - circ_area(0)
q
Examples:
---------------------------------------------------------------
Examples: abs(ring_area(100, 10) - 31101.8) < .1
ring_area(10, 0) == circ_area(10) - circ_area(0)
---------------------------------------------------------------
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_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 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_rad, double inner_rad)
{
return circ_area(outer_rad) - circ_area(inner_rad);
}
q
ring_area's body:
----------------------------------------------------------------
{
return circ_area(outer_rad) - circ_area(inner_rad);
}
----------------------------------------------------------------
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(100, 10) - 31101.8) < .1): true
(ring_area(10, 0) == circ_area(10) - circ_area(0)): true
Enter a C++ expression involving:
ring_area
circ_area
...and type enter
(or type q to quit):
ring_area(100, 10)
value of ring_area(100, 10):
31101.8
Enter next C++ expression and type enter
(or type q to quit):
q
Quitting funct_play2 ... goodbye.
Macintosh-194:131lect09-1 smtuttle$ expr_play
----------------------------------------------
Welcome to the 03-03-10 version of expr_play!
----------------------------------------------
Are there any already-created C++ functions (in the current
working directory) which you would like to be able to use
within C++ expressions?
(type y if so, n if not)
your answer: y
*********************************************************
NOTE: to test a function A, you need to give the names
of ALL functions that A uses, as well as those that
THEY use --- otherwise, the tests will fail.
(that is, you may have to give all functions in the
PROGRAM...)
**********************************************************
Enter the name of an already-created function (created in the
current directory), or q to quit:
function name: ring_area
Enter the next name of an already-created function (created
in the current directory), or q to quit:
function name: q
Enter a C++ expression involving:
ring_area
...and type enter
(or type q to quit):
ring_area(10, 1)
Undefined symbols:
"circ_area(double)", referenced from:
ring_area(double, double)in ring_area.o
ring_area(double, double)in ring_area.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
*****************************************************
Are you sure that ring_area(10, 1) is truly a C++ arithmetic
expression (with no variables)?
Chances are good that it is not; the above are C++
compiler messages. Save them and show them to
your prof if you have questions.
*****************************************************
Enter next C++ expression and type enter
(or type q to quit):
q
Quitting expr_play ... goodbye.
Macintosh-194:131lect09-1 smtuttle$ expr_play
----------------------------------------------
Welcome to the 03-03-10 version of expr_play!
----------------------------------------------
Are there any already-created C++ functions (in the current
working directory) which you would like to be able to use
within C++ expressions?
(type y if so, n if not)
your answer: y
*********************************************************
NOTE: to test a function A, you need to give the names
of ALL functions that A uses, as well as those that
THEY use --- otherwise, the tests will fail.
(that is, you may have to give all functions in the
PROGRAM...)
**********************************************************
Enter the name of an already-created function (created in the
current directory), or q to quit:
function name: ring_area
Enter the next 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
Enter a C++ expression involving:
ring_area
circ_area
...and type enter
(or type q to quit):
ring_area(10, 10
try_expr1.cpp: In function ‘int main()’:
try_expr1.cpp:11: error: invalid operands of types ‘double’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
try_expr1.cpp:11: error: expected `)' before ‘;’ token
*****************************************************
Are you sure that ring_area(10, 10 is truly a C++ arithmetic
expression (with no variables)?
Chances are good that it is not; the above are C++
compiler messages. Save them and show them to
your prof if you have questions.
*****************************************************
Enter next C++ expression and type enter
(or type q to quit):
ring_area(10, 1)
value of ring_area(10, 1):
311.018
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 expr_play ... goodbye.
Macintosh-194:131lect09-1 smtuttle$ funct_play2
----------------------------------------------
Welcome to the 03-03-10 version of funct_play2!
----------------------------------------------
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: abs_value
***** DESIGN RECIPE STEP 2.1: *****
Enter the contract for the function abs_value, using format:
abs_value : parameter_type parameter_type ... -> return_type
Contract: abs_value : double -> double
Your contract for abs_value is:
--------------------------------------------------------
Contract: abs_value : double -> double
--------------------------------------------------------
***** DESIGN RECIPE STEP 2.2: *****
Enter a purpose statement for the function abs_value,
"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 number and produces its absolute
value
q
Purpose statement:
---------------------------------------------------------------
Purpose: expects a number and produces its absolute
value
---------------------------------------------------------------
***** DESIGN RECIPE STEP 2.3: *****
Enter the header for the function, using the format:
return_type abs_value (param_type param_name, ...)
Function header:
double abs_value(double num)
Your header for abs_value is:
-------------------------------------------------
double abs_value(double num)
-------------------------------------------------
***** DESIGN RECIPE STEP 3: *****
Enter at least one example call of function abs_value
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_value(-3) == 3
abs_value(5) == 5
abs_value(0) == 0
q
Examples:
---------------------------------------------------------------
Examples: abs_value(-3) == 3
abs_value(5) == 5
abs_value(0) == 0
---------------------------------------------------------------
BEFORE you type in abs_value'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 abs_value calls, then it SHOULD be
visible for use in abs_value, 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 abs_value (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 abs_value's body is complete):
Enter body following the header:
double abs_value(double num)
{
if (num < 0)
return -1 * num;
else
return num;
}
q
abs_value's body:
----------------------------------------------------------------
{
if (num < 0)
return -1 * num;
else
return num;
}
----------------------------------------------------------------
COMPILING abs_value.cpp...
-----------------------------------------------------------------
abs_value.cpp COMPILED! 8-)
Would you like to run abs_value_ck_expect?
(type y if so, n if not)
your answer: y
testing abs_value: true's should mean passed:
---------------------------------------
(abs_value(-3) == 3): true
(abs_value(5) == 5): true
(abs_value(0) == 0): true
Enter a C++ expression involving:
abs_value
...and type enter
(or type q to quit):
abs_value(-34.6)
value of abs_value(-34.6):
34.6
Enter next C++ expression and type enter
(or type q to quit):
abs_value(0.1)
value of abs_value(0.1):
0.1
Enter next C++ expression and type enter
(or type q to quit):
abs_value(-3)
value of abs_value(-3):
3
Enter next C++ expression and type enter
(or type q to quit):
q
Quitting funct_play2 ... goodbye.
Macintosh-194:131lect09-1 smtuttle$ funct_play2
----------------------------------------------
Welcome to the 03-03-10 version of funct_play2!
----------------------------------------------
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: spiciness
***** DESIGN RECIPE STEP 2.1: *****
Enter the contract for the function spiciness, using format:
spiciness : parameter_type parameter_type ... -> return_type
Contract: spiciness : int -> string
Your contract for spiciness is:
--------------------------------------------------------
Contract: spiciness : int -> string
--------------------------------------------------------
***** DESIGN RECIPE STEP 2.2: *****
Enter a purpose statement for the function spiciness,
"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 Scoville rating of some pepper,
and produces a string of the youngest category
of person I should offer a chili with that
rating to
q
Purpose statement:
---------------------------------------------------------------
Purpose: expects a Scoville rating of some pepper,
and produces a string of the youngest category
of person I should offer a chili with that
rating to
---------------------------------------------------------------
***** DESIGN RECIPE STEP 2.3: *****
Enter the header for the function, using the format:
return_type spiciness (param_type param_name, ...)
Function header:
string spiciness(int sco_rating)
Your header for spiciness is:
-------------------------------------------------
string spiciness(int sco_rating)
-------------------------------------------------
***** DESIGN RECIPE STEP 3: *****
Enter at least one example call of function spiciness
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: spiciness(1) == "infant"
spiciness(500) == "toddler"
spiciness(799) == "toddler"
spiciness(1000) == "adult"
spiciness(10000) == "adult"
q
Examples:
---------------------------------------------------------------
Examples: spiciness(1) == "infant"
spiciness(500) == "toddler"
spiciness(799) == "toddler"
spiciness(1000) == "adult"
spiciness(10000) == "adult"
---------------------------------------------------------------
BEFORE you type in spiciness'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 int INFANT_MAX = 500;
do you have another named constant declaration?
(enter 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 int TODDLER_MAX = 1000;
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 spiciness calls, then it SHOULD be
visible for use in spiciness, 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 spiciness (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 spiciness's body is complete):
Enter body following the header:
string spiciness(int sco_rating)
{
if (sco_rating < INFANT_MAX)
{
return "infant";
}
else if (sco_rating < TODDLER_MAX)
{
return "toddler";
}
else
{
return "adult";
}
}
q
spiciness's body:
----------------------------------------------------------------
{
if (sco_rating < INFANT_MAX)
{
return "infant";
}
else if (sco_rating < TODDLER_MAX)
{
return "toddler";
}
else
{
return "adult";
}
}
----------------------------------------------------------------
COMPILING spiciness.cpp...
-----------------------------------------------------------------
spiciness.cpp COMPILED! 8-)
Would you like to run spiciness_ck_expect?
(type y if so, n if not)
your answer: y
testing spiciness: true's should mean passed:
---------------------------------------
(spiciness(1) == "infant"): true
(spiciness(500) == "toddler"): true
(spiciness(799) == "toddler"): true
(spiciness(1000) == "adult"): true
(spiciness(10000) == "adult"): true
Enter a C++ expression involving:
spiciness
...and type enter
(or type q to quit):
q
Quitting funct_play2 ... goodbye.
Macintosh-194:131lect09-1 smtuttle$