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?
A company that organizes and runs conferences stores several pieces of information on the people who have registered for the conference: their name, registration category (regular, student, or member), hotel information, and whether they plan to attend the banquet dinner. Hotel information consists of the number of nights needed, what rating of hotel is requested (a number of stars from 2 to 4, inclusive), and the room type needed (double or king).
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 hotel information and conference registrants. 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 one of your define-struct in the previous question (indicate which one you are using).
Registration categories 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 registration-rate
which consumes
a registration category and returns the registration fee for that
region. Fees are given in the following table:
regular | $400 |
member | $350 |
student | $150 |
Write a program hotel-surcharge
which consumes
hotel information and produces the total charge for that hotel request
(for all nights). One night starts at $109 for a double and $89 for a
king at a 2-star hotel. Rates go up $30 per night for each room type
for each additional star (so a 4-star king room should cost $149 a
night). Compute the charges based on the formula given, rather than
by explicitly coding in the rates for each room-type and star
combination.
Write a program fees-due
which consumes a
conference registrant structure and produces the total fees due for
the registration. The total fees should include the registration fee,
hotel surcharge, and $40 if the person plans to attend the
banquet.
Write a program upgrade-hotel
, which consumes a
conference registration (not a hotel info) and a number (new number of
hotel stars) and returns a conference registration. If the given
number is larger than the number of hotel stars currently requested,
the produced registration has the new number of hotel stars (and all
other information the same). Otherwise, all of the information in the
produced registration should be the same as in the given
registration.
(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)
(registration-rate 'member)
[use your own
registration-rate program and replace 'member with "member" if your
program expects ]
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.