Final answer:
The task involves writing a C++ program to read rectangles and points, store rectangles in a vector, and then classify points as inside or outside these rectangles. The program stops reading rectangles after encountering 4 negative values, and stops reading points when it reads (-99.0f, -99.0f).
Step-by-step explanation:
To solve this problem, we will create a simple program in C++ that reads rectangles and points, and then determines if each point is inside or outside the rectangles. We will use a Rect class for rectangles and a Vec class for points. The std::vector will serve as our container for storing rectangles.
Let's define both classes first:
class Rect {
public:
float x1, y1, x2, y2;
// Constructor and other member functions here
};
class Vec {
public:
float x, y;
// Constructor and other member functions here
};
Now, here's a simplified version of the program:
#include
#include
int main() {
std::vector rectangles;
float a, b, c, d;
while (std::cin >> a >> b >> c >> d && (a >= 0 && b >= 0 && c >= 0 && d >= 0)) {
rectangles.push_back(Rect{a, b, c, d});
}
float x, y;
while (std::cin >> x >> y && !(x == -99.0f && y == -99.0f)) {
Vec point{x, y};
for (const auto& rect : rectangles) {
// Logic to classify point as inside or outside
}
// Print classification of the point
}
return 0;
}
The above code continuously reads groups of 4 floats, creating Rect objects, until it encounters 4 negative values, after which it begins to read points and classify them. The classification logic would involve checking whether the point coordinates fall within the rectangular bounds defined by the Rect objects in the vector.