CPSC 110-08: Computing on Mobile Phones
Spring 2012

Homework: Leap Year
Due: Wednesday 2/29 (before class)

CS Principles

This activity addresses the concept of algorithms, abstraction and programming. It focuses, in part, on the following learning objectives:

Introduction

2012 is a Leap Year. But what exactly is a leap year and what years are leap years?

In this homework (and follow-up in class assignment) we will look at the definition of a leap year and turn it into an algorithm to test whether any given year is a leap year or not.

About Leap Years

A leap year consists of 366 (rather than 365) days, with the extra day coming on February 29. The purpose of the extra day is to bring the calendar more in line with the time it takes the earth to make a full orbit around the sun, which takes 365.242199 days. The leap year adjustment occurs approximately (although not exactly) every 4th year.

A closer approximation is provided by the following rule, which was adopted as part of the Gregorian Calendar:

Leap Year Definition. A year is a leap year if it is evenly divisible by 4 but not evenly divisible by 100 unless it is also evenly divisible by 400. So 1996 was a leap year. But 1900 was not a leap year because, although it is divisible by 4, it is also divisible by 100 and not by 400. 2000 is a leap year because it is divisible by 400.

Here are some interesting facts about leap years from timeanddate.com:

Homework

Let's build an app to figure out if a a year entered by the user is a Leap Year.

Getting Help

The TAs are available on Sunday, Tuesday, and Thursday evenings in MCEC 136. See the syllabus for their hours.

In Class

We'll finish the LeapYear app.