Challenge: Check If the Person Has a Driving License

This challenge checks your knowledge of traits.

We'll cover the following

Problem Statement

  • A struct Car and Motorbike is provided to you.

  • A trait Drive is provided to you which has an abstract method can_drive.

  • The task is to

    • implement method can_drive for Car
    • implement method can_drive for Motorbike
Vehicle Age Limit
Car 18 or above
Motorbike 14 or above

Output

The output should be 0 or 1 based on whether a person can drive or not.

1 or 0

Coding Exercise

Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.

Note: There is a can_drive function in the code for testing purposes. Do not modify it.

Here, Car, 🚗, and Motorbike, 🏍️, have one item owner_age for keeping things simple.

Good luck!🤞

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy