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.)

You'll use a list to store your quiz items in a global variable and use a sublist for each question/answer pair. And so you can choose just one pair at a time to work with. set (computer science quiz) to (list (list (What is the computer science term for looping or repetition?) (iteration)) (list (What is the name for the abstraction in a program that can hold a value?) (variable)) (list (What kind of variable is available only in the part of the program where it is defined?) (local variable))) ask (item(1) of (item (3) of (computer science quiz))) and wait  if (item (2) of (item (3) of (computer science quiz)) = answer) {      say (That's correct!) for (2) secs  }

But code like item (1) of (item (3) of (computer science quiz)) 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.
set (computer science quiz) to (list (question: (What is the computer science term for looping or repetition?) answer: (iteration)) (question: (What is the name for the abstraction in a program that can hold a value?) answer: (variable)) (question: (What kind of variable is available only in the part of the program where it is defined?) answer: (local variable))) ask (question of quiz item (item (3) of (computer science quiz))) and wait  if (answer = answer from quiz item (item (3) of (computer science quiz))) {      say (That's correct!) for (2) secs  }

: 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 item (1) of () 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.

    primitive types: number, text, Boolean, list, sprite, command, reporter, predicate

: 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.
  1. "U2L2-Quiz" Start a New Project called U2L2-Quiz

  2. Build the custom quiz detail abstract data type (both the constructor and the two selectors).
  3. 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...

    1. Click on the pointer to the right of the input name:
      create input name right arrow
    2. Choose the information type y'all want for that input. (For this project, you lot'll utilise the "text" and "list" input types.)
    3. Click "OK."
  4. Create a global variable to store your quiz items and initialize it as a listing of items, using your constructor where appropriate.
  5. 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. quiz watcher 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.

    Save your work
  6. Test both the selectors for different items in your list of quiz items, and debug any problems.
  7. Imagine you brand a variable capitals and employ ready to give this list of lists a name:
    set (capitals) to {{Augusta, Maine}, {Boise, Idaho}, {Columbia, South Carolina}, {Des Moines, Iowa}}
    Which of the post-obit statements are true?

    Choose all that apply.

    item (1) of (capitals) reports a listing with two items: "Augusta" and "Maine".

    item (1) of (item (1) of (capitals)) reports the word "Augusta".

    item (last) of (item (2) of (capitals)) reports the word "Iowa".

    (length) of (capitals) reports the number viii.

    all but first of (item (last) of (capitals)) reports a listing with one detail: "Iowa".

    item (3) of (capitals) reports the string "Boise".

    item (last) of (all but first of (capitals)) reports the cord "Iowa".

    (length) of (item (1) of (capitals)) reports the number 2.

heilsaily1965.blogspot.com

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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel