Purpose (do/learn; why this/here): Extend the ADT by adding a date
ADT, adapting the contact
ADT to accept it, and adding more helper blocks.
Can we cut all the commented out text on this page? --MF, 7/22/19
MARY: change the DATE ADT to use the correct ADT format. --MF, 5/23/20
BRIAN: as a low priority (that is, after ALL the solutions for all units and all optional projects are done), you want to add a "parse a date" TIF. --MF, 5/23/20
On this page, you will develop an abstract data type (ADT) to store and access dates, and you will adapt your contact ADT to use it to store each contact's birthday.
As we add more complexity to contacts—birthday, work address, and so on—the location of each data point (such as the phone number) inside a contact might change. This is where an abstract data type helps. If you were to move the phone number as you refine your contact ADT, you could fix every single block that uses the phone number, or if you have an ADT, you could just fix the one selector that chooses the phone number from the list. With that one change, all the other blocks using that selector will get the data they need automatically.
Notice that name, address, and text are strings, but birthdate is a list. You can combine elements of different types in a list.
date
constructor that accepts this data as input and then reports a date as a list of three items. date
ADT into the contact
ADT.
contact
constructor block definition to accept a birthdate as a list by using the date
constructor. birthdate from contact
selector to retrieve the contact birthdate from the inputted contact.You could use several ask and answer blocks together with script variables.
Another way is to use abstraction and create another helper, that reports a list of the user's answers to these prompts:
contact list
, and add a new few contacts with birthdays. Fix any problems.