Lab 1

Warning

To compile you should use a CMakeLists.txt. It takes sometimes to get use to it, but it makes the compilation much easier.

Class templates

  1. Create a class template Position that will store the position in a 2D environment. The position can be int or float, etc.

  2. Create a class template Rectangle that will contain the origin position and the size of the rectangle. For the size use the class position too.

  3. Create the a function getArea() that will calculate and return the area.

  4. Create the getters and setters.

  5. Define the following operators for the class Position:

    • operator==

    • operator<, we want to compare the area.

    • operator>, we want to compare the area.

Function templates

  1. Create a function template const Comparable& findMax(const vector<Comparable>& a).

  2. This function should be able to accept a vector of Rectangle and return the one the maximum area.

  3. Create a function int BinarySearch(const vector<Comparable>& a, const Comparable &x). That allow to search for a rectangle in an ordered vector of rectangle.

LeetCode

If you are done you can start doing the following problems on LeetCode:

ENSURE WE HAVE RECORDED YOUR COMPLETION. FAILURE TO DO SO WILL RESULT IN A GRADE OF 0!