Bjc Unit 2 Lab 2 Using Variables and Data Structures to Make Art
Planning a Quiz App
On this folio, you will brainstorm to develop a quiz app past creating an abstract data type to pair the questions with their answers.
: Sublist
A sublist is a list used equally an item of another list.
(The word sublist is also used to refer to some subset of a list.)
But code like is hard to read and empathise. A improve mode is to use brainchild to organize the quiz items. The brainchild only hides the list
and item of
blocks, then it isn't complicated to build, but it can make your code much easier to write, read, and debug.
: Data Types
- A data blazon is what kind of data something is (number, text string, list, etc.). For instance, number is the data blazon for the commencement input to and list is the the data blazon for its 2d input.
- Each programming language provides some primitive data types (data types that are built-in). For case, Snap! provides numbers, text (words and sentences), Booleans (true or false), lists, and some you haven't yet used as data (such every bit sprites and costumes). This menu shows all of Snap!'south primitive types.
: Abstract Data Types
The constructor and selector together implement the quiz detail
abstract data type.
- Data abstraction is the creation and use of abstract data types in a program.
-
"U2L2-Quiz"
- Build the custom
quiz detail
abstract data type (both the constructor and the two selectors). - Click on the pointer to the right of the input name:
- Choose the information type y'all want for that input. (For this project, you lot'll utilise the "text" and "list" input types.)
- Click "OK."
- Create a global variable to store your quiz items and initialize it as a listing of items, using your constructor where appropriate.
- Test both the selectors for different items in your list of quiz items, and debug any problems.
-
Imagine you brand a variable capitals and employ
ready
to give this list of lists a name:
Which of the post-obit statements are true?Choose all that apply.
reports a listing with two items: "Augusta" and "Maine".
Correct.
reports the word "Augusta".
Right.
reports the word "Iowa".
No. What is particular 2 of "capitals"?
reports the number viii.
No. Each of the small-scale lists is a single item in the list "capitals" .
reports a listing with one detail: "Iowa".
Correct.
reports the string "Boise".
The items of capitals are lists.
reports the cord "Iowa".
The items of
all but first of (capitals)
are lists.reports the number 2.
Correct.
Specifying an Input Type
Your selectors wait a quiz detail, i.e., a list, as input. You lot can make your blocks bear witness what type of data they look. It'south not necessary in Snap! but, like assigning a colour to a block, it tin can be a helpful reminder of what the block does and what type of input it expects. You lot've already seen input slots of several shapes, indicating different expected information types.
In the Cake Editor while creating a selector, click on a plus sign to enter an input name. And then...
Snap! has two dissimilar views for lists within lists. Y'all can switch which view you lot encounter by right-clicking (or control-clicking) on the quiz watcher (or whatever y'all called the variable) on the stage.
If you don't see the watcher on the stage, brand sure the checkbox beside the quiz variable in the Variables palette is checked.
: Table
A table is a two-dimensional data construction with rows and columns. If you've used a spreadsheet plan, what it displays is a tabular array.
In Snap!, a table is implemented as a list of lists, in which each sublist is one row of the table.
Source: https://bjc.edc.org/bjc-r/cur/programming/2-complexity/2-data-structures-art/2-quizzes.html?topic=nyc_bjc%2F2-conditionals-abstraction.topic&course=bjc4nyc.html&novideo&noassignment
0 Response to "Bjc Unit 2 Lab 2 Using Variables and Data Structures to Make Art"
Post a Comment