CS 1101 - Cterm 10
Homework 3 - Mixed Data (Unions of Data)
Due: Friday, January 29 at 5pm
Read the expectations on homework.
Assignment Goals
- To make sure you can define mixed data
- To make sure you can write programs over mixed data
The Assignment
An online gift shop is running a special promotion for Valentine's Day.
A chosen gift will be delivered to your loved one on the
morning of February 14. The gifts offered for Valentine's Day are
- flowers when choosing flowers, the following attributes need to be specified: the type of flower (such as roses or
tulips), the color, and the quantity (in dozens). In addition, a message to be
printed on the gift card should be specified.
- candy the types of candy offered are dark chocolate, chocolate truffles, and milk chocolate. Either a large or small box of candy may be ordered.
The box itself may be rectangular or heart-shaped. Again, a message should be
specified for the gift card.
- certificate For the less romantically-inclined, the gift shop
offers a hand-delivered gift certificate in a pink envelope. When ordering
a gift certificate, the customer should specify the amount (in dollars),
the vendor (such as Harry's Hardware Store or Mel's Bowling Alley), and the
message to be written on the gift certificate.
Writing Programs for Unions
- Develop a data definition for gifts that covers all types of
gifts described above (you will need to make
multiple data definitions).
Give several examples of gifts.
- Provide the template for each data definition you made in Problem 1.
- Write a function
flower-cost
which consumes flowers
and produces the cost of the flowers. The cost is $24.99 per dozen for
red roses, $19.99 per dozen for roses of any other color, and $15.99 per dozen for any other type of
flower.
- Write a function
candy-cost
that consumes candy and
produces the cost of the candy. The number returned is $60.00 for a large box of dark chocolate, $40.00 for a large box of truffles, and
$20.00 for a large box of milk chocolate. Small boxes cost half as much.
If the box itself is heart-shaped, an additional $5.00 is added to the cost.
- Write a function
certificate-cost
that consumes a certificate
and produces the cost of the certificate. The cost is calculated by adding a
10% delivery charge to the amount of the certificate.
-
Write a function
gift-cost
that consumes a gift and returns the
cost of the gift.
-
The gift-card messages are generated by a computer, and there is a limit of 50 characters
to the length of the message. Write a function
msg-too-big?
that consumes a gift and returns true if the length of the message for that
gift exceeds 50 characters.
- Sometimes changes in the status of a relationship result in last-minute
requests to change the contents of the gift-card message.
Write a function
change-message
that consumes a gift and a
string, and produces a gift. The gift that is produced is the same as the
original, except that the message for that gift has been replaced by the
given message.
What to Turn In
Using web-based turnin,
turn in a single file containing
all code and documentation for this assignment. Name your file according to the naming conventions for files.
Make sure both partners' names and login names appear at the top of the file in a comment.