hw2_C22 (1)

.pdf

School

Boston University *

*We aren’t endorsed by this school

Course

112

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

3

Uploaded by ChancellorMuleMaster163

Report
CS 1101 C-Term 2022 Professor Engling Homework 2 - I temizations & L ist P rocessing (175 Points) Due: Tuesday, February 1 at 11:00pm Read the Expectations on Homework posted atop the Assignments module in Canvas. Assignment Goals To make sure you can define itemizations and write programs over itemizations To make sure you can define lists and write programs over lists The Assignment Writing Data Definitions for Itemizations Valentine's Day is right around the corner - and it's big business. One company sells plush stuffed animals. Another sells candy. Then there's always the classic: 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 ( use the names in bold to name your structs and the names in blue to name your fields ): plush When ordering a stuffed animal, the sender chooses the kind of animal (boa, dillo, tiger, bear, etc.), the size (15" or 20" or 36"), the color of the fur/skin, and the message for the card. candy The kind of candy can be chocolate, caramel, or red hots. A card with a message is included, and a heart-shaped-box? is provided if requested. flowers When choosing flowers, these attributes need to be specified: the kind of flower (roses, tulips, etc.), the color , the quantity (in dozens), and the message for the card. 1. (20 Points) Develop a data definition for each type of gift described above, and a data definition for an itemization for gifts. When creating a struct, the order of the fields in the struct should match the order given in the descriptions above. For example, the fields of the struct for a plush should be kind , size , color , and message , in that order. Otherwise our auto-tester will fail, and you will lose points. Provide at least one example for each kind of gift . 2. (20 Points) Provide the templates for functions for each data definition you made in Problem 1 (including the itemization for gift ).
Writing Programs for Itemizations If you're working with a homework partner... You and your partner should review the data definitions and templates you each came up with in Lab 2. Make changes, if necessary, and complete any of the exercises you didn't get to during the lab. Create your Homework 2 file according to the naming conventions for homework files posted on Canvas, and copy/paste your data definitions and templates into your homework file. If you're working by yourself... copy your Lab 2 work into your Homework 2 file (name your file yourLastName-yourFirstName-hw2 ), and continue working on Homework 2. Everyone... Make sure your function names are exactly the same as the names given in the problems. Otherwise, our auto-tester will fail, and you will lose points. 3. (25 Points) Write a function has-red? that consumes a gift and produces a boolean. The function returns true if the gift is a red plush, red hots, or red flowers. 4. (25 Points) 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 plush 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 candy, the function returns the candy with the message changed and a different box. Writing Programs for Simple Lists In the following problems, use this data definition for ListOfString: ;; a ListOfString is one of ;; empty ;; (cons String ListOfString) ;; interp: ListOfString represents a list of strings 5. (25 Points) Develop a function any-same-enders? that consumes a ListOfString and returns a Boolean. The function returns true if and only if any of the strings begins and ends with the same letter (character). Note: The string "M" begins and ends with the same character.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help