Surface Area minus 2 other objects

Hi, this is the code I have currently and I have the surface area of the entire cabin, but I need to ask the user what is the dimensions of a kitchen counter and a shower stall and then subtract that from my surface area. How would I go upon doing that?

this is very important as well(Verify that these dimensions are realistic by confirming that the combined floor space of the counter and the shower stall do not take up more than 20% of the cabin's total floor space and that the shower stall is no larger than 32 inches x 60 inches.)

Here are the instructions for this program




The cabin is still a simple rectangular structure so, as before, you’ll need to request the dimensions of the cabin, but now you'll also need to request the dimensions of the kitchen counter and the shower stall. Now, you’ll call two separate functions to calculate most of the details. We want to know the total wall and ceiling surface area, how much paint and paint brushes will be needed, and how many boxes of floor tiles to buy.

Use the following functions, by name, in your design for this program:

main: do all input and output in main.

calc_area: Calculate the surface area of a rectangle and return the answer to main. Call this function several times: once for each wall, again for the ceiling, the floor, the kitchen counter and, finally, the shower stall.

calc_tiles: Calculate the number of boxes of tiles that will be needed to cover the floor. Of course, you'll need to subtract the space taken up by the kitchen counter and shower stall first. Tiles are sized 12 inches x 12 inches and there are 15 tiles in a box.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #include <iostream>
#include <string>
using namespace std;

double calc_area(double s1, double s2);

int main()
{
	double height, width, length, surf_area 
	cout << "What is the length, width, and height of the cabin?";
	cin << length << width << height;
	
	surf_area = calc_area(h, l); //front wall
	(height and length);
	surf_area += calc_area(h, w); //side wall
	(height and width);
	surf_area += calc_area(h, l); // back wall
	(height and length);
	surf area += calc_area(h, w); // side wall 2
	(height and width);
	surf_area += calc_area(l, w); // ceiling
	(length and width);
	surf_area += calc_area(l, w); // floor
	
	cout << "the total surface area is " << surf_area;
	
	return 0;

}

double calc_area(double side1, double side2)
{
	return side1 * side2;	
}
Last edited on
I need to ask the user what is the dimensions of a kitchen counter and a shower stall and then subtract that from my surface area. How would I go upon doing that?
The same way that you prompted for width and height of the cabin.

calc_tiles: Calculate the number of boxes
SMH. If you needed a function to calculated the number of dogs, would you call it calc_cats()? Of course not. It always surprises how many professors encourage bad habits. In a real world code review, I would insist that this name be changed to reflect what it actually does. Of course this is an assignment and you've been told to use that name, so use it.

Line 10: WHAT ARE THE DIMENSIONS?? I suspect that you're entering the cabin dimensions in feet. Then you'll probably enter the shower and counter top dimensions in inches? You need to be crystal clear with what dimensions the user should use to enter the values and what dimensions you're using to store them. Otherwise you're going to mess up the calculations somewhere. Notice that the max shower dimensions are given in inches, as are the tile sizes. My advice is to store all values in the same dimensions. I'd use inches/square inches. Prompt for the cabin dimensions in feet and then immediately convert the values to inches. When printing values in feet, convert immediately before printing them out. This way your code will use inches except for tiny sections in input and output.

Alternatively, you could prompt and store everything in feet and then convert the values given for shower size and tile size to feet.

Line 11: your <<'s should be >>'s
Lines 13-19: l and h are undefined. Also, you don't need to compute the front and back walls separately. They have the same area.

Here is your code cleaned up so it will compile when you add calc_tiles() and with comments on what you need to write. I've also used some math to reduce calls to calc_area(). You could reduce it further if you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
using namespace std;

double calc_area(double s1, double s2);
int calc_tiles(double tiledArea);

int main()
{
    // All dimensions stored in inches/square inches
    double height, width, length, painted_area;
    cout << "What is the length, width, and height of the cabin in feet?";
    cin >> length >> width >> height;
    length *= 12;
    width *= 12;
    height *= 12;
    painted_area = 2*calc_area(height, length); //front & back walls
    painted_area += 2*calc_area(height, width); //side walls
    painted_area += calc_area(length, width); // ceiling
    cout << "the total painted area is " << painted_area/(12*12) << "sq ft\n";
	
    // height and width of counter and shower
    double hcounter, wcounter, hshower, wshower;

    // TO DO: prompt for the counter and shower dimensions.

    // TO DO: ensure counter and shower aren't too big.

    double tiledArea;

    // TO DO: calculate tiled area = total floor space - counter space - shower space

    int boxes = calc_tiles(tiledArea);
    cout << "You need " << boxes << " boxes of tiles\n";
    return 0;

}

double calc_area(double side1, double side2)
{
    return side1 * side2;	
}
Oh yea I understand it a little better now, but where and what would I put in the calc_tiles function?
The input to calc_tiles is the area to be tiled. The output is the number of boxes required. The problem states that each tile is 12"x12" and there are 15 tiles per box.

So do the math and round up on the number of boxes. In other words, if the math says you need 3.453 boxes, then you need 4 because you can't buy .453 boxes of tile.

By the way, in the real world, the calculation is more complex. You'd have to add some for breakage. Tiles are fragile and you're going to break a few. You also have to add some for waste since you can't use each and every square inch of every tile.
Got it. Thank you!
Topic archived. No new replies allowed.