Recall the Laws of Homework and the academic honesty policy when preparing your solutions.
Your intro engineering professor has asked you to design a small bridge. You can use five components: 2-hole wood slats, 3-hold wood slats, pairs of bolts and nuts, washers, and steel mesh. Your grade on the assignment will be based on a combination of the weight and number of components used to build your bridge, as well as the maximum load (weight) that your bridge can support.
As you plan to consider several designs, you decide to write some programs to compare your designs to maximize your score (this is adapted from an actual intro engineering course assignment at another school).
Develop a data model for bridges. Your model only needs to capture the number, not the configuration, of the various components. Include the define-struct needed to model bridges and three examples of plans created with your model.
Develop a data model for a design. A design should contain a bridge and the maximum weight that it held.
State all of the operators (with their contracts) that are created from your define-struct for designs.
Write a function part-weight that consumes the name of a part (bridge component) and returns the weight of one unit of that component. The weights for single units are as follows:
|Wood slat, 3 hole||2.78|
|Wood slat, 2 hole||2.82|
|Steel mesh, per square inch:||0.51|
Write a function total-components that consumes a bridge and returns the total number of component units in the bridge.
Write a function total-weight that consumes a bridge and returns the total weight of the bridge.
Write a function design-score that consumes a design and returns the overall score for that design. Compute the score for a design with the following formula:
A truss is a common structure in a bridge design. A simple truss is made of a triangle of three 2-hole wood slats, fastened together with a nut/bolt pair at each of the three corners. Write a function add-simple-trusses that takes a bridge and a number of trusses to add and returns a bridge. The returned bridge should have the same components as the original bridge plus the given number of new trusses.
Write a program load-to-improve-score that consumes a design and a bridge and determines how much weight the bridge would need to bear in order to yield the same or a higher score than the design. When you test your program, make sure that the returned weight does indeed yield a higher score for the new bridge than the original design. [Note: it's fine to return the load required to match the score on the existing design.]
Evaluate each of the following expressions by hand (use the rules covered in class, which match those of Beginner level). Show every step. In each expression, indicate the subexpression that is evaluated to obtain the next expression. For example:
(sqrt (+ (* 3 3) (* 4 4))) ^^^^^^^ = (sqrt (+ 9 (* 4 4))) ^^^^^^^ = (sqrt (+ 9 16)) ^^^^^^^^ = (sqrt 25) ^^^^^^^^^ = 5
If an expression would result in an error, show all of the steps up to the error, then indicate the error message you'd get (error messages don't need to be verbatim, as long as they convey the right kind of error).
Include the answers to this question in the same file as your programs from the previous part. You can enclose the entire section in a block comment (to prevent Scheme from processing it) as follows:
#| [stuff to comment out, as many lines as you want] |#
(/ (- (* 16 16) (double a)) 2) where double is defined as (define (double n) (* n 2))
(or (< 7 2) (and (= 15 (- 18 3)) (> 8 4)))
(and (+ 9 -1) false)
(part-weight 'washer) [use your part-weight program from above]
(cond [(- 5 2) 'subtracted] [(* 5 2) 'multiplied] [else 'neither])
cond: expected a clause with a question and answer, but found a clause with only one part
reference to undefined identifier: x
function call: expected a defined name or a primitive operation name after an open parenthesis, but found a number
Turn in a single file hwk1.ss or hwk1.scm containing all code and documentation for this assignment. Turn in your answers to all three parts (writing programs, evaluating programs, and debugging programs).