Now letβs say that we want to create a structure to represent a rectangle. The question is, what information do I have to provide in order to specify a rectangle? To keep things simple letβs assume that the rectangle will be oriented vertically or horizontally, never at an angle.
There are a few possibilities: I could specify the center of the rectangle (two coordinates) and its size (width and height), or I could specify one of the corners and the size, or I could specify two opposing corners.
The most common choice in existing programs is to specify the upper left corner of the rectangle and the size. To do that in C++, we will define a structure that contains a Point and two doubles.
struct Rectangle {
Point corner;
double width, height;
};
Notice that one structure can contain another. In fact, this sort of thing is quite common. Of course, this means that in order to create a Rectangle, we have to create a Point first:
βboxβ names a box that contains three variables: βwidthβ which is 100, βheightβ which is 200, and βcornerβ which names a package that has βx: 0β and βy: 0β."
The innermost squiggly braces are the coordinates of the corner point; together they make up the first of the three values that go into the new Rectangle. This statement is an example of nested structure.
Click on the legal ways to create a Point and Rectangle structure, assuming that the Point and Rectangle structures are declared above the main function in the same way as in the active code above.