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
- To make sure you can define structs
- To make sure you can write functions over structs
- To make sure you can define unions of data (itemizations)
- To make sure you can write functions over itemizations
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:
- Teddy Bear Teddy Bears come with a personalized gift card
and a box of candy. When ordering a Teddy Bear, one must choose the
outfit (for example, "teacher", "biker", "society lady", "tattoo artist"),
the size (15" or 20"), the color of the fur, the choice of candy (chocolate
or caramel), whether or not the sender wants to provide the standard
pre-printed Valentine's Day message ("I love you
beary much") or specify their own message, and the gift card information.
A gift card contains a message and the name of the sender.
- Pajamas Valentine's Day pajamas come in four sizes (S, M, L,
XL),
and two colors (red and pink). They can be gift-boxed on request.
- flowers when choosing flowers, the following attributes need to
be specified: the type of flower (such as roses or
tulips), the color, the quantity (in dozens), and the gift card information (message and the name of the
sender).
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).
- 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.
- Develop a data definition for pajamas. Provide two examples
of pajamas.
- Develop a data definition for flowers. Provide two examples
of flowers.
- Provide the templates for gift-card, teddy, pajamas, and
flowers.
- Develop a data definition for gifts that covers all types of
gifts described above. Provide the template for gifts.
- 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.
- Write a function
pajama-cost
. The price of a pair of
pajamas is $60.00. Gift-boxing costs an additional $7.99.
- 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
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.
- 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.