Use of procedures, parameter passing, block structures, data types, arrays, abstract data structures, conditional control, iterative and recursive processes, and input/output in programming solutions to a variety of problems. Prerequisite: None.

Project 4 - Pet Finder (Classes, Searching, and Sorting) - (100 points)



Part 1 Due date: 5/6/2019

Part 2 Due date: 5/9/2019

Objectives



  • Practice with classes in Python
  • Familiarize yourself with Binary Search
  • Learn about sorting algorithms

Part 1 (Due May 6th, 2019)



For this project, you will write a python program that reads in a file that contains information about various pets. The file will be read into separate objects depending on the type of the pet. For example, a dog will be read into a dog object and its attributes will be stored in the dog object. All these objects will be added to one list and searching/sorting operations will be performed on that list.

Here are the steps to complete this part of the project:

  • Create a Dog class that contains the following data attributes: name, birthdate (store as a string), breed, color and related methods.
  • Create a Cat class that contains the following data attributes: name, birthdate (store as a string), breed, color and related methods.
  • Create a Fish class that contains the following data attributes: name, birthdate (store as a string), type, color and related methods.
  • Create a Bird class that contains the following data attributes: name, birthdate (store as a string), type, color and related methods.
  • Create a python program called (petfinder.py) that imports the pet classes created above.
  • Read the pets.csv file into your program. Each line should contain information about a single pet with its individual attributes separated by commas.
  • Here is a sample CSV (comma separated values) file.

    Fish, Nemo, April 2nd, GoldFish, Orange,
    Cat, Shadow, July 3rd, American Bobtail, White, 
    Dog, Dug, August 1st, Golden Retriever, Brown,
    Bird, Nigel, January 15th, Pelican, Brown,
  • For every line, read in all of the fields for a single pet and create a new object for that pet depending on its type (the first string in each line).
  • Create a list that contains all the objects and add every new object to the list as it is created.
  • When the list of pet objects has been created, its size must be equal to the number of pets in the CSV file. Hint: Use this to double check if your code is working currently so far.

Part 2 (Due May 9th, 2019)



Display the following menu to the user for interaction.

  1. Print only the names of all the pets
  2. Show only pets of a certain type - Ask the user what kind of pet would you like to see (dog/cat/fish/bird). Based on the user input, show only the pets that are dogs/cats/fish/birds.
  3. Search for a Pet - For this option, you will call your own binary search function to search for the first pet name that matches the user entered string. If a pet is found in the list, then print all the details for that pet and the index in the list where it was found. If the pet is not in the list, then print a message informing the user that the pet is not in the list.
  4. Sort list based on pet name - For all the sort options you can implement either selection sort or insertion sort on the list of pet objects. After sorting the list, display the sorted list.
  5. Exit the program

Make sure to include input validation wherever you take input from the user and to comment your code comprehensively.

Submitting the project using submit directory



Create a ZIP file that contains the following and upload it to Canvas

  • README file
  • petfinder.py, dog.py, cat.py, fish.py, bird.py