Unit 2 Lab 2 Making Art by Using Data Structures Page 2

Planning a Quiz App

On this page, y'all volition brainstorm to develop a quiz app by creating an abstruse data type to pair the questions with their answers.

: Sublist

A sublist is a list used as an item of some other list.

(The word sublist is as well 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/reply pair. Then you can choose only 1 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  }

Just code like item (1) of (item (3) of (computer science quiz)) is hard to read and understand. A better way is to use abstraction to organize the quiz items. The brainchild merely hides the list and item of blocks, and so it isn't complicated to build, but it can brand 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 information type is what kind of information something is (number, text string, list, etc.). For case, number is the data type for the starting time input to item (1) of () and list is the the data type for its second input.
  • Each programming language provides some primitive data types (data types that are built-in). For example, Snap! provides numbers, text (words and sentences), Booleans (true or false), lists, and some you oasis't all the same used as data (such every bit sprites and costumes). This bill of fare shows all of Snap!'due south primitive types.

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

: Abstract Data Types

The constructor and selector together implement the quiz item abstract data type.

  • Data abstraction is the creation and employ of abstract data types in a plan.
  1. "U2L2-Quiz" Start a New Project called U2L2-Quiz

  2. Build the custom quiz item abstract data type (both the constructor and the two selectors).
  3. Specifying an Input Blazon

    Your selectors expect a quiz item, i.e., a list, as input. You tin make your blocks testify what type of information they wait. It's not necessary in Snap! but, like assigning a color to a cake, it can exist a helpful reminder of what the block does and what type of input it expects. You've already seen input slots of several shapes, indicating different expected information types.

    In the Block Editor while creating a selector, click on a plus sign to enter an input proper name. Then...

    1. Click on the pointer to the right of the input name:
      create input name right arrow
    2. Choose the information blazon you want for that input. (For this project, you'll use the "text" and "list" input types.)
    3. Click "OK."
  4. Create a global variable to store your quiz items and initialize it equally a listing of items, using your constructor where appropriate.
  5. Snap! has two different views for lists within lists. You lot can switch which view yous come across past correct-clicking (or command-clicking) on the quiz watcher (or whatever you chosen the variable) on the stage.

    If you don't see the watcher on the stage, make sure the checkbox beside the quiz variable in the Variables palette is checked. quiz watcher checked

    : Table

    A table is a two-dimensional information structure with rows and columns. If you lot've used a spreadsheet program, what it displays is a table.

    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 listing of quiz items, and debug any problems.
  7. Imagine you make a variable capitals and apply set to requite this list of lists a name:
    set (capitals) to {{Augusta, Maine}, {Boise, Idaho}, {Columbia, South Carolina}, {Des Moines, Iowa}}
    Which of the following statements are truthful?

    Cull 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 discussion "Iowa".

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

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

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

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

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

dohertyalsetly.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 "Unit 2 Lab 2 Making Art by Using Data Structures Page 2"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel