CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Intermediate Julia

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

mutable struct Employee
    name::String
    location::String
    age::Int
    
    # Create a function that defaults the location to "Sydney"
    function ____(name, ____)
		____(____, "Sydney", ____)
    end
    
end
Modifier et exécuter le code