CS 1101 - C-term 12

Homework 3 - Lists of Structs

Due: Tuesday, February 7 at 5pm

Read the expectations on homework.

Assignment Goals


The Assignment

Are you sick of watching television ads? The typical 30-minute TV program consists of 22 minutes of programming and 8 minutes of commercials. What with the hype over Super Bowl ads and the run-up to the March 6 Presidential Primary in Massachusetts, we're all going to be suffering from ad-fatigue over the next few weeks. In this assignment, you'll create data to represent information about television ads, and write programs that process lists of ads.
  1. An ad consists of the type of ad (product or political), the name of the product or politician the ad is for, the duration of the ad (in seconds), the cost to produce the ad, whether the ad is to be aired nationally or locally, the time of day that the ad is to be aired (either daytime, primetime, or off-hour), and the number of times the ad is to be aired.

    Write data definitions and provide examples of data for ad and list-of-ad.

  2. Write the template(s) for list-of-ad.

  3. Write a function count-political-ads that consumes a list-of-ad and produces the number of ads in the list that are classified as political ads.

  4. Write a function any-ads-for? that consumes a list of ads and a string representing a product name or politician's name, and produces a boolean. The function returns true if the list contains any ads for the given product or politician.

  5. Write a function primetime-ads that consumes a list of ads and produces a list of all the ads airing in primetime.

  6. Write a function politicians-sponsoring-ads that consumes a list of ads and produces a list of strings. The list that is produced contains the names of the politicians who have political ads (it's OK if the resulting list contains duplicate names).

  7. Write a function air-cost that consumes an ad and produces a number. The number produced is the cost of airing the ad, which is determined as follows: airtime is sold in 30-second-spot blocks (so if the duration of the ad is 15 seconds, it would cost half the stated amount, etc.). The cost of a 30-second primetime ad for a national market is $100,000. The cost of a 30-second primetime ad for a local market is $5000. A discount of 20% is applied to the cost if the ad is aired in the daytime, and a discount of 50% is applied if the ad is aired during off-hours; the discounts apply to both national and local ads. Finally, the air-cost is multiplied by the number of times the ad is to be aired. (You may assume that all airings of an ad occur in the same market and at the same time of day.)

  8. Write a function campaign-air-cost that consumes a list of ads and the name of a politician, and produces the total air-cost of all political ads for that politician.

  9. Write a function total-ad-cost that consumes an ad and produces the total cost of the ad. The total cost is the sum of the cost of producing the ad and the cost of airing the ad.

  10. Write a function expensive-ads that consumes a list of ads and a number. The function produces a list of those ads for which the total ad cost exceeds the given number.


What to Turn In

Here is the grading sheet that the graders will be using for Homework 3.

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.