CSc 110: Contacts

This assignment should be written in the python programming language. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors! You may use any python version 3.0 or newer.

All of your programming should be well-formatted and easy for the graders to read and comprehend. Each program file should have a header comment at the top that has the following format:

#
# Author: Student Name
# Description:
#    A short description of what this program does!
# 

If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.

Contact Manager

Almost everyone these days has some type of contact list for managing the phone numbers and email addresses of friends, co-workers, and acquaintances. Some use Google contacts( contacts.google.com ), others use the contacts app on their phone, and some still even prefer old-fashioned paper-and-pencil organization.

In this assignment, you will implement a very simple contact organizer application in python.

You will write a program called contacts.py. Using this application, you will be able to request contact information, as well as add new contacts to your list.

This program will read and write contacts to/from a file named contacts.txt. contacts.txt will have a file format that looks like the following:

Bill Jones | bjon@gmail.com | 520-999-8765
Sam Dekker | dekker@apple.com | 123-456-7890
Janet Keller | kel@yahoo.com | 456-2356
James Jamie | jjamie@gmail.com | 435-234-2334

The precise names, emails, and phone numbers may vary. Also, the number of contacts in the file may vary. You should not assume that the file has any particular number of contacts in it. It could even be totally empty. You can assume that the contacts.txt file is in the same directory as the program you are implementing (contacts.py).

When contacts.py begins, it should read in and save all of the contact names, emails, and phone numbers into the program. Since you won’t know how many contacts are in the file ahead-of-time, you should use lists to accomplish store the information in. As you read in each contact, you can append the info into lists.

Once read them all in, your program should repeatedly prompt the user to enter in commands. Your program should support three main types of commands.


(1) show me contact X

The user can enter a command of the form show me contact X. In this case, X is the full name of a person (meaning that, it can have spaces in it). If the command that a user types begins with show me contact, then you should check to see if the name X is in the contact list. If it is, you should report the contact info like so:

X's contact info:
  email: A
  phone: B

However, you should replace X, A, and B with the actual name, email, and phone number. If the name does not exist, then you should print:

Not sure who that is.

Either way, after processing the command, the program should prompt the user for the next command afterward.

(2) add contact

When add contact is typed, the program will continue to prompt the user for three additional values: The name, email, and number of the contact. Once it prompts the user for these three things, the program will add this new contact to the list(s) of contact info that are stored in the program. Below is an example of what this should look like:

> add contact
    name: X
    email: Y
    phone: Z
contact added!

This is what it would look like, but the X, Y, and Z values will be custom values entered by the user. Each time an add contact command is processed, a new contact should be added to the list. You do not need to validate that X, Y, and Z are any particular type of input.

(3) exit

If the user types exit (all lower case) then the program should print an exit message and end. For example:

> exit
Goodbye!

When you exit the program, you should make sure to save the contents of the contact info lists back into the contacts.txt file. This is important so that your program will remember all of the newly-added contacts when it runs again in the future.

If contacts were added via the add contact command, these must be saved into the contacts.txt file, using the format described earlier.

Other

If any other command is entered, your program should print Huh? and then prompt the user for another command.


I will be providing a lot of example runs/output on the diff-testing tool on the class website. You should take care to make sure that the output of your program very closely matches the example runs that I post. That will be the best way to make sure you are implementing the program correctly.

Diff-Testing

As I mentioned, I will be providing many test-cases on the diff-testing tool on the class website. The format of the test cases that I will put on there is a little bit different than usual. The text of each test will have 3 parts.

It is critical that you test this program very well.

Submission and grading

It is due on 7/17/2017 at 7:00pm.

You should put all of your code in to a python file named contacts.py. Submit contacts.py to the associated D2L dropbox. Following these turn-in and naming instructions closely is very important, because our grading scripts will depend on some of the details. You may lose points if these instructions are not followed precisely!