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. (OPTIONAL) Look at this program and figure out what useful work (if any) the mystery function accomplishes. You may find it useful to add cout statements and run the program with these additional outputs.

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