CS 1101 - C-term 11
Homework 4 - Writing functions for Lists of Structs
Due: Thursday, February 10 at 5pm
Read the expectations on homework.
Assignment Goals
- To be able to define a list of structures
- To make sure you can write functions for lists of structs
The Assignment
The waiters in a local restaurant use hand-held devices to record customers'
orders. In this assignment, you will write data definitions and functions
that model the ordering of items from the restaurant's menu.
- Each item on the menu consists of the name of the item, the type
(appetizer, entree, dessert, or beverage), whether or not the item
is vegetarian, the number of items ordered,
and the cost of a single item. Define a struct called menu-item
that represents the given information. Give at least 3 examples of
menu-items.
- Write the template for functions over menu-items.
- Define an order (a list-of-menu-item). Give at least two examples of
orders.
- Write the template for functions over orders.
As you develop the following functions over orders,
develop auxiliary (helper) functions over menu items that can be used by the
order functions.
- Develop the function count-appetizers, that consumes an order
and returns the number of items in the order that are
appetizers. (The quantity of each appetizer is not taken into account by
this function - the function simply counts each menu item in the list that
is classified as an appetizer.)
- Develop a function list-expensive-vegetarian that consumes an
order and a number and
produces an order. The order that is produced contains only those items
from the original order that are vegetarian and that cost more than the
given amount.
- Develop a function order-total. The function consumes an order
and produces the total cost of the order (a number). When calculating the total cost,
you should take into account the quantity of each item ordered.
- Develop a function beverage-total that consumes an order and
produces a number. The function calculates the cost of all beverages in the
order (again, you should take quantities into account).
- Develop a function called cost-with-tip. The function consumes
an order and a number representing the percent of the tip. The function
produces the total cost of the order with the tip. When calculating the
cost, the tip is applied only to non-beverage items.
What to Turn In
Here is the grade sheet that the TAs will use
when they grade Homework 4.
Using web-based turnin,
turn in a single file containing
all code and documentation for this assignment. Follow the naming conventions for naming your file.