Get startedGet started for free

Writing your own functions - structs

In this final exercise on structs, you are going to modify a pre-defined structure using a custom constructor.

You have been provided with a custom type to store the details of each employee at our company, and this a mutable struct so that the values within the instance can be modified. Our company only has one office in Sydney, so let's set the location field to Sydney by default when creating a new instance.

After this, you need to write a custom function to increment the age field when it is the birthday of an employee.

This exercise is part of the course

Intermediate Julia

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

mutable struct Employee
    name::String
    location::String
    age::Int
    
    # Create a function that defaults the location to "Sydney"
    function ____(name, ____)
		____(____, "Sydney", ____)
    end
    
end
Edit and Run Code