? print position 2 12.56 ? print position 6 0
You may wish to run additional test cases.
? Type in a number. -7 The absolute value of -7 is 7.
For full credit the punctuation should appear exactly as above. You may wish to run additional test cases.
Test your procedure to confirm that it runs as follows:
? print absolute -2 2 ? print absolute 6 6
You may wish to run additional test cases.
Test your procedure to confirm that it runs as follows:
? print oddp 3 true ? print oddp 6 false
You may wish to run additional test cases.
b) What happens when you print smallp zero? Why? What happens when you print smallp "zero? Why? (Note: this a question about error messages, not about predicates. It also serves as an introduction to and motivation for part (c).)
c) Use the primitive procedures numberp and ifelse to create a new procedure smallnumberp that takes one input and outputs true if the input is a number less than 1, false if the output is a number greater than or equal to 1, and which prints a warning and outputs false if the input is not a number. (If you get stuck on this problem, take a break and work on the next one.)
to ticketPrice :age ifelse :age < 13 [output 0][ifelse :age >= 55 [output 3][output 7]] endUse complete sentences. Draw an informal flow chart to provide visual support for your explanation. If you wish, you may submit the flow chart on paper in class. Support your explanation with sample runs of the procedure for representative choices of inputs.
Vocabulary point: The procedure uses "nested conditionals" because conditional execution occurs within conditional execution.
? rollDice Your dice roll is: 6 4
? rollDice Your dice roll is: 3 3 You got doubles!
? rollDice Your dice roll is: 5 2If you wish, you may use wait to build suspense for each die roll.
? solveQuadratic 1 -1 -2 2 -1 ? solveQuadratic 1 -2 1 1 1 ? solveQuadratic 1 -1 2 0.5 + 0.5*i*sqrt 7 0.5 - 0.5*i*sqrt 7 ?
As you can see, our new task for this procedure is correctly displaying complex roots. For the test case above with complex roots, you should solve x^2 - x + 2 = 0 by hand to reason through what the roots should be. Notice that humans understand 0.5 + 0.5*i*sqrt 7 as a number, but we will have Logo construct it as a sentence. The first 0.5 comes from -b/(2a). The second 0.5 comes from 1/(2a). The square root of -1 is denoted i. The discriminant is negative, so instead of putting the discrimant after the word "sqrt (not the instruction sqrt), we switch the sign on the discriminant (to display 7 instead of -7).
You should run additional test cases to make sure your procedure is not tailored to the specific cases above and to get extra evidence that it works as it should for all cases with complex, real and different, and repeated roots. (You are not required to show these test cases.)
Would you like a receipt for this transaction? (Type "Y" or "N".) Insert your parking ticket. (Type "P" to simulate inserting your parking ticket.) Thank you. You owe $12 for 4 hours of parking. Insert your credit card. (Type "C" to simulate inserting your credit card.) Thank you. Remove your credit card. Please remove your parking ticket. Please remove your receipt.Have it print the last line only if you pushed "yes" at the beginning. (In practice it gives you a receipt and tells you to take it regardless.)
Add an option to pay in cash, use a randomly generated number between 1 and 12 for the time parked. For bonus points, add a "help" screen; can you make the help screen come up whenever a user types "H" at a prompt then return to the appropriate point in the program?
It is important that this program be very reliable and easy to use. Spelling and grammar should be correct.