CS 1101 - Aterm 10
Homework 3 - Unions of Data
Due: Friday, September 10, at 5pm
Read the expectations on homework.
You should do this assignment with your homework partner.
Assignment Goals
- To make sure you can define unions of data
- To make sure you can write programs over unions of data
The Assignment
A major-league baseball team keeps data on its players. Players are either position
players or pitchers. Information kept for both types of players
includes the player's name, age, and the player's yearly salary
(in millions of dollars).
In addition, the following information is kept
for position players: a symbol representing the player's field position (C, 1B, 2B, 3B, SS,
LF, CF, RF); the number of at-bats; the number of runs scored; the number
of hits; the batting average; and the number of errors. For pitchers,
the following information is kept: the number of innings pitched,
the earned run average, the number of wins, and the number of losses.
(For those of you not familiar with baseball, here is some
information
about baseball statistics).
Writing Programs for Mixed Data
- Develop a data definition for players that covers both types of
players (position and pitcher) described above (you should have at least three data
definitions; remember that the data definition for a union consists only of a comment).
Give several examples of players.
- Provide the templates for your data definitions in Problem 1 (you should
provide as many templates as you have data definitions).
- Write a function
position
which consumes a player
and returns a symbol. If the player is a position player, the function
returns the player's field position. If the player is a pitcher,
the function returns the symbol 'P
.
-
Write a function
near-retirement?
that consumes a player
and produces a boolean. The function returns true if the player's age is
greater than 35.
- Write a function
add-bonus
that consumes a
player and produces a player. If the player is a position player
with a batting average greater than .320, or if the player is a
pitcher with an earned run average less than 2.5, then the player's
salary is increased by 10%. Otherwise, the player is returned
unchanged.
What to Turn In
Here is the gradesheet for Homework 3.
Using web-based turnin,
turn in a single file containing
all code and documentation for this assignment. Files should be named according to the file-naming conventions
for homework files.
Make sure both partners' names and login names appear in a comment at the top of the file.