A.
If you do the extra credit, submit it as the same files listed on the
write-up (i.e., as you would for the basic part). You MAY NOT submit 2
different versions.
A.
When working with the basic assignment, you can change things like the
defined constants, but you shouldn't change what functions
are given (you can change what those functions do and can add helper
functions).
As for the extra credit, you may even have to change what functions are used (i.e., more radical changes in the structure of the program will be allowed).
Is that correct?if (IsLeapYear(year) == 0) { ... }
A.
Well...that's ok, but it's better to do:
if (!IsLeapYear(year)) { ... }
which reads very naturally as "if not is a leap year". Likewise, to test for a leap year, you'd do:
if (IsLeapYear(year)) { ... }
rather than:
if (IsLeapYear(year) == 1) { ... }
The == 0
== 1
IsLeapYear
) can make your
code more understandable.
A.
For example, if you want to know what day February 1, 1902 starts on, you
can count the number of days between 1/1/1900 and 2/1/1902, which is:
Then, you have to figure out: "If 1/1/1900 started on a Monday, what day of the week is 365x2+31 days later?"365 (days in year) x 2 (years, i.e., 1900 and 1901) + 31 (days in the months before Feb).
Of course, sometimes February has 29 days.
A.
Don't use screen coordinates, just use add spaces.
A.
You need it to say, "It is a leap year if it is divisible by 4 and it is
not the case that it is a century unless it is every 4th century."
You'll want to ask whether a year is "evenly divisible" (does a certain
number go into the year without a remainder) or "not evenly divisible"
in your condition.
Keep in mind that &&
takes precedence over
||
, unless you add parentheses.
A.
It must just be that your machine uses smaller (2 byte) integers that
cannot handle numbers that large.
In general you don't want a simple calculation like that, since some years have 366 days.
Instead, start with the initial day of week (for 1/1/1900), then add one year. After you add this first year, figure out what day of week that gives. Next, add the 2nd year and then figure out what day of week that gives. And so on, till you reach the year you want. Certainly, what I am describing to do for each year is the same, so you can write some code that "does something many times" to figure out the first day of the year you want.
A.
The key is that you know how many days are in each month...
If you get to the year you want, say Jan 1 1902, and then you want to know what day April starts on, you can go through how many days there are in Jan, then Feb (28 or 29), then March. After skipping over those 3 months, you'll be at April 1st.
So, the only part you need to figure out is if Jan 1 1902 was a Wed and if you add 31 days for January, what day of week is Feb 1 1902. Then, if you add the 28 days for Feb, what day of the week do I end up on for Mar 1 1902, etc.
Ask yourself (suppose Sunday is defined as 0), and so we start on a Wed = 3. What day of week (0 thru 6) is 31 days later?
A.
First, they test the opposite truth condition (which is a separate
issue). Nonetheless, the last form is preferred since it is more
readable than the first (since the first would evaluate to 0 (false)
when the year IS divisible by 4). You can always use the "not equals"
operator if needed in such an expression too.