The code looks as follows.