BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Intermediate Julia

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

mutable struct Employee
    name::String
    location::String
    age::Int
    
    # Create a function that defaults the location to "Sydney"
    function ____(name, ____)
		____(____, "Sydney", ____)
    end
    
end
Kodu Düzenle ve Çalıştır