Chapter 4 - Enum & Patterns
-
Create an enum that contains HTTP 4xx Client Errors.
i.e.Not FoundShould have value404associated with it. -
Write an enum to store information of whether a person is a child or adult based on his/her age.
-
Create a calculator with the help of an enum named
Operationthat as values such asAdd, Sub, Div, Multi.
hint:For input like2+5*10it should first evaluate5*10and then add 2 to it. -
Use pattern matching to associate a enum of
Gradetype with a student based on his/her marks. -
Create an enum named
Jsonthat can work with arbitrary JSON data. -
Print what kind of input the user has given(numbers, letters, symbols) using pattern matching.
hint:Try using range for it e.g.0 ... 100or'a' ... 'k' -
Use pattern matching to find that whether a point lies on X-Axis, Y-Axis or on which quadrant.
-
Create a struct that holds info about a gun(gun type, recoil time, magazine size, extra) where
gun typeandextraare enums andextracontains silencer, scope, extended mags nadNone.
Based on user input change the value of extra (may cause change in recoil time and magazine size). -
Create a Binary tree and have a method
addon it to add elements to it andminandmaxto find the minimum and maximum element in it. -
Create a
Regexto extract dates from this stringIt was on 2019-03-14, almost after a year from 2018-02-11and store in a Struct with fields ofday,monthandyear.
hint:UseRegexcrate