Work

Work 05: 9/20

posted Sep 20, 2018, 10:37 AM by JonAlf Dyrland-Weaver   [ updated Sep 20, 2018, 12:19 PM ]

Write the following functions in racket
  • average3
    • Has 3 number parameters.
    • Returns the average of those three numbers.
    • examples
      • (average3 1 2 3) ==> 2
      • (average3 23 176 5) ==> 68 
  • tip
    • Takes one argument representing the cost of a meal.
    • Returns the total amount you should pay including an 18% tip
      • Examples
        • (tip 100) ==> 118
        • (tip 64) ==> 75.52
  • gravity
    • Takes 3 arguments representing the masses of 2 objects and the distance between them.
    • Returns the gravitational force as calculated by Newton's formula:
      • Force = (G * mass1 * mass2) / distance2
      • G is a constant defined as 6.674 * 10-11 , which can be written as 6.674e-11 in racket.
    • Examples
      • (gravity 1 2 3) ==> 0.000000000014831
      • (gravity 100000 20000000 6) ==> 3.707
  • coinValue
    • Has 4 parameters representing the number of pennies, nickels, dimes and quarters, respectively.
    • Returns the total value, in dollars, of the coins
    • Examples:
      • (coinValue 1 2 3 4) ==> 1.41
      • (coinValue 2 2 2 2) ==> 0.82
      • Note: you might actually get a number like 0.8200000000000001 back
  • getHundredsDigit
    • Takes one argument representing an integer.
    • Returns the hundreds digit of that number.
    • Examples
      • (getHundredsDigit 234) ==> 2
      • (getHundredsDigit 76348) ==> 3
    • Hint: you may find a function from the previous assignment helpful.
Submit this as test0-review

Work 04: 9/18

posted Sep 18, 2018, 9:53 AM by JonAlf Dyrland-Weaver   [ updated Sep 18, 2018, 12:46 PM ]

Write the following functions in racket:
  • discriminant
    • Has 3 parameters, representing the coefficients of a quadratic equation (i.e. ax2 + bx + c = 0)
    • Returns the value of the discriminant of the equation
      • For the less mathematically inclined: discriminant = b2 - 4ac
    • examples
      • (discriminant 4 2 2) ==> -28
      • (discriminant 2 4 2) ==> 0
      • (discriminant 5 10 3) ==> 40
  • posRoot
    • Has 3 parameters, representing the coefficients of a quadratic equation (i.e. ax2 + bx + c = 0)
    • Returns the root of the equation obtained by this formula:

    • examples
      • (root1 2 4 2) ==> -1
      • (root1 4 8 12) ==> -1.0+1.4142135623730951i
    • note: you cannot put  a - in front of a variable to make it negative (doing -x will create an error)
    • second note: part of this formula should look familiar
  • getOnesDigit
    • Has 1 parameter representing an integer.
    • Returns the ones digit of the parameter.
    • examples
      • (getOnesDigit 124) ==> 4
      • (getOnesDigit 5) ==> 5
  • disaster
    • Consider 2 trains, traveling directly towards each other at different speeds on the same track.
    • Write a function that will return how long it will take for the two trains to crash into each other
    • Has 3 parameters, the first 2 represent the speed of the trains in miles per hour, and the third represents the distance between the trains at the start in miles.
    • examples
      • (disaster 20 80 100) ==> 1
      • (disaster 4 2 30) ==> 5
    • hint: time = distance / speed

submit these as racket-2. Don't forget to include test cases.

Work 03: 9/14

posted Sep 14, 2018, 11:06 AM by JonAlf Dyrland-Weaver   [ updated Sep 16, 2018, 11:44 AM ]

Write the following racket functions. Save and submit a .rkt file with your definitions and test cases.
  • areaC
    • Has 1 parameter representing the diameter of a circle
    • Returns the area of that circle
    • Examples:
      • (areaC 20) ==> 314
      • (areaC 5) ==> 19.625
  • hypotenuse
    • Has 2 parameters representing the 2 non-hypotenuse legs of a right triangle.
    • Returns the length of the hypotenuse of the right triangle
      • Remember what your good friend Pythagoras taught you: a2 + b2 = c2
    • Examples:
      • (hypotenuse 3 4) ==> 5
      • (hypotenuse 11 60) ==> 61
  • perimFromArea
    • Has 1 parameter representing the area of a square.
    • Returns the perimeter of that square
    • Examples:
      • (perimFromArea 25) ==> 20
      • (perimFromArea 10) ==> 12.649110640673518
  • areaDonut
    • Consider a 2-dimensional donut, which is essentially a circle with a circular hole cut out of the middle.
    • Takes 2 parameters representing the diameter of the outer circle and the inner circle, respectively
    • Returns the area of that donut. 
    • Hint: you should already have written a function that finds the area of a circle
    • Examples:
      • (areaD 20 5) ==> 294.375
Submit this on the hw server under racket-1

Work 02: Express yourself

posted Sep 7, 2018, 12:52 PM by JonAlf Dyrland-Weaver

  1. Log into the Homework Server
  2. Download and install DrRacket
    • https://download.racket-lang.org
    • When you run DrRacket for the first time, it may ask you for a language, select Beginning Student. (we will be changing this through the semester)
  3. Use DrRacket to write three valid arithmetic expressions and save them in a racket file.
  4. Upload the racket file to the Homework server, under the expressions assignment.
Remember if you have any questions or troubles, check out the QAF first.

Work 01: Getting to know each other

posted Sep 6, 2018, 1:04 PM by JonAlf Dyrland-Weaver

  • Check your email for an invitation to the google group (QAF)
  • Accept the invitation.
  • Read & respond to the post titled "Welcome to the world of tomorrow"

Work 0: Getting to know you

posted Sep 5, 2018, 6:57 AM by JonAlf Dyrland-Weaver

  • There are things I need to know about you. Fill out the following form with all the information.
  • Supplies needed:
    • A notebook
      • You will have to take notes in this class, on paper (why not on these computers sitting on our desks you ask?, Here are some reasons.)
      • You may use any kind of notebook, but it must be an organized notebook, not random sheets of paper in a folder.
    • Pens and pencils
      • Have a few of each, try multiple colors to make your notes even better.
    • Access to a suitable computer
      • The programming tools we will be using in class do not require much of a computer, but you should have access to a computer that runs either:
        • MacOS
        • Linux (most flavors of linux will work)
        • Windows
      • Note that tablets/computers running iOS, android or chromeOS will probably not work well for this class.
      • Tablets running windows may work, but there still might be problems.
      • If you have any problems accessing a computer talk to me.
        • There are some computers available most periods in room 301 for student use.
        • Starting soon, room 307 will be open for the CS Dojo, providing computer access Monday-Thursday after 10th period.

1-6 of 6