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
andMotorbike
is provided to you. -
A
trait
Drive
is provided to you which has an abstract methodcan_drive
. -
The task is to
- implement method
can_drive
forCar
- implement method
can_drive
forMotorbike
- implement method
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
, 🚗, andMotorbike
, 🏍️, have one itemowner_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