Question: Need Help with Haskell code CSC 207 Assignment 1 The purpose of this assignment is to let you try on some simple Haskell programming. In


CSC 207 Assignment 1 The purpose of this assignment is to let you try on some simple Haskell programming. In United States, the Memorial Day is always the last Monday in May. For example, the Memorial Day for 2020 is May 25 while for 2021 it is May 31. Our goal is to produce a function named nenorialDate, that when passing in the year as parameter, it returns the date of the Memorial Day for that year in the form of a 3-tuple. For example, calling memorialDate with 2020 should return (2820,5,25), and calling memorialDate with 2021 should retur (2821,5,31) (note that the first value of the tuple is always same as the parameter, and the second value of the tuple is always 5 - for May) memorialDate 2828 (2020,5,25) memorialDate 2821 (2021,5,31 memorialDate 2022 (2822,5,38) To help you start, I have provided several helper functions: 1sLeap Year year. (year "nod" 4 - ) 88 (year mod 188 = ) Il year "hod" 480 8) adjust year if isleap Year year then 1 else jan1 year - (year . year div 4 - year 'div 10 year div 4ee - adjust year) "hod 7 The function isLeap Year takes a year as its parameter and returns True if that year is a leap year. It returns False otherwise The function adjust is a helper function. It takes a year as its parameter and returns 1 if that year is a leap year. It retums 0 otherwise. This function allows us to adjust our calculation to deal with the irregularity caused by leap years. The function jant takes a year as its parameter and returns the weekday (as an integer) of January 1 for that year. Note that we adapt the convention that Sunday is O, Monday is 1, Tuesday is 2...., and Saturday is 6. Here is the idea how you should proceed. If you know the weekday of January 1, you can compute the weekday of June 1. There are 151 days (or 152 days for leap years) between January 1 and June 1. The formula for this calculation is: weekday of June 1 = (weekday of January 1 + number of days in between) mod 7 Once you know the weekday of June 1, you can figure out on which days the first Monday of June and the last Monday of May are. For example, if June 1 is on Sunday, then June 2 is Monday, and it is the first Page 2 Monday of June. Going back 7 days gives the date of the last Monday in May (2-7 +31). The following table shows the details: 1 June 1 is on Then the first Monday of And the last Monday of Formula June is on June (y) May is on May (2) Sunday 0) 2 26 Monday (0) 1 25 Tuesday (2) 7 y=(8 - x) mod 7+1 31 Wednesday (3) 6 30 2y+31-7 Thursday 4) 5 29 -(8 - x) mod 7 + 25 Friday 5) 4 28 Saturday (6) 3 27 Download the file CSC20781.hs from Canvas'. The file contains the three helper functions listed above. You are going to do the followings: . (8 points) Implement the function junt that takes a year as parameter and returns the weekday of June 1 in that year. For example, juni 2821 2 since June 1, 2021 is a Tuesday. (8 points) Implement the function memorialday that takes a year as parameter and returns only the day in May on which the Memorial Day of that year is. For example, menorial Day 2021 31 since Memorial Day in 2021 is on May 31 (4 points) Implement the function memorialDate that takes a year as parameter and returns the date of Memorial Day in that year, the returned value should be in the form of a triplet. For example, memorialDate 2821 (2821, 5, 31). Additional notes You should take advantages of the helper functions provided. The process we use to solve this problem is called "stepwise refinement". That is, during each step, we develop a function that is closer to our solution and can be reused in the next step. For example, you can use the Junt function to compute memorial Day However, you should not reinvent the wheel. That is, you should not just copy the code from junt into your memorialDay function. o Instead, you should call junt in your memorial Day function implementation. The same can be said to the memorialDate function In the same sprite, you should not just copy the code from the helper functions into your code. Instead, you should be calling them in your code (if needed) o You need to demonstrate the use of the stepwise refinement to qualify for full credit. That is you should try not to duplicate code whenever possible, We have been using the nod and div functions as operators ("mod' and 'div'). There should not be any import statement used in your code. . New of the thesis The following table gives you additional testing data: If Calling Calling Calling year jun1 year memorialDay year memorialDate year is should return should retum should return 2028 1 25 (2820,5,25) 2021 2 31 (2821,5,31) 2822 3 30 (2822,5, 38) 2823 4 29 (2823,5,29) 2024 6 27 (2824,5,27) 2025 @ 26 (2825,5,26) 2826 1 25 (2826,5,25) 2027 2 31 (2827,5, 31) 2828 4 29 (2828,5,29 2029 5 28 (2829,5,28) 2838 6 27 (2838,5,27) Instruction: Complete the three functions (juni, memorialDay, and memorialDate) required and put them in the file CSC207a1.hs. You should load the file in ghci (or VinGHCi) to verify that it contains no error preventing it from loading. And you should also test your functions to make sure they retum the expected values. This assignment is graded on a 20-point scale I will be using ghci running in the Ubuntu environment to test your implementation You will lose 10 points if your file cannot be loaded (for any reason). The remaining 10 points may be awarded based on how close your implementation is comparing to the correct solution. The points distribution will be 4 points for jun1,4 points for memorialDay, and 2 points for memorialDate. Submit the file csc2e7a1.hs to Canvas. The due date for this Assignment is Sunday February 14. CSC 207 Assignment 1 The purpose of this assignment is to let you try on some simple Haskell programming. In United States, the Memorial Day is always the last Monday in May. For example, the Memorial Day for 2020 is May 25 while for 2021 it is May 31. Our goal is to produce a function named nenorialDate, that when passing in the year as parameter, it returns the date of the Memorial Day for that year in the form of a 3-tuple. For example, calling memorialDate with 2020 should return (2820,5,25), and calling memorialDate with 2021 should retur (2821,5,31) (note that the first value of the tuple is always same as the parameter, and the second value of the tuple is always 5 - for May) memorialDate 2828 (2020,5,25) memorialDate 2821 (2021,5,31 memorialDate 2022 (2822,5,38) To help you start, I have provided several helper functions: 1sLeap Year year. (year "nod" 4 - ) 88 (year mod 188 = ) Il year "hod" 480 8) adjust year if isleap Year year then 1 else jan1 year - (year . year div 4 - year 'div 10 year div 4ee - adjust year) "hod 7 The function isLeap Year takes a year as its parameter and returns True if that year is a leap year. It returns False otherwise The function adjust is a helper function. It takes a year as its parameter and returns 1 if that year is a leap year. It retums 0 otherwise. This function allows us to adjust our calculation to deal with the irregularity caused by leap years. The function jant takes a year as its parameter and returns the weekday (as an integer) of January 1 for that year. Note that we adapt the convention that Sunday is O, Monday is 1, Tuesday is 2...., and Saturday is 6. Here is the idea how you should proceed. If you know the weekday of January 1, you can compute the weekday of June 1. There are 151 days (or 152 days for leap years) between January 1 and June 1. The formula for this calculation is: weekday of June 1 = (weekday of January 1 + number of days in between) mod 7 Once you know the weekday of June 1, you can figure out on which days the first Monday of June and the last Monday of May are. For example, if June 1 is on Sunday, then June 2 is Monday, and it is the first Page 2 Monday of June. Going back 7 days gives the date of the last Monday in May (2-7 +31). The following table shows the details: 1 June 1 is on Then the first Monday of And the last Monday of Formula June is on June (y) May is on May (2) Sunday 0) 2 26 Monday (0) 1 25 Tuesday (2) 7 y=(8 - x) mod 7+1 31 Wednesday (3) 6 30 2y+31-7 Thursday 4) 5 29 -(8 - x) mod 7 + 25 Friday 5) 4 28 Saturday (6) 3 27 Download the file CSC20781.hs from Canvas'. The file contains the three helper functions listed above. You are going to do the followings: . (8 points) Implement the function junt that takes a year as parameter and returns the weekday of June 1 in that year. For example, juni 2821 2 since June 1, 2021 is a Tuesday. (8 points) Implement the function memorialday that takes a year as parameter and returns only the day in May on which the Memorial Day of that year is. For example, menorial Day 2021 31 since Memorial Day in 2021 is on May 31 (4 points) Implement the function memorialDate that takes a year as parameter and returns the date of Memorial Day in that year, the returned value should be in the form of a triplet. For example, memorialDate 2821 (2821, 5, 31). Additional notes You should take advantages of the helper functions provided. The process we use to solve this problem is called "stepwise refinement". That is, during each step, we develop a function that is closer to our solution and can be reused in the next step. For example, you can use the Junt function to compute memorial Day However, you should not reinvent the wheel. That is, you should not just copy the code from junt into your memorialDay function. o Instead, you should call junt in your memorial Day function implementation. The same can be said to the memorialDate function In the same sprite, you should not just copy the code from the helper functions into your code. Instead, you should be calling them in your code (if needed) o You need to demonstrate the use of the stepwise refinement to qualify for full credit. That is you should try not to duplicate code whenever possible, We have been using the nod and div functions as operators ("mod' and 'div'). There should not be any import statement used in your code. . New of the thesis The following table gives you additional testing data: If Calling Calling Calling year jun1 year memorialDay year memorialDate year is should return should retum should return 2028 1 25 (2820,5,25) 2021 2 31 (2821,5,31) 2822 3 30 (2822,5, 38) 2823 4 29 (2823,5,29) 2024 6 27 (2824,5,27) 2025 @ 26 (2825,5,26) 2826 1 25 (2826,5,25) 2027 2 31 (2827,5, 31) 2828 4 29 (2828,5,29 2029 5 28 (2829,5,28) 2838 6 27 (2838,5,27) Instruction: Complete the three functions (juni, memorialDay, and memorialDate) required and put them in the file CSC207a1.hs. You should load the file in ghci (or VinGHCi) to verify that it contains no error preventing it from loading. And you should also test your functions to make sure they retum the expected values. This assignment is graded on a 20-point scale I will be using ghci running in the Ubuntu environment to test your implementation You will lose 10 points if your file cannot be loaded (for any reason). The remaining 10 points may be awarded based on how close your implementation is comparing to the correct solution. The points distribution will be 4 points for jun1,4 points for memorialDay, and 2 points for memorialDate. Submit the file csc2e7a1.hs to Canvas. The due date for this Assignment is Sunday February 14
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
