RU beehive logo ITEC dept promo banner
ITEC 380
2018fall
ibarland

working with a union type
hw03

Due: Sep.21 (Fri) 15:00 (hardcopy and D2L)
Your submitted file should be named “hw03.rkt”.

We wish to write code about whether or not the Radford Highlanders won their soccer game, this last weekend. We want to capture: whether they won/lost, or tied, or there wasn't any game this weekend, or (if the game is still in-progress) what the name of the team currently being played is. (Oddly, we will not track the opposing team's name when the game isn't in progress1. Perhaps we don't care about such details once a game is over?)

  1. (5pts) Complete steps 1-3 of the design recipe for representing this information, which we'll name “game-result”.
    Hint: To represent whether they won or lost, a boolean seems appropriate. What types seem appropriate for each of the other variants?
  2. (5pts) Write a function payout which takes in the amount of a bet2 placed that the Highlanders’ would win their game (non-negative) and a game-result and returns how much money is to be repaid:
  3. (5pts) Write a function game-result->string which returns a user-friendly message similar to one of the following, as appropriate: (You will, of course, follow the applicable steps 4,5,7,8 of the design recipe.)

Standard instructions for all homeworks (unless instructed otherwise):


1 Certainly it is natural to want to always know the opposing-team-name even for the other situations (won/lost, tied, etc.). But since we haven't yet introduced compound types (“structs”/“records”/“objects”), we don't know how to do this. So: Don't. Only keep track of the opposing-team-name in the event of game-in-progress.

(And on further thought, we'll also note that while opposing-team-name could conceivably be information worth tracking for several cases, it wouldn't make sense for no-game-this-week. This complicates a correct data-representation; more on that in class.)

     
2 A perfectly perfecty legal bet on a game of skill, with no luck involved whatsoever.      
3 The only exception to open-paren-preceded-by-space (or, at the start of a line) is any “[(”s occuring in a cond. Though we'll have a few other exceptions in the future: let* expressions, and (very occasionally) when calling higher-order functions.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.