Lab 7: Good Dog

In this hands-on activity we will use parallel arrays to list all the good dogs.

Example

What if we want to input all the scoring data (average of the judge's scores for different categories) into our computer for a list of puppers? How can we write a program to find all the good dogs? Parallel arrays might be a good start.

For example, in JavaScript:

// Data on the dog's application (strings)
var names   = ["Aaron", "Barko", "Chilly", "Dog", "Ester", "Froufrou"];
var genders = ["boy", "boy", "girl", "dog", "girl", "girl"]
var breeds  = ["Poodle", "Boxer", "Mini-Pen", "Lab", "Chihauhau", "Mix"];

// Data from the dog's score (doubles)
var sits    = [9.8, 7.2, 8.2, 1.3, 9.4, 8.9];
var stays   = [7.3, 8.1, 7.0, 1.1, 6.0, 8.5];
var cuddles = [3.0, 6.2, 5.5, 9.9, 6.4, 8.6];

// Who is a good dog? Let's say anyone with a 5+ on all three scores
for (var i=0; i < names.length; ++i){
    console.log("Is "+names[i]+" the "+breeds[i]+
                " a good "+genders[i]+"?");
    if (sits[i] >= 5.0 && stays[i] >= 5.0 && cuddles[i] >= 5.0){
        console.log("Yes! "+names[i]+" the "+breeds[i]+
                    " is a good "+genders[i]+"!");
    } else {
        console.log("Well, not this year...");
    }
}

Questions

Part 1

  1. According to the book, what are parallel arrays? Why would we want to use them?
  2. For each of the following, say whether it will resolve to "true" or "false":
    • true AND true
    • true AND false
    • true OR true
    • true OR false
    • false AND false
    • false OR false
    • true AND (false OR true)
    • (true AND false) OR true
  3. Answer for each language: What is the syntax in your language for logical AND and logical OR? How would you use this to code "if it is sunny and warm, then print go outside, else print stay inside"? Demonstrate your answer with screenshots.
  4. Assume I have your Blackboard grades stored in parallel arrays (I don't). Your name is at index 14 of the names array. At what index would you find your grade for lab 2 in the lab2s array? Why?
  5. Research as necessary: When speaking about arrays in general (regardless of language), what do we mean by the terms:
    • split
    • concatenate
    • reverse
    • filter
    • map
    • reduce

Part 2

  1. Pick one language from your group. What language did you choose for this task and why?
  2. In your chosen language, program the "good dog detection algorithm" described above. Change the values of the scores arrays to have whatever values (doubles between zero and ten) that you want so that some dogs are good dogs but not all dogs are good dogs. Demonstrate your answer with screenshots.

Part 3

  1. According to our current "good dog detection algorithm," why is Aaron not considered a good dog?
  2. The dog named Dog is not considered a good dog, yet gives very good cuddles. Update the logic to say anyone with a 5+ on any score is a good dog. (Hint: use OR instead of AND.) Demonstrate with screenshots.
  3. Add another score array called fetches and populate it with whatever values (doubles between zero and ten) that you want. How could you update your logic to say anyone with a 5+ on any two scores is a good dog? Demonstrate with screenshots.