Struct

Can u help me with this, please ?


Create a room structure (C-style, no member-functions) with member-data room dimensions. Write a show () function that displays the room data and an area () function that calculates its face (squaring).
In main () create a static array of rooms (Room variables) - the rooms in one apartment. For each of the rooms, display its dimensions and square footage. Determine the total square footage of the apartment.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;


struct room {
	double l ;
	double h;
	
};

void show (room);
What, exactly, is it that you're having trouble with?
Considering i posted it, yes
You'll need a struct that holds the dimensions as you've done. Mine is a little different.
1
2
3
4
struct RoomDimensions {
    double length;
    double width;
};


Then you need show() to display those value, and area() that calculates the area. area() might look like this.
1
2
3
double area(RoomDimensions room) {
    return room.length * room.width;
}


To use such a function, you might do this.
 
std::cout << area(kitchenDimension) << std::endl;
Last edited on
Hello Chad9,

This may help.


1. Create a room structure (C-style, no member-functions) with member-data room dimensions.

2. Write a show () function that displays the room data
   2a. and an area () function that calculates its face (squaring).

3. In main () create a static array of rooms (Room variables) - the rooms in one apartment.

4. For each of the rooms, display its dimensions and square footage.

5. Determine the total square footage of the apartment.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <iomanip>  // <--- May be useful later. Used for "std::fixed" and "std::setprecision()".
#include <string>

using namespace std;

struct room
{
    double length{};
    double width{};
};

void show(room);  // <--- Step 2.
// <--- Step 2a.

int main()
{
    // <--- Step 3.
    // <--- Step 4.
    // <--- Step 5.

}

// <--- Functions for step 2 and 2a. 

When it comes to naming variables this video may help https://www.youtube.com/watch?v=MBRoCdtZOYg

A good name that describes the variable or function is very helpful.

I would suggest working on the program in small parts. First get the input to put into the array then store the information. A good question is do you want a 1D array or a 2D array? Point 3 does not say what the array should be, so you could choose a 2D array that would be acceptable.

I like to get some of the easier parts coded first. Esepically when it comes to getting user input so that you have something to work with. Then the rest becomes easier to work out.

It is also a good idea to have some plan to work from. It makes the coding easier.

Andy
Topic archived. No new replies allowed.