Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Paint ALL The Walls! % Function Name: paintRoom % Inputs (5): - (double) one dim

ID: 3648102 • Letter: P

Question

Paint ALL The Walls!


% Function Name: paintRoom
% Inputs (5): - (double) one dimension of a rectangular room (in feet)
% - (double) a second dimension of the room (in feet)
% - (double) the third dimension of the room (in feet)
% - (double) the total area (in square feet) of any windows in
% the room
% - (double) the number of coats of paint needed
% Outputs (2): - (double) the number of 5-gallon paint cans needed
% - (double) the number of 1-gallon paint cans needed
%
% Function Description:
% Write a function named "paintRoom" that takes in three dimensions of a
% rectangular room, the area of the windows in the room, and the number
% of coats needed to paint the room. The function should calculate the
% number of 5-gallon cans of paint and the number of 1-gallon cans of
% paint needed to to paint the room (excluding the floor and windows),
% assuming one gallon of paint covers 350 square feet. In order to
% minimize cost, you should use as many 5-gallon cans as possible without
% exceeding the total number of gallons needed. Then use 1-gallon cans
% for any remaining paint required. If a fraction of a one-gallon can is
% needed, this number should be rounded up to account for the whole
% additional can that must be purchased (i.e. the number of 1-gallon cans
% must always be an integer).
%
% Notes:
% - The dimensions of the floor will always be the first two inputs.
% - The room is not guaranteed to have any windows.
% - The number of coats is guaranteed to be a positive integer.
%
% Hints:
% - You may find the ceil(), floor(), and mod() functions helpful.
%
% Test Cases:
% [bigcans1, galcans1] = paintRoom(30, 20, 30, 800, 2)
% bigcans1 => 3
% galcans1 => 1
%
% [bigcans2, galcans2] = paintRoom(10, 20, 55, 0, 1)
% bigcans2 => 2
% galcans2 => 0
%
% [bigcans3, galcans3] = paintRoom(13, 8, 9, 8, 2)
% bigcans3 => 0
% galcans3 => 3
%

Explanation / Answer

function [Num5gal,Num1gal]=paintRoom(fLength,fWidth,WallH,windowArea,coats) %paintarea= 4 walls and the floor ...why not the roof too? %paintarea=[((2*WallH*(fLength+fWidth))-windowArea)+(fLength*fWidth)]*coats; %spreadout: wall1=WallH*fLength; wall2=WallH*fWidth; flor=fLength*fWidth; paintarea=[((2*[wall1+wall2])-windowArea)+flor]*coats; gal=350;% one gallon =350sqft totgal=paintarea/gal Num5gal=floor(totgal/5);%round to >=int less5area=mod(totgal,5); %less5area=totgal-(Num5gal*5); Num1gal=ceil(less5area);