Assignment.4.Solutions.cs2102

Assignment.4.Solutions.cs2102 - CS 2102 - 2009 DISCRETE...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 2102 - 2009 DISCRETE MATHEMATICS 1 Assignment 4 Solutions 1. Write a natural language specification for a program to determine whether a year is a leap year. Check Wikipedia to make sure you have the correct definition of a leap year. Answer: A year is a leap year either: (a) if it is divisible by 400; or (b) divisible by four but not by 100. 2. Write a predicate that is true for a year that is a leap year and false otherwise. Assume you have the operator “rem” where x rem y gives the remainder of dividing x by y. Answer: year : è ((year rem 400) = 0) Ú (((year rem 4) = 0) Ù ((year rem 100 μ 0))) 3. Using set comprehension, define the set of leap years. Answer: leapyears == {y : ¤ | ((y rem 400) = 0) Ú (((y rem 4) = 0) Ù ((y rem 100 μ 0)))} 4. Write a formal specification in Z for a program to compute the leap years for the century beginning in the year 2102. Answer: years : ¡ è years’ = {y : è | (y rem 1000 = 0) Ú ((y rem 4 = 0) Ù (y rem 100 μ 0)) Ù y    y   LeapYears 5. Write a natural language
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/10/2009 for the course CS 2102 taught by Professor Knight during the Spring '08 term at UVA.

Page1 / 2

Assignment.4.Solutions.cs2102 - CS 2102 - 2009 DISCRETE...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online