Exercises in this lecture   previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home      

Exercise 5.13
Interval indexer


The Interval type represents an oriented interval [from - to]. We use the Interval example to illustrate the overloading of operators. If you have not already done so, read about the idea behind the struct Interval in the course teaching material.

In the client of struct Interval we use an indexer to access elements of the interval. Where, precisely, is the indexer used?

Add the indexer to the struct Interval (getter only) which accesses the i'th element of the interval.

Be careful to take the orientation of the interval into account.

Would it make sense to program a setter of this indexer?