(define-struct ad (political? name duration production-cost national? time-of-day repetitions)) ;; an Ad is a (make-ad Boolean String Natural Natural Boolean String Natural) ;; interp: a television ad, where ;; political? is true if the ad is a political ad, false otherwise (for product ad) ;; name is the name of the politician or the product the ad is for ;; duration is the length of the ad (in seconds) ;; production-cost is the cost to produce the ad (in thousands of dollars) ;; national? is true if the ad is to be aired nationally (false if locally) ;; time-of-day is one of "P" for primetime, "D" for daytime, "O" for off-hour ;; repetitions is the number of times the ad is to be played ;; a ListOfAd is one of ;; empty ;; (cons Ad ListOfAd)
Make sure you name your functions exactly the same as the names given in the problems below.
count-political-ads
(from Homework 3) that consumes a
list of ads and produces the number of ads in the list that are classified
as political ads. You may use the built-in Racket function length
, which consumes a list and produces the number of items in the list.
primetime-ads
that consumes a list of ads
and produces a list of all the ads airing in primetime.
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).
cheap-to-produce
that consumes a list of ads and a number and produces a list of ads. The list that's produced contains those ads for which the production costs are less than the given amount. (The given amount is in thousands of dollars.)
mailsys
to be a mail system with no users.
add-user
that consumes a username and produces void. The effect of the function is to add a new user with the given username to the mail system. The new user should have an empty mailbox. You may assume that the username is not already in the mail system.
send-email
that consumes the name of the sender of an email, the name of the recipient of the email, and the text of an email message, and produces void. The effect of the function is to store a new unread message in the recipient's mailbox. Assume the named recipient is a user in the mail system.
get-unread-messages
that consumes a username and produces a list of messages. The produced list contains the unread messages in the mailbox of the user with the given name. Assume the username is a valid user in the mail system. An effect of the function is that all unread messages in the named user's mailbox have been set to read.
most-messages
that doesn't consume anything. The function produces the user in the mailsystem with the largest number of messages in his/her mailbox. If there are no users in the system, the function produces an appropriate error. If two or more users have the most messages, the function just needs to return one of them (it doesn't matter which one). You must use accumulator-style programming to solve this problem.
Submit your .rkt
file to InstructAssist. The name of the project is Homework 6. Follow the naming conventions for naming your file.