9.4. The clsDates Design

Now let's use some of our design ideas to implement the design for clsDates. The code for clsDates is shown in Listing 9-4.

Example 9-4. Listing 9-4
using System;
using System.Collections.Generic;
using System.Text;

public class clsDates
{
    // =============== symbolic constants ==================

    // =============== static members ======================
    private static int[] daysInMonth = { 0, 31, 28, 31, 30, 31, 30, 31,
                                        31, 30, 31, 30, 31};

    // =============== instance members =====================
    private int day;
    private int month;
    private int year;
    private int leapYear;

    private DateTime current;

    // =============== constructor(s) ======================

    public clsDates()
    {
        current = DateTime.Now; // Sets DateTime to right now
    }
    // =============== property methods =====================

    // =============== helper methods =======================

    // =============== general methods ======================

    /*****
     * Purpose: To determine if the year is a leap year. Algorithm
     *          taken from C Programmer's Toolkit, Purdum, Que Corp.,
     *          1993, p. 258.
     *
     * Parameter list:
     *    int year      the year under consideration
     *
     * Return value:
     *    int           1 if a leap year, 0 otherwise
     *****/
    public int getLeapYear(int year)
{ if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return 1; // It is a leap year else return 0; // Nope. } /***** * Purpose: To determine the date for Easter given a year. Algorithm * taken from C Programmer's Toolkit, Purdum, Que Corp., * 1993, p. 267. * * Parameter ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.