Question: The following function returns a Boolean value indicating whether the inputs are in the correct range. If they are, it updates the value of vol

The following function returns a Boolean value indicating whether the inputs are in the correct range. If they are, it updates the value of vol to be the volume.

bool volume(double w, double h, double d, double &vol)

{

if(w<0 || h<0 || d<0)

return false;

vol = w*h*d;

return true;

}

a. Rewrite it so that it returns the volume and throws an exception if the inputs are invalid.

b. Write a code fragment which tries to call your rewritten volume function with and prints "could not compute volume" if it catches any exceptions.

Step by Step Solution

3.37 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the rewritten function that returns the volume and throws an exception for invalid inputs pyth... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!