Courses‎ > ‎Intro to CS - Half Year‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

Work 09: 9/27 (pair programming)

posted Sep 27, 2018, 11:02 AM by JonAlf Dyrland-Weaver   [ updated Sep 27, 2018, 12:02 PM ]
You and your partner must submit this at the end of class! The HW server due date will be 4pm today. If you are absent, you can do this at home, it will show up as late on the server,  just add a comment when you submit on the server stating that you were not in school and as such could not finish it by 4pm. 

Note the lack of examples, you and your table buddy will need to come up with test cases. Make sure you come up with enough cases to test all possible outcomes.

Make liberal use of the DrRacket tools we discussed yesterday (stepper and black highlighting)
  • areaSC
    • Has 2 parameters, the first represents either the length of one side of a square or the length of the radius of a circle. The second parameter will be 0 if the intended shape is a square or any other number if the intended shape is a circle.
    • If the second argument is 0, should return the area of a square using the first parameter.
    • If the second argument is ANY OTHER NUMBER, should return the area of a circle using the first parameter.
  • militaryTime
    • Takes 2 arguments, the first represents an hour in 12-hour format, the second will be 0 if the hour is AM or 1 (or any other number) if the hour is PM.
    • Should return the correct hour in 24-hour format (i.e. 1am = 1, 12am = 0, 1pm = 13, 4pm = 16 ...)
  • closerNumber
    • Has 3 numbers as parameters.
    • Returns the first number if it is "closer" to the third than the second number is to the third.
    • Returns the second number if it is "closer" to the third than the first number is to the third.
    • By closeness we are referring to the distance between 2 numbers on a number line.
      • The distance between 16 and 10 is 6
      • The distance between 7 and 10 is 3
      • 7 is closer to 10 than 16
  • closerPoint
    • Takes 6 arguments, each pair of parameters represents the (x, y) coordinates of a point on the cartesian plane.
    • Returns 1 if the first point is closer to the third than the second is to the third.
    • REturns 2 if the second point is closer to the third than the first is to the third.
    • Use the distance formula to determine closeness:
      • d = (sqrt (x3 - x1)2 + (y3 - y1)2 )
      • where the 2 points are (x1, y1) and (x3, y3)
  • Challenge Problem
    • If you have finished the above problems in class, try this on for size.
    • numDigits
      • Takes a single positive integer as an argument.
      • Returns the amount of digits in that number.
      • helpful hints
        • Do not use any functions that we have not covered in class.
        • For what numbers is this problem trivially easy to solve? How can you tell if a number fits into that category?
        • If a number is not in the trivially easy category, how can it become so? What numbers are almost as easy?
        • Solving this should involve liberal usage of keys to success.
Submit this under: if-pair