Exercises: Using CollectionsFeb 122018
Before attempting these exercises, you should read the posts about abstract data types, arrays and stacks and queues.
- In each of the following scenarios, choose appropriate collection types to represent the required data, and explain your choice:
- A 16-digit payment card number is validated by an arithmetic formula which uses the individual digits.
- A web browser records the sequence of URLs visited by a user during a browsing session.
- An image editor records the edits made by the user, so that an ‘undo’ button can be supported.
- A currency exchange matches a buyer with whichever seller offers the best exchange rate.
- In each of the following scenarios, choose appropriate combinations of collection types to represent the required data, and explain your choice:
- An order form allows a customer to enter their postcode, and then choose their delivery address from a drop-down menu of options.
- A program simulates Conway’s game of life.
- A university records system allows module marks to be queried, given a student ID number and a module code.
- For each of your answers to questions 1. and 2., write down which of the collection types’ operations would be needed to implement the required behaviour.