CS 111 Quiz 2 god help me part 1

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

18 Terms

1
New cards

To create a custom data type with named fields. Groups pieces of related information together.

What is the purpose of a struct? define-struct

2
New cards

(define-struct russian-dance-team (nickname height coach lifts-per-program))

Give a correct example of creating a struct

3
New cards

No parenthesis separating the field names from the struct name itself

(define-struct cat (name breed color meow-volume)

Fix and explain:

(define-struct cat name breed color meow-volume)

4
New cards

Does not specify the type of item as struct, therefore cat seems like a variable

Fix and explain:

(define cat (name breed color meow-volume))

5
New cards

the inner 2 arguments are not defined as lists, so they are passed as function or variable inputs instead.

List of lists, nested lists. Explain and fix

(define list-of-lists (1 2) (3 4))

6
New cards

No parenthesis necessary at *, 1 is taken as the accumulator start value. But outer list needs sub-lists, not numbers .

(map (lambda (xub) (fodll * 1 sub)) list-of-lists)

Nested lists, explain and fix

(foldl * 1 list-of-lists)

7
New cards

To extract and combine different parts of strings

What is the purpose of a substring and string-append function

8
New cards

(string-append "a" "n" "n" "a")

Write a correct example of string-append

9
New cards

Substring needs both a start and end indice, even if only producing one letter.

(substring "hello" 0 1)

Explain and fix

(substring "hello" 0)

10
New cards

Nothing! string-append doesn't need a parenthesis since it is a function being passed as an argument to foldl

Explain and fix

(foldl string-append "" (list "a" "b" "c"))

11
New cards

Libraries take lists of string input

(define pop-lib (list (make-track "living la vida loca" "ricky martin" "pop")))

Explain and fix this library

(define pop-lib (make-track "livin la vida loca" "ricky martin" "pop"))

12
New cards

Doesn't define the name of the struct. Needs to make-something for it to be findable as a "something"

(define latin-library (list (make-song "voy a reir" "marc anthony" "ice dance")))

Explain and fix this library

(define latin-library (list "voy a reir" "marc anthony" "ice dance"))

13
New cards

(define-struct track (title artist genre))

(list of track) -> (list of string) where all the strings are song titles,

Give the type signature of this function, which extracts all song titles from a library

(define all-titles

(lambda (lib)

(map track-title lib)))

14
New cards

(define-struct skating-programs (team year music))

Define a struct with a title and the input types

15
New cards

Not using the complete struct name.

(map (skating-programs-team name-of-new-list-here)

Fix and explain

(define-struct skating-programs (team year music))

(map programs team)

16
New cards

Should use map, not foldl. We are transferring items to a new list, not combining.

Fix and explain

(foldl skating-program-title empty lib)

17
New cards

(filter (lambda (t) (string=? team (track-year t))) name-of-a-new-list)

Use filter not map, because map returns booleans. Andmap returns a single boolean. Filter iterates through and edits the list.

Write a line of code from this struct that outputs a list of all the programs by a specific ice dance team

(define-struct skating-programs (team year music))

(map programs team)

18
New cards

(= (music (skating-programs-music "upbeat" library)) 2)

Write a boolean function to produce #true or #false from testing whether a team's music fits the upbeat 90s theme