Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To write a function that uses helper functions inside another function A helper function is a function that is meant to be called from some

To write a function that uses helper functions inside another function
A helper function is a function that is meant to be called from some other "bigger" function. Its a technique
for dividing a problem into parts, and thus very important in computer science. For this question, youll
create a function that uses two other helper functions to do its work.
Painting a House
Mrs. Peacock loves the color blue. She wants to paint the entire outside of her house blue, including the
roof!
The house has four walls, and all of the walls are the same size. With W as the width of each wall and H
as the height of each wall, the formula for the total outer wall area is:
walls = W H 4
The roof is a pyramid, which is to say that it is made up of four isosceles triangles. The width of the base
of this pyramid must be W , i.e. the width of each wall. If we let T be the height of each of the triangles that
make up the pyramid (in geometry this is often called the slant height), then the formula for the total roof
area is:
roof =4 W T /2
All of the above units of size are in meters. If we are also told the cost of paint per square meter, then our
task is to calculate the total cost for the paint needed to paint the house.
Helper Functions
First, write the following two helper functions. They will be very short and simple. Thats ok; in fact, thats
the point.
A function to calculate the area of the walls
A function to calculate the area of the roof
In both cases, the functions should take only the parameters they need to perform their computations.
Total Cost Function
Next, write a function to compute and return the total cost of paint needed to paint the house. The function
should have four parameters:
the width of the walls
the height of the walls
the slant height of the roof (i.e. the height of each triangle)
the cost per sq. m. of paint
This function should call the helper functions to perform their part of the calculation.
Console I/O
In the main part of your program (i.e. NOT inside the functions body), use console input to get the values
needed by your function. You may assume that the user supplies valid input. Then call your function using
those values to get the total cost of painting the house. Finally, display a message that indicates the total
cost.
Sample Run
Here is an example of how your programs console output might look. Green text was entered by the user;
blue text came from data returned by the function.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Does the person have her/his vita posted?

Answered: 1 week ago

Question

How can either be made stronger?

Answered: 1 week ago