Home About Me Projects
Home
Github Repo

This project is a parser created for a C++ programming class that takes in a CSV file, specifically that which contains data for restaurant inspections, and maps this data to classes for analysis later. Once the CSV file is parsed, the program groups the cases by zip code and then orders the set by number of failures. Sets with the same number of failures are ordered by the date of their last failed inspection.

Structure

Restaurant Class

Below is the header for the restaurant class, which held the data that was stored in each column of the CSV file:

  • Constructor that takes in a list of strings so an instance can be created using a row of the CSV
  • Helper functions to set the values of different properties and to print out the class when finished

Location Data Class

An instance of the location data class held data for the cases found in its corresponding zip code. This class was used to structure data so that I can sort it later once all the cases were placed into location data instances:

  • Analyzes data from a restaurant class to see if it failed its health inspection, and if it did, the amount of failures in that zip code goes up and the date of failure is further analyzed
  • Dates are represented by structs in order to easily compare them while keeping code readable

Parsing and Sorting

Data from the CSV file was handled using the ifstream class, which read through the file row by row. Once all the data had been read in, the data was sorted using the following strategy:

  • Instances of the restaurant class are put in a list, which is then iterated through to see if a case with a zip code that has not been represented yet has been found (and if it is, create a new instance of LocationData for that zip code)
  • Sorts the map of LocationData instances with the most recent inspection failures at the beginning and the oldest at the end