169k views
0 votes
You are writing a function double getcostofsandbox(int l, int w, int h, double costofpaintpersquareinch, double costofsandpercubicinch) that takes the dimensions of a sand box, the cost of painting a square inch, and the cost of filling a cubic inch with sand. Which of these is the best example of designing the function using functional decomposition?

1) Writing a separate function to calculate the cost of painting the sand box
2) Writing a separate function to calculate the cost of filling the sand box with sand
3) Writing a separate function to calculate the total cost of the sand box
4) Writing a separate function to calculate the dimensions of the sand box

1 Answer

1 vote

Final answer:

The best example of using functional decomposition for the function getcostofsandbox is to write separate functions for calculating the cost of painting and the cost of filling the sandbox with sand, which simplifies the main function.

Step-by-step explanation:

The best example of designing the function getcostofsandbox using functional decomposition is option 1) Writing a separate function to calculate the cost of painting the sandbox. Functional decomposition is a process where a complex operation is broken down into simpler, more manageable components. In this case, by creating a dedicated function to handle the calculation of the printing costs, you isolate this specific task and reduce the complexity of the getcostofsandbox function. Similarly, option 2 is also a good practice as it separates the task of calculating the cost of filling the sandbox with sand.

Moreover, option 3, while it sounds comprehensive, is essentially the original function's purpose, and option 4 does not aid in decomposition since the dimensions are inputs and do not need to be calculated.

User Mvw
by
8.4k points