Exercise 4:

Create a directory ex4 and store in this directory all the files corresponding to this exercise.

Question 1: Const-correctness (40 points).

For this question, we will reuse the class Date that you have created for the exercise 1, question 3.

Copy the files "Date.h", "Date.cpp" and "test_date.cpp" to the current directory.

We can notice the following in the code:

Let us modify these methods accordingly.

Modify the method set() such that it takes 3 arguments: m, d and y which are references to const integer.

Modify the method print() to indicate that it is a const method, i.e. it does not modify the object.

Add 3 methods: get_month(), get_day(), get_year(). Each of this method has no argument and returns an int corresponding to the month, the day and the year respectively. These methods are all const: they do not modify the object. Add these methods in the file "Date.h" and add their implementations in the file "Date.cpp".


Question 2: Inline functions (40 points).

Create two files: "utils.h" and "test_utils.cpp". In "utils.h" define the following inline functions:

In "test_utils.cpp", type (and complete) the following code:

// test_utils.cpp

// Include all necessary headers here

int main() {
double a = 2.1;
double a2 = square(a);
std::cout << a2 << std::endl;

double b = 4.5;
double M = max(a, b);
double m = min(a, b);
std::cout << "Max: " << M << " and min: " << m << std::endl;
}

Question 3: Inline methods (20 points).

Take the files from the question 1: "Date.h", "Date.cpp" and "test_date.cpp". Make copies of these files named: "Date_q3.h" and "test_date_q3.cpp". Make sure to rename the class Date to "class Date_q3". We will work now with these files suffixed by "_q3".

Modify the methods: set(), print(), get_month(), get_day() and get_year() to have inline methods. There are two ways to tell to the compiler that methods are inline. You are free to use either of these methods.