On this page, you will develop code for "Add Contact" and "Clear List" buttons in your contact list program.
We use "input" loosely to mean the empty boxes in a block that get filled with values. But input also means information entered into a program by the user, as in the ask and wait block. Program input can also come from data tables, sounds, pictures, video, or other programs.
Similarly, program output means any data sent from your program to the user or to any device. Typically, the output depends on the input.
contact constructor.You'll want to ask the user for each piece of data (contact name, address, and phone number) separately.
ask and answer blocks together with script variables to request and then store each piece of user input until you are ready to report them all together using contact.
and
) that each ask the user for one piece of data and report their answer to the contact constructor.
ask the user a specific question (like, "What is the contact's address?") and then report the user's answer.
You could first build a more general
helper block (yet another abstraction) to use in the other helper blocks instead of rewriting the ask and answer script every time.
You can use these examples or make up your own:
| 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 |
ask the user, "Enter c to clear the list, or enter anything else to cancel."hide variable and show variable to hide the contact list watcher until the end of each sprite's script.In this activity, you're going to refine the handling of people's names. When you look up a particular person, you want to see their name as you've been seeing it on this page, first name first: "Morgan Preston." But suppose you want to sort your contacts. Typically that's done by last name, so the list would look something like
Before you begin, save your project again, under the name U3L2-TIF. This will keep your work on these problems separate from the regular problems.
contact with name block. This is an abstract data type (name) inside another abstract data type (contact).name from contact block will now report a list, as it should. But some other parts of the program, such as the part that displays a contact to the user, want to display the name as a text string: "Jasmine Anderson." The part that sorts the contact list also wants a string: "Anderson, Jasmine." Write two blocks
and
that join the two parts of the name with a space and/or a comma as needed.Save your work. On page 4 you're going to find a contact by letting the user enter any part of the name, and display the entire contact. Use the name abstraction you've just created when you do that.
Based on the thermostat program described in the flowchart, determine whether the following statements are true or false.