Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Mrs . Peacock loves the color blue. She wants to paint the entire outside of her house blue, including the roof! The house has four

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.
Page 4
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephone: (306)966-4886, Facsimile: (306)966-4884
CMPT 141
Winter 2024
Introduction to Computer Science
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.
House Paint Calculator
Width of house walls : 4
Height of house walls : 5
Roof slant height : 3
Cost of paint for each square meter : 2
Total cost for an all - blue house : $208.0

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago