## CS 115 Lab 9 Leap Year (Individual)

### 50 Points

Due on Sunday November 5 midnight

This is an individual lab. Every student is expected to do the activity by themselves.

Individual Submit link: Submit your program with this link. Use the Lab 9 and Code menu choices.

Educational goals of this lab - verify that every student can

• use if statements
• write a boolean function
• write sentinel logic

Preparations: Watch these videos

(30 points) Problem #1: Leap Year Function

• Write a function that will accept one integer as a parameter which represents a year, and will return True if the year is a leap year and False otherwise.
• A year is a leap year if it is evenly divisible by 4, unless it is divisible by 100, in which case it must also be divisible by 400. That is, 1996 is a leap year because it is divisible by 4 and not 100, 1997 is not a leap year because it is not divisible by 4, 2000 is a leap year because it is divisible by 100 and 400, and 2100 will not be a leap year because it is divisible by 100 but not 400.
• You want to write this to work as efficiently as you can, no redundant tests.
• Write this function with only ONE return statement. You will need another variable to hold results through the function body, then return it at the end.
• Hint: the mod operator is useful here.
• If you need help with testing this, go to this web page for a leap year calculator.
• As usual, document your function!

(20 points) Problem #2: Driver with Sentinel Logic

• Write a main function to act as a driver for the leapyear function. It should ask the user repeatedly for a year and call the function properly using the year as the argument. It should output "yes, it is a leap year" if the user's input was a leap year, "no, it is not a leap year" if it was not. It should repeat this action until the user enters a -1. Note that the -1 is NOT used as an argument with the function. Hint: Sentinel logic and a while loop!
• As usual, document your function!
• Sample run
```Enter a year (-1 to quit): 2000
Yes, it is a leapyear
Enter a year (-1 to quit): 2100
No, it is not a leapyear
Enter a year (-1 to quit): 1996
Yes, it is a leapyear
Enter a year (-1 to quit): 1600
Yes, it is a leapyear
Enter a year (-1 to quit): -1
```
• Submit your finished program with the link at the top of the page. Use the Lab 9 and Code menu choices.