Purpose: The purpose of this lab is to practice designing and programming with structures and union data.
Exercise 1 Design a data definition for a time of day. Your definition must keep track of the hours, minutes, and whether the time is in the morning or afternoon. Be sure to follow all the steps of the data design recipe.
Exercise 2 Design the function set-to-hour which takes a time of day (as defined in the previous exercise) and sets the minutes to zero. Be sure to follow all the steps of the function design recipe.
Please submit the above exercise to the handin server by 10pm EDT on the day of lab. Please make sure the code you submit runs with no errors (this means you will need some of your work from the previous exercise as well).
Exercise 3 Joe Exotic needs your help to keep track of his many, many tigers. Each tiger has a name, an age, and a time of day that they are fed. Design data for a Tiger. Be sure to follow all the steps of the data design recipe.
Exercise 4 Now that Joe is... busy, someone else has to take care of his tigers! Carole decides to save the day but Carole is also super busy so she can only feed tigers every hour on the hour. She needs to update the database so that tigers which are normally not fed on the hour have a new feed time. Design the function set-feed-time which takes a Tiger (as defined in the previous exercise). If the tiger is normally fed at an hour mark (e.g. 2pm exactly) the tiger will be returned as is. If the tiger is normally fed at any other time, the function will return a new tiger with the same name and age but which is fed at the hour mark before its normal feed time. For example, if the tiger is normally fed at 11:45am it will now be fed at 11am instead. Be sure to follow the template!
Exercise 5 Northeastern has several kinds of employees: hourly, salaried, and tenured. For hourly employees we need to keep track of their hourly wage and how many hours they have worked this week. For salaried employees we need to keep track of their annual salary and how many vacation days they have remaining. For tenured employees we just keep track of their name. Design data to represent an Employee at Northeastern. Be sure to follow all the steps of the data design recipe.
Exercise 6 Design the function get-weekly-wage which takes in an Employee (as defined in the previous exercise) and gets their weekly wage. For an hourly employee it multiplies their hourly wage by the number of hours they worked this week. For salaried employees it divides their annual salary by 52 (the number of weeks in a year). For tenured employees it just produces the String "a lot". Be careful with your signature. What kind(s) of data are we producing?
Exercise 7 How many data definitions did you design in Exercise 5? There are two ways to do this problem: one where you design only one definition and one where you design data for each subtype and a definition to combine them. How does the template differ if you change your data design? How does your function in Exercise 6 change?
If you had trouble finishing any of the exercises in the lab or homework, or just feel like you’re struggling with any of the class material, please feel free to come to office hours and talk to a TA or tutor for additional assistance. We love to teach and you will learn. It’s symbiotic!