CS 1101 - Cterm 11

Homework 2 - Structs and Unions

Due: Thursday, January 27 at 5pm

Read the expectations on homework. You will do this and all subsequent homework assignments with your homework partner.

Assignment Goals


The Assignment

Valentine's Day is right around the corner - and it's big business. One company sells teddy bears, dressed and accessorized to match the recipient's profession or personality. Another company sells pajamas. Then there's always the old standby, flowers.

An online entrepreneur decides to cash in on the lucrative Valentine's Day market and creates a clearing house for all things Valentine. If you decide to take advantage of this one-stop shopping place for your sweetheart's Valentine's Day gift, you are offered these choices:

Writing Programs for Structs and Unions

After Friday's lecture, you should be able to complete problems 2 and 7. After Monday's lecture, you should be able to complete problems 1, 3, 4, 6, and 8. After Tuesday's lecture you should be able to complete the remaining problems (5, 9, and 10).

Make sure you provide an adequate set of test cases for each function that you develop (including helper functions).

  1. Develop data definitions for gift-card and teddy. The gift-card definition should just contain the message and the sender. (If the standard message for a teddy is chosen, any data in the message portion of the gift card will just be ignored.) Provide two examples of gift-cards, and two examples of teddies.

  2. Develop a data definition for pajamas. Provide two examples of pajamas.

  3. Develop a data definition for flowers. Provide two examples of flowers.

  4. Provide the templates for gift-card, teddy, pajamas, and flowers.

  5. Develop a data definition for gifts that covers all types of gifts described above. Provide the template for gifts.

  6. Write a function teddy-cost that consumes a teddy and produces the cost of the teddy. The cost is calculated this way: 15" bears have a base cost of $39.99 and 20" bears have a base cost of $49.99. If the fur color is brown or black, there is no additional charge, but any other color incurs an extra charge of $5.00. The standard pre-printed message is free, but if the message is customized, the additional charge is 5 cents per character (including spaces and punctuation). Develop a helper function that calculates the cost of a customized message.

  7. Write a function pajama-cost. The price of a pair of pajamas is $60.00. Gift-boxing costs an additional $7.99.

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

  9. Write a function gift-cost that consumes a gift and returns the cost of the gift. Added to the cost of any gift is a charge of $12.99 for shipping and handling.

  10. 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. If the gift is a teddy or flowers, the function returns a gift the same as the original except that the gift-card is customized with the new message. If the gift is pajamas, the function returns pajamas the same as the original.


What to Turn In

Here is the grading rubric that will be used to grade Homework 2.

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. Use group submission to submit your solution to your homework-partner group (there should be only one submission from each group). Make sure both partners' names and login names appear at the top of the file in a comment.