程序代写代做 html Lab 4.3 – Number Cruncher

Lab 4.3 – Number Cruncher
In this lab, you will practice processing lists of numbers. Start from the template project here:
http://snap.berkeley.edu/snapsource/snap.html#cloud:Username=dlnelson&ProjectName=NumberCruncher
To help you check your work as you go, we have provided several suites of tests that will exercise your code and help catch common mistakes. Click on a test suite to run it. If the tests pass, it will report “Tests pass,” otherwise it will report an error telling you what the arguments were, what the result was, and what the result should have been.
WARNING: Just passing all the tests does not mean that your code is correct.

By default, SNAP does not check whether list items you’ve asked for are in the list. You can run nonsense code like and SNAP will report . . . something. For this lab, the test framework changes that behavior, and SNAP will report an error in such cases.
For each block you’re asked to write, an empty custom block has already been created; just edit the block and fill in the body with your solution.

Part 1: Summarizing Numbers
In this section, you will be writing custom blocks that reduce lists of numbers into a single value (either a number or a Boolean). For each block, you may assume that all items in the list passed as the argument will be numbers.
• Write a custom reporter block called that takes a list as an argument and reports the sum of all the numbers in the list.
• Write a custom reporter block called that takes a list as an argument and reports the average of all the numbers in the list.
• Write a custom predicate called that takes a list as an argument and reports:
• true if the list contains at least one negative number
• false if all numbers are positive.
• Write a custom predicate called that takes a list of numbers as an argument and reports:
• true if each value in the list is strictly greater than the one before it
• false otherwise.
• Write a custom reporter called that takes a list of numbers as an argument and reports the largest number in the list. You may assume that the list will not be empty.
Part 2: Transforming Lists
In this section, you will be constructing new lists based on argument lists. Do not modify the argument list. Rather, you should build up a new list to report. Start with the empty list, and add items as appropriate.
Again, you may assume that all items in the lists passed as arguments will be numbers.
• Write a custom reporter called that takes a list of numbers as an argument and reports a new list that is the same as the argument, except that all negative numbers have been replaced with their absolute values.
• Write a custom reporter called that takes a list of integers as an argument and reports a new list that contains only the even numbers from the argument list. The result list should have its values in the same order as the original list, but with the odd integers removed. You may assume that all the list items are integers. (Remember that the block can be useful in determining whether or not a number is even.)
• Write a custom reporter called that takes two lists of numbers as arguments and reports a new list that contains the sum of the corresponding values from each argument list. For example, if the arguments were (1 4 6) and (2 2 3), the result should be (3 6 9). You may assume that the argument lists are the same length.
• Write a test suite for your element-wise sum block. Include at least four test cases. Try to include test cases that would detect common programming errors (it’s a bit of an art).