The months vector is representing each month and how many days are in that
month.
(define months (vector 0 31 28 31 30 31 30 31 31 30 31 30 31))
31 would be 1 or January (since all indexes start at 0, there is no 0th
month), 28 would be 2 or February, and so forth and so on. So if we did
(vector-ref months 1) -> 31
I know how to read code, but writing it is my problem. This is my first
coding class. So I don't know if I can write a parameter in the definition
using vector-ref....like
(define (number-days-in-month year (vector-ref months x)
(cond
[if (= y leap-year?
29
28
Or even with that above, how would it know that leap-year? only effects
month 2. I am highly confused unfortunately.
On Sunday, April 19, 2020 at 12:59:48 PM UTC-7, johnbclements wrote:
>
> First off: you’re very close.
>
> Thing two: I think you need a clearer comment on the meaning of the
> “months” vector. Your description does not actually say what the vector
> represents or contains.
>
> Thing three: Here’s my question to you. Suppose that I tell you a year and
> a month and the result of (vector-ref months x).
>
> To be more concrete, suppose I tell you the year is 2234 and the month is
> 4 and the result of (vector-ref months x) is 30. How many days would that
> month have? Can you explain how to compute the answer for each of the test
> cases below?
>
> John Clements
>
> > On Apr 19, 2020, at 11:50, Suz Renae <[email protected] <javascript:>>
> wrote:
> >
> > I am new to racket (first year student) and since class has been pushed
> to online only, I am having a harder time.
> >
> > We are currently working on vectors and hash tables. I feel like I keep
> overthinking it and keep getting stuck. I know that the first parameter in
> the function will be the year and the second will be the (vector-ref months
> x)that I pull from the defined vector.
> >
> > The question I am having a hard time with and what I have actually done
> below.
> >
> > Create a function that calculates the number of days in a month given a
> year and a month
> > • Call the function number-of-days-in-month, and it's signature
> is number, number -> number
> > • Example:
> > (number-days-in-month 2016 1) -> 31
> > (number-days-in-month 2016 11) -> 30
> > (number-days-in-month 2016 12) -> 31
> > (number-days-in-month 1900 2) -> 28
> > (number-days-in-month 2000 2) -> 29
> > (number-days-in-month 2016 2) -> 29
> > (number-days-in-month 2200 2) -> 28
> > What I have so far...
> >
> > ;Leap Year
> > (define (leap-year? year)
> > (and (zero? (modulo year 4))
> > (or (not (zero? (modulo year 100)))
> > (zero? (modulo year 400))
> > )
> > )
> > )
> >
> > ;Months with days vector, beginning at an index of 0 since there is not
> 0th month
> > (define months (vector 0 31 28 31 30 31 30 31 31 30 31 30 31))
> >
> > (check-expect(number-days-in-month 2016 1)31)
> > (check-expect(number-days-in-month 2016 11)30)
> > (check-expect(number-days-in-month 2016 12)31)
> > (check-expect(number-days-in-month 1900 2)28)
> > (check-expect(number-days-in-month 2000 2)29)
> > (check-expect(number-days-in-month 2016 2)29)
> > (check-expect(number-days-in-month 2200 2)28)
> >
> > I need help with building the actual function and what conditionals I
> should be using.
> >
> > (define (number-days-in month ?? ??)
> > (cond
> > [
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected] <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/5d017eef-b235-4a8b-94fa-fe1e3f7b766e%40googlegroups.com.
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/e057a97b-2ee0-4114-abd4-b2fc208dc3fa%40googlegroups.com.