CS 2135 (C03) Homework 2: Lists

Due: September 11 (Thursday) at 11:59pm via turnin (assignment name hwk2).

Assignment Goals

To make sure you can

In your solutions to these problems, do not worry about efficiency of your code. Aim for code that follows the templates over code that is clever for the sake of being fast.

Set DrScheme to "Intermediate Student with lambda" language level for this assignment.


The Assignment

A professional bicycling organization wants programs to track riders' performances in events. A rider's result for an individual event consists of four pieces of information: the name of the event, the time (number of minutes) it took the rider to complete the event, the number of points the rider earned for mountain climbing, and the number of points the rider earned for sprinting. For each rider, the organization wants to store their first and last names, sponsoring team name, and a list of their recent results. The organization's roster consists of a list of riders.

  1. Develop a data model and data definitions (with examples) for lists of riders. Include definitions and examples for all needed lists and structures.

  2. Write the template for programs over list-of-riders.

  3. Write a program total-mtn-points that takes a list of results and returns the total number of mountain points stored in those results.

  4. Write a program total-sprint-points that takes a list of results and returns the total number of sprint points stored in those results. Share common code between this problem and the previous one [you may not be able to implement the shared version until after Monday's lecture -- you can do the problems first without sharing, then modify them with sharing after we cover the material in class.]

  5. Write a program any-pointless? that takes a list of riders and returns a boolean indicating whether the list contains a rider who has no points (mountain or sprint) in any event.

  6. Write a program riders-on-team that takes a team name and a list of riders and returns a list of last names of riders on the given team.

  7. Write a program add-result that takes a rider's last name, team name, race name, time, mountain points, and sprint points, as well as a list of riders, and produces a list of riders. In the returned list, the rider with the given last name and team should have an additional result with the other input information (any order in the result list is fine); no information should be lost from the input list.

  8. [Optional, but you will need the information in italics for problem 9] The organization uses different metrics (scoring functions) for ranking riders. One set of metrics rates riders based on their overall times and points earned in the two categories. Write a program make-weight-result-func that takes in two weighting factors (one for each of mountain and sprinting points) and produces a function that takes a result and produces the score for that result: the score is produced by subtracting both the mountain points times the mountain weight and the sprinting points times the sprinting weight from the time in the result (this means that a low score is better in this scoring metric).

  9. Give Scheme expressions that produce two lists of riders, sorted according to the following functions: one sorted in decreasing order of total mountain points, and one sorted in increasing order of weighted score. The weighted score for a rider is the sum of the weighted score of that rider's results, where the results weight each set of points at 20%. Develop helper functions as needed for this problem. Your two expressions should be able to share a single sorting routine. You may not use DrScheme's built-in sorting functions, but you may adapt or use any sorting functions covered in class.


What to Turn In

Turn in a single file hwk2.ss (or hwk2.scm) containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.


Guidelines


Back to the Assignments page