Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are a few pointers. Note: For this exercise I will assume that when <code>N=0</code> that <code>Y % 400 == 0</code>.</p> <p><strong>1:</strong> There are a fixed number of days in each 400 year period <code>(400 * 365) + 100 + 1 - 4</code>.</p> <p>The <code>+100</code> is for the leap years, the <code>+1</code> is for the leap year every 400 years and the <code>-4</code> is for not having a leap year every 100 years.</p> <p>So your first line of code will be:</p> <pre><code>GetDate(int N, int &amp;Y, int &amp;M, int &amp;D) { const int DAYS_IN_400_YEARS = (400*365)+97; int year = (N / DAYS_IN_400_YEARS) * 400; N = N % DAYS_IN_400_YEARS; </code></pre> <p><strong>2:</strong> You can make your life a great deal easier if you treat March 1st as the first day of the year</p> <p><strong>3:</strong> Adding to the code in <strong>(1)</strong>, we can work out the year. Bear in mind that every fourth century begins with a leap year. So you can complete the calculation of the year with the following:</p> <pre><code> const int DAYS_IN_100_YEARS = (100*365) + 24; year += 100 * (N / DAYS_IN_100_YEARS) + (N &lt; DAYS_IN_100_YEARS ? 1 : 0); // Add an extra day for the first leap year that occurs every 400 years. N = N - (N &lt; DAYS_IN_100_YEARS ? 1 : 0); N = N % DAYS_IN_400_YEARS; </code></pre> <p><strong>4:</strong> Now you've sorted out the years, the rest is easy as pie (just remember <strong>(2)</strong>, and the process is easy).</p> <p>Alternatively you could use <a href="http://www.google.co.uk/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CGQQFjAA&amp;url=http%3A%2F%2Fwww.boost.org%2Flibs%2Fdate_time%2F&amp;ei=oiINUNa5Eoqp0AWYzri8Cg&amp;usg=AFQjCNHqzBUilIMg5xFhJj_3uc-fjKAs-Q&amp;sig2=YJnZHL3NW8CwL3cmHq6QsA" rel="nofollow">boost::date</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload