In this lab, you will develop a Contact List database application like the one on your phone.
On this page, you will develop an abstract data type to store and access contact data (name, address, phone number, etc.).
An abstract data type (ADT) is a custom data type that's meaningful to your program. You learned about data types and ADTs on Unit 2 Lab 2 Page 2: Planning a Quiz App.
quiz item
abstract data type to store the questions and answers in a list of quiz items. Here, we can make a contact
abstract data type to store the data for each contact in our list of contacts.contact
constructor and then selectors to access the name
, address
, and phone number
for any given contact.Snap! projects are not secure. Do not use your or your classmates' personal information.
contact with name: %name address: %address phone: %phone
contact
constructor that accepts three pieces of data as input: the contact's name, phone number, and address. name from contact
, address from contact
, or phone from contact
.
It's important to make sure that your inputs to a function match the expected input type. For example, the input type of address from contact
matches the output type of contact
; they are both of type "contact."
If you call address from contact
with an input that doesn't match, such as a list of contacts (for example, the contact list variable or the result of running keep
and having a subset of that list), it's not going to work. That may sound obvious, but in fact, beginning programmers make mistakes like that all the time; you have to teach yourself to think about the input and output types of your functions every time you write or use one.
That's also true about the inputs to the contact
constructor; you can't put something that isn't a name in the name input for contact
.
It's somewhat artificial to use the constructor as the input to a selector; these images are just examples to show what the selectors should be able to do when given a contact as input. In your program, the selectors will take an item from the contact list as input and output the correct piece of that contact, like this:
contact
constructor to add
a few contacts to your contact list.
name | address | phone |
---|---|---|
Jasmine Anderson | 123 Main St. #4, New York, NY 10001 | 212-555-1234 |
Morgan Preston | 149 E. 16th Ave., Sunnyvale, CA 94089 | 408-555-6789 |
Omar Hernandez | 369 Center St., Boston, MA 02130 | 617-555-1098 |
name
, address
, or phone
from a contact in your list