Homework 3
The homework is due on Wednesday, May 3, 2006 at 5pm.
Due to the power outage, you can submit the homework through Thurs. May 4
at 5pm.
Name your files hw03_<problem>.cpp. Email all files to my Helios
account.
-
This purpose of this problem is to work with function overloading. You will
write several versions of a function call find_min(), a function called
get_input() and a function called print_min().
- The first version of find_min() will take two integers and return the
smaller integer. The corresponding version of get_input() will have two
call-by-reference integer parameters and will prompt the user for two integers
that will be returned via those parameters.
- The second version will take two doubles and return the smaller double. The
corresponding version of get_input() will have two call-by-reference double
parameters and will prompt the user for two doubles.
- The third version will take three integers and return the smallest integer.
Its corresponding get_input() will have three call-by-reference parameters
and will prompt the user for three integers.
- The first version of print_min() will take an integer and print the message
"The minimum is <value>.\n".
- The second version of print_min() will take a double and print the message
"The minimum is <value>.\n".
From within main, call each version of get_input() and find_min() in turn and
call print_min() with the result of find_min(). For example, you will call
get_input() with two integers, find_min() with two integers and then
print_min() with the result of find_min().
- From the book, programming project 5.13 on page 296:
The area of an arbitrary triangle can be computed using the formula
area = sqrt( s(s - a)(s - b)(s - c) ), where a, b, and c are the lengths of
the sides and s is the semiperimeter. s = (a + b + c)/2. Write a void function
that uses five parameters: three value parameters that provide the lengths of
the edges, and computes the area and perimeter (not the semiperimeter) via
reference parameters. Make your function robust. Note that not all combinations
of a, b, c produce a triangle. Your function should produce correct results
for legal data and reasonable results for illegal combinations.