Skip to Content
Beginning C# 3.0
book

Beginning C# 3.0

by Jack Purdum
May 2008
Beginner
550 pages
13h 22m
English
Wrox
Content preview from Beginning C# 3.0

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Navigating the Metaverse

Navigating the Metaverse

Cathy Hackl, Dirk Lueth, Tommaso Di Bartolo, John Arkontaky, Yat Siu
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
Capitalism at Risk

Capitalism at Risk

Joseph L. Bower, Herman B. Leonard, Lynn S. Paine

Publisher Resources

ISBN: 9780470261293Purchase book