11. Data Structures

  • Feel free to use your laptop if you have it

  • Ensure I have recorded your completion — failure to do so will result in a grade of 0

  • I strongly encourage you to work with others in the lab

    • When you get stuck, do me a favour and ask those sitting around you for help

    • I want people to get used to working together in the labs

    • Peer teaching and peer learning is super effective

Note

To obtain full marks for the lab, you must:

  1. Have completed the pre-lab exercises

  2. Have been working on the lab content

  3. Demonstrate competency in the topics

11.1. Pre Lab Exercises

Warning

You must have completed the specified exercises prior to the start of the lab. If you have not come to lab prepared, you will be asked to leave and you will obtain a grade of 0 for the lab.

  1. Have all classes from the previous lab complete

  2. Chapter 15 exercise(s)

    • 6

  3. Write assertion tests for each of your functions above

11.2. Before Kattis

  1. Add to the Person class from the previous lab

    • A reasonable __repr__ method — you can decide what the string looks like

    • A reasonable __eq__ method — you can decide what it means for two Person objects to be equivalent

    • Make instances of the class and write assert tests to verify correctness

  2. Write a Contacts class that will manage a collection of Person objects

    • The class will keep track of many instances of Person objects

    • A method for getting the size() of the Contacts

    • No duplicate/equivalent Person objects are allowed to be in the collection

    • A method for adding a Person to the Contacts called add that takes a Person as a parameter

      • If someone tries to add a duplicate/equivalent Person, the method should raise a ValueError

    • A method to remove a Person called remove that takes a Person as a parameter (the one to be removed)

      • If someone tries to remove a nonexistent Person, the method should raise a ValueError

    • A __repr__ that returns a string containing the details of all Person objects

      • Be sure to make use of the Person class’ __repr__ method

    • Make an instance of the class, add/remove Person objects to it, and write assert tests to verify correctness

11.3. Kattis Problems

Go back and work on Kattis problems from previous labs that you have yet to solve. I’m betting there are several of the earlier ones you can revisit and solve. Remember, the Kattis problems are great for practice, and practice is the only way to get better at programming.

Warning

Ensure that your your completion has been recorded. Failure to do so may result in a grade of 0.