Implementation of the compulsory part of exercise 3.