Frequently Asked Questions about HW2


Q.
For the extra credit part, can we submit 2 separate programs, one for the basic part and one for the extra credit?

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.


Q.
Can we change the defined constants and fundamental workings of your pre-written procedures?

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).


Q.
When I want to test for a year not being a leap year, I use something like:
if (IsLeapYear(year) == 0) {
  ...
}
Is that correct?

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 and == 1 stuff is less readable in these cases. This demonstrates how nicely-named functions (like IsLeapYear) can make your code more understandable.


Q.
What exactly should the function "FirstDayOfMonth" do? What does it mean when it says, "... counts forward from January 1, 1900, which was a Monday..."?

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:

365 (days in year) x 2 (years, i.e., 1900 and 1901)
+ 31 (days in the months before Feb).
Then, you have to figure out: "If 1/1/1900 started on a Monday, what day of the week is 365x2+31 days later?"

Of course, sometimes February has 29 days.


Q.
How do we indent and/or align the weekdays...can we use the screen x and y coordinates?

A.
Don't use screen coordinates, just use add spaces.


Q.
I'm having some trouble with my leap year condition?

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.


Q.
When I multiply two numbers (e.g., 365*99) on my PC, I get a weird result...What should I do since I need calculations like this to figure out the weekday that some year starts at?

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.


Q.
I've figured out how to get to the first day of week of the year I want, but then am having trouble getting to the correct month?

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?


Q. [New]
Is (year % 4) or (year % 4 == 0) better?

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.


BU CAS CS 113 - FAQ - HW2