Due: Wednesday 09/18 10:00am
Submission name: work05.rkt
Function Contracts
A function contract is a way to document a function within your code. Contracts contain the following information:
- Template function call using variables.
- The type of value to be returned by the function.
- The type of value represented by each parameter.
- A description of what the function does.
- One (or more) samples with input values and expected outputs.
Sample contract:
; (hypot a b) --> number
; a : number
; b : number
; Returns the lenght of the hypotenuse of a right traingle with legs of length a and b.
; (hypot 3 4) --> 5
Write the Following Functions given the contracts.
Paste the contracts into your racket program when starting. Use define
and lambda
to write your functions. Include test cases with descriptive output.
; (perimFromArea a) --> number
; a : number
; Returns the perimeter of that square whose area is a
; (perimFromArea 25) --> 20
; (perimFromArea 10) --> 12.649110640673518
; (f_to_c temp) --> number
; temp : number
; Returns temp converted from farenheit to celsius
; (f_to_c 212) --> 100
Tip: \(C = (F-32)\dfrac{5}{9}\)
Write contracts and the functions for the following:
cost
- Returns the cost of a ticket to the Totally Real Not Made Up Amazing Museum of Racket Exercises.
- The cost of admission depends on a base amount and a discount rate.
- Cost is calculated by:
base + base * rate
. - Write the function
(cost base rate)
that will return the cost using the formula above. - Example:
(cost 10 0.25)
==>12.5
groupCost
- Returns the total cost of the tickets for a school trip to the Totally Real Not Made Up Amazing Museum of Racket Exercises
- The base cost for students is $5, and the discount rate is 0.5.
- The base cost for teachers is $10, and the discount rate is 0.75.
- The base cost for other adults is $10, and the discount rate is 1.
- Write the function
(groupCost students teachers adults)
that returns the total cost of the tickets given the amounts provided as parameters, using thecost
formula. - Example:
(groupCost 34 2 2)
==>330.0
Submitting your work using GitHub Classroom:
- Join the GitHub classroom assignment via the correct link:
- Period 9: https://classroom.github.com/a/pQDHKUhf
- Period 10: https://classroom.github.com/a/L22rWK5Q
- After following that link, click “Accept this assignment”
- After ~1 minute (maybe less), refresh the page.
- You should see a link that looks something like: https://github.com/stuycs-gh-classrooms/09-fcs-dw-work-jonalf
- The end of that url will differ based on your GitHub username and the beginning by your class period. Click on that url.
- This is where you will submit all your work, bookmark this page.
- This will create a GitHub repository for you, and add a basic
README.md
file to it.
- You will be taken to the repository page for your work. You will see the contents of
README.md
, which should display: “Work For NeXtCS” and then “Name: YOUR NAME HERE”. - Edit
README.md
by clicking on the pencil icon found to the far right ofREADME.md
- Replace “YOUR NAME HERE” with your full name, first then last (use preferred name if you’d like).
- Find the “Commit changes” button and click it.
- When you’ve finished the homework, use the “Add File -> Upload Files” button to upload your
work03.rkt
file.
Important Notes:
- Use the submission name listed above as the file name for your work.
- Make sure you are using the definitions pane to write your programs, and that you are saving that area when submitting.
- Use the interactions pane to test your code, but you do not submit what is there.
- The CS Dojo starts today! If you want to get a leg up, stop by 307 from 3:45 - 5!
- If you are having difficulty getting DrRacket to work on your computer, you can use this online editor:
Work Task:
- Read chapter 4 of the online textbook.
- Take the 3 formulas from the previous assignment, and make the functions using
lambda
anddefine
. - If done correctly, this code should work (as long as you named the functions the same as I did):
(triArea 12 5) (celToFaran 100) (gravity 27 2 3)