Thank you for replying. The course is at Mesa College in San Diego. Intro to Computer Science. Not as easy as I thought it would be.
On Sunday, April 19, 2020 at 12:58:20 PM UTC-7, Jon Zeppieri wrote: > > Well, this all looks very familiar. Can I ask where this course is > offered? > > > Okay, let's start with part of the problem definition: > > > 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 > > Let's put these two statements together. In fact, let's start with the > second one, specifically: "[the function's] signature is number, > number -> number." That means the function takes two arguments, both > of which are numbers, and it returns a number. That's not very > informative. If that were all the information you had, you might start > your function definition like this: > > (define (number-of-days-in-month one-number a-second-number) > [ somehow calculate yet a third number ]) > > But the previous sentence gives you more information. It says, "[the > function] calculates the number of days in a month given a year and a > month." This is a actually a more specific version of what the > signature tells you. Let me reverse the order of the statement to make > this more clear: "Given a year and a month, the function calculates > the number of days in the month." > > So the "numbers" in the signature aren't any old numbers. Let's look > at the signature again: > number, number -> number > > The things to the left of the arrow are what the function is given. > The problem says that the function is given a year and a month. So > let's restate the signature, adding that information: > year-number, month-number -> number > > The thing to the right of the arrow is what the function calculates, > in this case the number of days in the given month. (This is where > things get a little complicated. You're trying to calculate the number > of days in the month that you're given. Fine, so why are you given a > year in addition to the month? The answer to this question will help > you when you start to fill in your function body. By the way, I'm not > trying to be patronizing. I'm pretty sure you know the answer to this > question, given what you wrote in your message. But it may help to > think about it this way.) So let's add this information to the > signature: > > year-number, month-number -> number-of-days-in-month > > Or, in English: "`number-of-days-in-month` is a function that takes a > year number and a month number and returns the number of days in the > month." If you're skeptical of my claim that this is more specific > than the signature we started with, consider that not all numbers are > valid year-numbers or month-numbers. For example, 2.5 isn't the number > of a year (well, not in the Gregorian calendar, anyhow), and -20 isn't > the number of a month. > > So now at least, we should be able to replace the "??"s in your > function skeleton: > > (define (number-days-in-month year-number month-number) > (cond > [ > > As for the conditional in the function body, go back to the question I > posed above: why are you given a year-number in addition to a > month-number if you're just supposed to find the number of days in a > month? > > - Jon > > > > On Sun, Apr 19, 2020 at 2:50 PM 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/99f89998-201e-4eb7-9667-999284980239%40googlegroups.com.

