HW1_C22

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 1 - Defining Structs (120 Points) Due: Tuesday, January 25 at 11pm EST If you have one, you should work with your homework partner on this and all remaining homework assignments. The Expectations on Homework document remains posted under Assignments in Canvas. Assignment Goals To gain experience modeling data using Racket structs. To assure you can write programs using cond , structures, and nested structures To gain additional practice in combining functions Reminders Your solutions to the following problems should use helper functions in place of repeated code and to improve the readability of your code. Remember to include a signature, purpose, and test cases for every function you write, including helpers. Make sure you read each problem carefully and create a signature that conforms to the problem description. You must name each function with the exact name specified in the problem. Your signature must conform to the problem description. Otherwise, we won't be able to run our automated tester on your program, and you'll lose points. Programs that don't work with our auto-tester (and thus must be tested manually) will be penalized with a deduction of 10% of the total number of points for the assignment. Each test case you develop should be annotated with a brief comment that describes the situation being tested.
The Assignment The website for a publishing house contains information about each of the books it has in print. The following information is stored for a book: the title of the book the book's author the book's genre (mystery, history, science fiction, biography, etc.) the length of the book, in pages the date of publication of the book (it should include the year, month, and day) the total sales for the book so far (in dollars) Problems 1. (20 Points) Provide data definitions for both a Book and a Date . Include both the define-structs and at least three examples for each data definition. When creating a struct, the order of the fields in the constructor should match the order given in the descriptions above. The names of the fields in the struct don't matter, but the order does. For example, the fields of the struct for a Book should be the title , author, genre , length , publication date , and sales , in that order. Failure to define the fields in the given order will cause our auto-tester to fail, and you will lose points. Your struct for a Date should have 3 fields, one for the year , one for the month , and one for the day , in that order. Each field in a Date is of type Natural. 2. (15 Points) In a comment in the Definitions Window, state the signatures of all the procedures that are created by Racket for your Book struct. 3. (20 Points) Write a function imaginative-fiction? which consumes a Book and returns true if its genre is "mystery'', "science fiction'', or "fantasy'' and returns false otherwise. 4. (20 Points) Write a function combined-length which consumes two Book s and produces a Number. The number produced is the sum of the lengths of the two books. 5. (20 Points) Write a function update-sales which consumes a Book and a Number, and produces a Book . The Book that is produced is the same as the original except that its sales has been replaced by the new amount. 6. (25 Points) Write a function since? which consumes a Book and a Date , and produces a Boolean. The function produces true if the given Book was published after the given Date , and returns false otherwise.
Grading Programs must run to receive credit. Note that code that is commented out will not be graded. The grading rubric the graders will use is posted in Canvas below this assignment. What to Turn In Using Canvas, turn in a single .rkt file containing all code and documentation for this assignment. Name your file according to the name conventions for files in CS 1101 posted with Assignments in Canvas. Both partners' names and WPI usernames must appear in a comment atop the file.
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