Lab 2, Objectives 3 and 4 code