Homework 4
Due Date: Wednesday February 5, 9pm
Purpose To design and use structured, hierarchical and union data; to practice writing templates
Expectations
You should submit three .rkt files, each containing your response to one of the 3 exercises below, via the Handin Server; the three files should be named "HW4-1.rkt", "HW4-2.rkt", and "HW4-3.rkt". We accept NO email submissions. Failure to submit a .rkt file will result in a 0 for that part.
You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.
Your code must conform to the guidelines outlined in the style guide on the course website. Pay particular attention to the list of prohibited functions in the guide. The style guide may be updated as the semester progresses so please remember to read it before submitting each assignment.
Unless otherwise stated, all data and functions you design must be designed according to the data and function design recipes (DR), resp., following all four steps in each case, with the exception of functions that call big-bang, for which you need no check-expects, as justified in class. All functions used inside big-bang must have check-expects, along with the other three steps of the design recipe.
We will not walk you through the DR steps in each problem, nor request them individually and explicitly. Instead, review the data and function design recipes before starting this homework, and then have these recipes handy.
-----------------------------------------------------------------------------
You are designing a database for people affiliated with Northeastern. There are three types of entities at the university we want to model: students, faculty, and staff. You will design a separate data type for each of these categories, named Student, Faculty, and Staff. All three will be structured data types, meaning you will first do a define-struct for each. You will then build on top of this a fourth data type named NEUPeep, which will be a union of the three previously defined types of Northeatern people. Details on what kind of component information you need to model for each is detailed below.
For each data type you design, make sure you do a thorough job on all four parts of the design recipe–you will be graded critically on each. Choose your field names, and the types you specify for each field, carefully. Most of the data designs will require a define-struct for that type– don’t forget to do those.
You will then design some functions that process the data types you defined.
Exercise 1 Designing Utility Data
Start by designing two utility data types and functions that will be useful in your main task:
Design the date type Name:
This should have fields for holding a person’s first name, middle initial, and last name.
Design the function name->string:
Take a Name, and produces the name as a string with the format "<FIRSTNAME> <MIDDLE-INITIAL>. <LASTNAME>"; for example, "John B. Doe"
Design the date type Month:
This is used to represent a month by its full name, like "January"; what type should this field be? (Hint: it starts with an ’e’ (and ends with "numeration")) Don’t forget the template.
Design the function month-abbrev:
This takes a Month, and produces the month formatted as a 3-character abbreviation, like "Jan".
Design the data type Date:
This should have fields for holding the desired month, day-of-month, and year. The month should be of type Month (defined above); to keep it simple, the day and year fields can be simple numbers–you don’t have to specify any range.
Design the function date->string:
This takes a Date, and produces the date as a string with the format: "Jan. 1, 2025" (the BSL function number->string might be useful).
Exercise 2 Designing the Main Data
In this part, you will design the data to support each of your entity types. To the greatest degree possible, reuse the Name and Date data types and functions you designed for the previous exercise.
Design the data type Student:
A Student will be structured data that has fields representing the student’s name, the date they first enrolled, and the tuition they pay per semester.
Design the function end-of-enrollment:
This produces the date the student’s 4-year stay ends, starting from their enrollment date. This is not their graduation date.
Design the function annual-tuition:
This produces the amount of tuition a student pays per year, assuming they register for that standard fall and spring semesters.
Design the data type Faculty:
A Faculty member will be structured data that has fields representing the professor’s name, the date their current employment contract started (so, this is for non-tenure track professors), their contract term (how long their contract runs from their contract start date, in years), and their annualized salary rate.
Design the function end-of-contract:
Produces a Date representing when their current employment contract ends: contract-start-date + contract-term
Design the function takehome-salary:
Note that this is not the same as their annualized salary rate which is what’s stored in the data; unless the faculty member takes on an optional summer teaching course load, their take-home is 75% of the annualized salary rate. That is what this function calculates.
Design the data type Staff:
A Staff member will be structured data that has fields representing the employee’s name, the date they were hired, and their hourly salary.
Design the function annual-compensation:
This function calculates their annual salary from their hourly salary. You can assume that they are a full-time staff member, who works 50 weeks a year, 40 hours a week; so, 2000 hours per year.
Exercise 3 Designing the Union
In this final part, you will design th NEUPeep data type, which will be a union that allows for the various NEU people defined above. Make sure you correctly define the union type, and that you follow every step of the design recipe carefully. You will then design the functions specified below to work with this union. Note that for the functions you design, you must follow the template: if that says you call a template for another defined type, you must design and call a helper function defined on that type! Note that much of the work you did in the previous exercise will be helpful here.
Design the data type NEUPeep:
This is a data type that consists of a union of the Student, Faulty, and Staff data types previously defined. Make sure the template is correct (review the lecture notes on the design recipe for templates).
Design the function end-date:
This function should produce a formatted string representing the date that the given NEUPeep’s current status at Northeastern ends: for a student, it should be 4 years after their enrollment; for faculty, it should be when their current contract ends; and for staff, you should produce the string "<UNKNOWN>".
Design the function annual-budget-cost:
This function calculates the per-year cost of that person to the university. For a faculty member, it would be their annual take-home pay; for a staff member, it would be what they earn in a year, assuming the standard 2000 hours per year for a full-time employee. For a student, you would use their tuition costs, assuming the standard fall+spring semester matriculation (so, no summer). IMPORTANT: note that for the purposes of this function, student tuition is revenue, so the budget cost should be negative.
This might sound repetitive, but you must follow the template (and the template must follow the template recipe!). That implies that splitting out some of the code to helper functions is mandatory in certain cases!