Description
The purpose of this challenge is to define basic classes.
Requirements
- Define a class called Point as below
class Point { private: double x, y; public: void set_coords(double _x, double _y) { x = _x; y = _y; } };
- Beneath the definition of Point, define a class called Map as below
class Map { private: Point tl, br; public: Map(Point _tl, Point _br) { } double calc_area() { } };
- Create Point variables tl, br. Think of these variables to hold top-left, and bottom-right sections of a map. Note that these data members are of type Point.
- In Point, create public getter functions for the variables x and y.
- Create an overloaded constructor for Map to pass in two variables of type Point.
- In Map, create a getter function that calculates the area bounded by tl and br. Note that tl may not necessarily always hold values that are top-left in relation to br. Regardless, tl and br represent coordinates of two points that are diagonally across from each other. The area bounded by these two points can be calculated by getting the difference between their respective x and y properties. Consider using absolute value when calculating the differences.
- In main(), instantiate two Point objects. For each of the two objects, call set_coords() with some values that correspond to x and y coordinates on a Cartesian plane. See sample interaction.
- In main() calculate and display the area bounded by the two points.
Sample main()
// class definitions here int main() { Point p1, p2; p1.set_coords(3, 3); p2.set_coords(6, 7); // instantiate a map object // display total area bounded by p1 and p2 return 0; }
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0057
Print Requirements