CS 1101 - Cterm 10

Homework 3 - Mixed Data (Unions of Data)

Due: Friday, January 29 at 5pm

Read the expectations on homework.

Assignment Goals


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

Writing Programs for Unions

  1. 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.

  2. Provide the template for each data definition you made in Problem 1.

  3. 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.

  4. 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.

  5. 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.

  6. Write a function gift-cost that consumes a gift and returns the cost of the gift.

  7. 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.

  8. 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.