Remember to follow the Expectations on Homework when preparing your solutions, including the academic honesty policy.
The following code produces bar graphs for three pieces of data.
;; bar-graph : number number number -> image ;; consumes three numbers and produces bar graph of results ;; NOTE: background image sized for inputs up to 20 (define (bar-graph num-a num-b num-c) (overlay/xy (overlay/xy (overlay/xy (rectangle 80 80 'solid 'tan) -25 (- 40 (* 1/2 3 num-a)) (rectangle 15 (* 3 num-a) 'solid 'red)) 0 (- 40 (* 1/2 3 num-b)) (rectangle 15 (* 3 num-b) 'solid 'blue)) 25 (- 40 (* 1/2 3 num-c)) (rectangle 15 (* 3 num-c) 'solid 'green)))
Copy this code to your homework file, then create a cleaner version of it using helper functions and constants. Turn in only your final version (with all helpers and constants). You do not need to include a copy of the original code. Your final version should have the same behavior as the original code (don't embellish it, just clean it up).
Be sure to include contracts, purposes and test cases for your helper functions.
Describe in a few sentences how you went about this exercise. Specifically, how did you decide when to create a helper function or constant?
TravelersComputer.com specializes in insuring mobile computers, guaranteeing to replace a mobile computer if it is lost or stolen. The company stores several pieces of information on their customers: their name, number of years that they are enrolled, computer information, and which replacement policy they have (express-within 24 hours, regular-within 3 days, discount-within 1 week). Computer information consists of the type of computer (notebook, tablet, pocketpc), disk size in GB, and whether it includes a printer.
Your solutions to the following problems should use helper functions in place of repeated code (we will deduct points otherwise). You may also introduce helper functions to improve the readability of your code.
Develop data models for customers and computers. Include both the define-structs and three examples of data for each struct that you define.
State all of the operators (with their contracts) that are created for either one of your define-struct in the previous question (indicate which one you are using).
Computer type could be represented either as symbols or as strings. What are the advantages and disadvantages to each decision? Which one seems to make more sense and why?
Write a program basic-insurance-rate
which consumes
a computer type and returns the insurance charge for that
type for one year. Charges are given in the following table:
notebook | $100 |
tablet | $150 |
pocketpc | $50 |
Write a program computer-insurance-rate
which consumes
computer information and produces the total yearly insurance charge
for that computer. Charges start with the
basic-insurance-rate
,
plus $.10 per GB of disk.
A printer, if present, is an additional $10.
Write a program insurance-due
which consumes a
customer structure and produces the total insurance charges due for
the customer. The total charge should include the yearly rate times
the number of years, with an additional 25% surcharge for express
service and a 10% savings for discount service.
Write a program add-printer
, which consumes a
customer (not a computer) and produces a customer. If the customer's
computer does not have a printer, then
the returned customer's computer has a printer (and all
other information remains the same). Otherwise, all of the information in the
produced customer should be the same as in the given
customer.
(sqrt (+ (* 3 3) (* 4 4))) ^^^^^^^ = (sqrt (+ 9 (* 4 4))) ^^^^^^^ = (sqrt (+ 9 16)) ^^^^^^^^ = (sqrt 25) ^^^^^^^^^ = 5If an expression would result in an error, show all of the steps up to the error, then indicate the error message you'd get (error messages don't need to be verbatim, as long as they convey the right kind of error). You can use the Stepper to check your answers, but do the problem manually first to make sure you understand how Scheme works.
(/ (- (* 16 16) (double a)) 2)
where double is
defined as (define (double n) (* n 2))
(or (< 7 2) (and (= 15 (- 18 3)) (> 8 4)))
(and (+ 9 -1) false)
(basic-insurance-rate 'tablet)
[use your own
basic-insurance-rate program and replace 'tablet with "tablet" if your
program expects a string]
cond: expected a clause with a question and answer, but found a clause with only one part
reference to undefined identifier: x
function call: expected a defined name or a primitive operation name after an open parenthesis, but found a number
Turn in a single file hwk1.ss or hwk1.scm containing all code and documentation for this assignment (there is something to turn in for every part). Make sure that both students' names are in a comment at the top of the file.
This page maintained by Mike Gennert Department of Computer Science Worcester Polytechnic Institute |