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.

Lab 4 - Introduction to Files and Exceptions - (50 points)



Due date: 3/8/2019

Objectives



  • Using File input/output
  • Practice with exceptions

Introduction



For this lab, you will create a program (addressbook.py) that will manage an individual's address book. The program should allow a user to add new contacts, print the entire address book, search for a contact, modify the information about a specific contact, delete a contact, and exit the program. These features should work as follows:

  • Display the menu to the user that contains all the above options. Use a function for this option. (5 points)
  • Get input from the user. Note: Remember to perform input validation (5 points)
  • Add new contact - For this option, get the name, address, phone number, and email address from the user. Write/Add them to a file contacts.txt. Note: Make sure to use exception handling when opening the file for read/write purposes. Write out the file such that all the information about an individual is on separate lines. For example, the name "Mickey" and address "DisneyLand" should be on separate lines rather than on the same line. (10 points)
  • Print the Address Book - For this option, print all the contents of the address book. (5 points)
  • Search for a contact - For this option, ask the user for the name of the contact who they are looking for. Based on the name, look for that individual in the file one line at a time and, if they are found, display all the information for that individual. If the individual is not found, then display a message to the user saying "There is no contact with that name in your address book." (10 points)
  • Delete a contact - For this option, ask the user for the name of the contact who they want to delete from the addressbook. The first step is to find that individual in the file. If the individual exists in that file, then create a new file, copy all the contents before that individual and after that individual into that new file. Then write the entire to a 'new' file called contacts.txt. (10 points)
  • Exit - For this option, ask the user if they want to continue (y/n). If they would like to continue, then display the menu and get input from the user. If not, exit the program. Note: Make sure to include input validation for y/n. (5 points)

Extra credit - Modify a contact (5 points)



For this option, ask the user for the name of the contact whose information needs to be modified. Find the information for that individual in your file. Now ask the user which aspect of that individual's information would they like to modify - name, address, phone number, or email address. Accordingly, get input from the user and modify that information for that user. Make sure to write the modified information to contacts.txt

Submitting the lab



Please turn in the following for the lab on Canvas.

  • addressbook.py
  • contacts.txt
  • README file