CS 1101 - Aterm 15

Homework 3 - Itemizations and Simple List Processing

Due: Thursday, September 17 at 5pm

Read the expectations on homework.

Assignment Goals


The Assignment

Writing Data Definitions for Itemizations

A video-rental company called Web-Flicks provides two plans for customers: DVDs-by-mail and on-demand streaming. In this assignment, you'll create data definitions for video rental plans, and write programs over those data definitions.

A rental plan can be either of the following:

  1. Develop a data definition for each type of plan described above, and a data definition for an itemization for plans. Provide at least one example for each kind of plan.

Writing Programs for Itemizations

  1. Provide the template for each data definition you made in Problem 1 (including the itemization).

  2. Write a function monthly-cost that consumes a rental plan and produces a number that represents the monthly cost of the plan. If the plan is for DVDs by mail, the basic monthly cost is based on the number of DVDs shipped at once: $7.99 for 1, $8.99 for 2, $9.99 for 3, and $10.99 for 4. If the DVDs are high definition, $0.50 per DVD is added to the cost. If the plan allows the customer to keep the DVDs for an unlimited amount of time, an additional $3.00 per month is charged.

    Streaming plans cost $2.99 for SD, and $4.99 for HD. If the plan is for unlimited streaming, an additional $5.00 is added to the monthly cost.

  3. Write a function make-high-def that consumes a rental plan and produces a rental plan. The plan that is produced is the same as the original, except that the produced plan is HD. If the original plan was already HD, the produced plan is the same as the original.

Writing Programs for Simple Lists

In the following problems, use this data defintion for ListOfString:
;; a ListOfString is one of
;;  empty
;;  (cons String ListOfString)
;; interp:  ListOfString represents a list of strings
  1. Develop a function contains-all-numbers? that consumes a ListOfString and produces true if at least one string in the list consists entirely of numeric characters. Otherwise, the function produces false. (Hint: check the DrRacket help desk for various string functions). Here are two sample test cases (you may need additional test cases):
    (check-expect (contains-all-numbers? (cons "CS1101" (cons "A1" (cons "32" empty)))) true)
    (check-expect (contains-all-numbers? (cons "CS1101" (cons "A-one" empty)))) false)
    

  2. Develop a function count-X that consumes a ListOfString and counts the total number of X's (upper and lower case) that occur in all strings in the list. Hint: helper functions are your friend.

  3. Write a data definition to represent a list of natural numbers (call it ListOfNatural). Then develop a function lengths-of-strings that consumes a ListOfString and produces a ListOfNatural. The function produces a list of the lengths of each of the strings in the given ListOfString.

What to Turn In

Here is the grading sheet that the graders will be using for Homework 3. Programs must run in order to receive credit. Note that code that is commented out will not be graded.

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.