As part of a Racket-assignment, I have a task I am absolutely not getting. Since this is homework, I'd prefer to not get the solution directly in order to avoid any trouble with plagiarizing, but would rather try to write the code with your help.
Given two phone-contracts, implement a function that calculates at what number of sent SMS one contract gets more expensive than the other. If one contract is always cheaper than the other (no matter how many SMS sent), return false.
Contracts are described my a basefee, a monthly fee that might change in the second year of the contract (Contracts have always a duration of two years), a fee for SMS and how many free SMS the contract includes. Therefore I've written my contract-structure as following:
(define-struct contract
(basefee monthlyfee1 monthlyfee2 smsfee freesms))
Beforehand, I've implemented two functions. One, to compute the total cost of a contract in relation to possible free sms and a given number of sms:
(define (contract-total ctr sms)
(cond
[(= (contract-freesms ctr) 0) (+ (contract-basefee ctr)
(* 12 (contract-monthlyfee1 ctr))
(* 12 (contract-monthlyfee2 ctr))
(* (contract-smsfee ctr) sms))]
[(>= (contract-freesms ctr) sms) (+ (contract-basefee ctr)
(* 12 (contract-monthlyfee1 ctr))
(* 12 (contract-monthlyfee2 ctr)))]
[(<= (contract-freesms ctr) sms) (+ (contract-basefee ctr)
(* 12 (contract-monthlyfee1 ctr))
(* 12 (contract-monthlyfee2 ctr))
(* (- sms (contract-freesms ctr))
(contract-smsfee ctr)))]))
Two, compare the two contracts and return a boolean whether the first contract is cheaper than the second one with a given number of sms:
(define (cheaper? ctr1 ctr2 sms)
(< (contract-total ctr1 sms)
(contract-total ctr2 sms)))
I am now struggling to implement that very break-even-function that tells me at which amount of sms the second contract will be cheaper than the first one. The signature of the function is
Contract Contract -> MaybeSMS
So, a first idea of mine was to implement a cond-clause checking which of the two contracts is cheaper in the beginning of the break-even-graph (with 0 SMS, so to speak).
How do I proceed from here? I think the other cond-clauses (the condition in particular) needs to have different cheaper?-functions, but since in my Signature no number of sms is given, I am not sure how to implement that one.
Aucun commentaire:
Enregistrer un commentaire