Pure Programmer
Blue Matrix


Cluster Map

Project: Ordinal Date (Revisited)

Write a function to compute the ordinal date. The function should have arguments for month, day and year. Write a second function to determine if the year is a leap year that is used by the first function. Use preconditions to validate the function arguments and postconditions to check the result. You can compute the ordinal date with the following formula:

  • for January: d
  • for February: d + 31
  • for the other months: the ordinal date from March 1 plus 59, or 60 in a leap year
  • where the ordinal date from March 1 is: floor(30.6m-91.4)+d

    and a year is a leap year if it is evenly divisible by 4 but not evenly divisible by 100 unless it is evenly divisible by 400.

See [[Ordinal Date]] and [[Leap Year]]

Output
$ swiftc OrdinalDate2.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc OrdinalDate2.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc OrdinalDate2.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc OrdinalDate2.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc OrdinalDate2.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution