Lab 4
Practicing composition with the Company class
Submit after the end of the lab session

Overview

For this lab, you will continue practice the concept of using composition with the Company class. The lab also makes use of a CSV reading to obtain company andemployee records.

Instructions, Questions and Code-Writing

  1. Download the zip folder for the lab.
  2. Study the code in file lab4.py. Run the cdemo function and explain to yourself what it does.
  3. In the interactive shell, create two Company objects of your choosing and add Employee objects that you have also created. Place these two objects in a list and assign them to a variable (e.g. comp_list = [comp_obj1, comp_obj2]). With this variable as an argument, run the function display_companries (e.g. display_companies(comp_list) ) to see that it works.
  4. In the interactive shell, run the following statements:
    records = read_csv_to_dicts('emprecords.csv') display_employees('emprecords.csv')
    Explore the structure of the records data structure (you can just type it in the interactive shell and also call the type function on it. Describe it.
  5. Write a new function called load_companies that returns a list of Company objects based on records from the emprecords csv file. It should only take one argument: a string the indicates the name of the csv file (like display_employees). This function has multiple parts. Before you begin, make a list of intermeidate steps that you can implement and test. For example, you might want to just start with what the display_employees function does. After you make your list discuss it with the TA, or if busy, someone sitting next to you. You are encouraged to use the find_company function, which will return a Company object from your list if it already exists.
  6. Test your load_companies function by assigning it to a variable and calling display_companies on it.
  7. (optional) To the company.py file, add a new method to the Company class called total_salary. This method should return the total salary of all employees staffed at the company.
  8. (optional) In the lab4.py file, modify the display_companies function so that it also prints the total salary for the company on a separate line.

Deliverable

Create a pdf file that contains the following:

  1. A statement that summarizes your completion of the lab. As appropriate, the statement should include the following:
    • Who you worked with on the lab
    • Any difficulties you encountered
    • How you tested it (output can be provided at the end of your file)
    • Responses to questions
  2. Your clearly labeled answers to explanations and questions
  3. A summary of the files included in the zip folder
  4. Demonstrations that show that your code works

Put your files in a folder, zip it and submit it under Lab 1 on D2L. Check that your submitted zip file is complete.

Grading

The lab is worth 3 points. Your lab submission will be graded using the following rubric:

  • + .5 --- Your submission is clearly formatted.
  • + .5 --- Your submission includes a summary statement and includes how you collaborated.
  • + .5 --- Your statement addresses all questions.
  • + .5 / 1.0 --- You submitted most of the lab (0.5) or you submitted all of the lab (1.0).
  • + .5 --- Your lab submission is generally correct.

Labs are worth three points. Fraction scores will be rounded up to the nearest whole point.