Remember to follow the Expectations on Homework when preparing your solutions, including the academic honesty policy.
A cellular phone company defines different service plans around three pieces of information: the region in which the plan is active, the number of minutes included, and whether the plan includes text messaging. The company defines three regions: Massachusetts, New England, and Nationwide.
Develop a data model for service plans. Include the define-struct needed to model plans and three examples of plans created with your model.
State all of the operators (with their contracts) that are created from your define-struct in the previous question.
Develop a data model for customer subscriptions for cellular service. A subscription contains the customer's name, number, service plan, and a discount code (one of none, long-dist-cust, or long-term-cust). Include the define-struct needed to model your subscriptions and three examples of data created with your model. You may choose/design your own data model for phone numbers (but be sure to document it if it's not a built-in kind of data!).
Discounts codes 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 regional-rate which consumes a
region and returns the monthly rate for that region. Regional rates are
according to the following table:
| mass | $19.95 |
| new-england | $29.95 |
| usa | $49.95 |
Write a program minutes-surcharge which consumes
a number of minutes (assume non-negative) and returns the rate for
that number of minutes. The first 150 minutes are free. Each 250
minutes beyond the first 150 costs $12. Your program should return
only whole-number multiples of 12. For example, 151 minutes costs
$12, 400 minutes costs $12, and 500 minutes costs $24.
Write a program message-surcharge which consumes
a discount code and returns a number representing the rate for text
messaging under that code. The rates should follow the table below:
| long-dist-cust | $3.95 |
| long-term-cust | $0 (free) |
| none | $5.95 |
Write a program subscription-rate which takes a
subscription and returns the total rate for that subscription. The
subscription rate is the total of the regional rate, minutes
surcharge, and messaging surcharge. The messaging surcharge should be
0 if the plan does not include messaging.
Write a program enable-messaging, which consumes
a subscription and returns a subscription with the same name, number,
and discount code as the original subscription, but with a plan that
includes text messaging.
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)
(offset-image+ (offset-image+ (offset-image+ (filled-rect 85 75 'tan)
10 (- 75 (* 3 num-a))
(filled-rect 15 (* 3 num-a) 'red))
35 (- 75 (* 3 num-b))
(filled-rect 15 (* 3 num-b) 'blue))
60 (- 75 (* 3 num-c))
(filled-rect 15 (* 3 num-c) '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?
(sqrt (+ (* 3 3) (* 4 4)))
^^^^^^^
= (sqrt (+ 9 (* 4 4)))
^^^^^^^
= (sqrt (+ 9 16))
^^^^^^^^
= (sqrt 25)
^^^^^^^^^
= 5
If 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)
(regional-rate 'new-england) [use your regional-rate program from above]
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.