Question 4 Solution

Solved question 4 in C++