Homework 19

 

1. Assuming the following declarations and initializations and prototypes:

double w = 0.25, u = 0.36;
int i=7;

// sqrt(x) is just like cmath's sqrt
double sqrt(double x);

// sqrt(k) returns true if the square root of k is a positive integer, false otherwise
bool sqrt(int k);

// round(x) returns integer nearest x
int round(double x);

 Note: sqrt() is overloaded.  Which sqrt function is called depends on the data type of the argument (here, double or int) passed to it as an argument.

Fill in the following table, giving the type and value of each expression.

Expression

Type

Value

sqrt(w)

 

 

sqrt(-9)

 

 

round(sqrt(u))

 

 

sqrt(5) || (i <2)

 

 

 

2. Step through this program with the debugger and figure out what useful work (if any) the mystery function accomplishes. In particular, use the "Step Into" button to step into calls to the function mystery and watch it execute.

 

Turn in the table from question 1 with the types and values filled in, and a sentence telling me WHAT the function in question 2 does (not HOW it does it!).