How many and what type of expressions should such a


Important notes

• Signatures and purpose statements are ONLY required for function definitions -- you do NOT write them for named constants or for non-function-definition compound expressions.

• Remember: A signature in Racket is written in a comment, and it includes the name of the function, the types of expressions it expects, and the type of expression it returns. This should be written as discussed in class. For example,
; signature: purple-star: number -> image

• Remember: a purpose statement in Racket is written in a comment, and it describes what the function expects and describes what the function returns (and if the function has side-effects, it also describes those side-effects). For example,

; purpose: expects a size in pixels, the distance between
; points of a 5-pointed-star, and returns an image
; of a solid purple star of that size

• Remember: it is a COURSE STYLE STANDARD that named constants are to be descriptive and written in all-uppercase -- for example,

(define WIDTH 300)

• You should use blank lines to separate your answers for the different parts of the homework problems. If you would like to add comments noting which part each answer is for, that is fine, too!

• Because the design recipe is so important, you will receive significant credit for the signature, purpose, header, and examples/check-expects portions of your functions. Typically you'll get at least half-credit for a correct signature, purpose, header, and examples/check-expects, even if your function body is not correct (and, you'll typically lose at least half-credit if you omit these or do them poorly, even if your function body is correct).

Problem 1

Start upDrRacket, (if necessary) setting the language to How To Design Programs - Beginning Student level, and adding the HTDP/2e versions of the image and universe teachpacks by putting these lines at the beginning of your Definitions window:

(require 2htdp/image)
(require 2htdp/universe)

Put a blank line, and then type in:

• a comment-line containing your name,
• followed by a comment-line containing CS 111 - HW 2,
• followed by a comment-line giving the date you last modified this homework,
• followed by a comment-line with no other text in it --- for example:

; type in YOUR name
; CS 111 - HW 2
; last modified: (today's date)
;

Below this, after a blank line, now type the comment lines:

;
; Problem 1
;

Now, consider a function that is to produce the area of a triangle.

1 part a

How many and what type of expressions should such a function expect, to be able to return such an area?

Decide on a good, descriptive name for this function, and write an appropriate signature comment for this function.

1 part b

Write an appropriate purpose statement comment for this function.

1 part c

Write an appropriate function header for this function (putting ... ) for its body for now).

1 part d

Write at least 2 specific tests/check-expect expressions for this function. Interestingly, you may actually place these either before or after your not-yet-completed function definition, whichever you prefer.

1 part e

Only NOW should you replace the ... in the function's body with an appropriate expression to complete this function.

Run and test your function until you are satisfied that it passes its tests and works correctly.

Finally, include at least 2 example calls of your function (such that you will see their results) after your function definition.

Problem 2

Next, in your definitions window, after a blank line, type the comment lines:

;
; Problem 2
;

Consider a function that praises a given person for a job well-done. Given a person's name, it returns Good job, ...that person's name... ! (Optionally, you may change the exact wording of the praise, as long as it includes the person's name and ends with at least one exclamation point.)

2 part a

How many and what type of expressions should such a function expect, to be able to return this praise?

Decide on a good, descriptive name for this function, and write an appropriate signature comment for this function.

2 part b

Write an appropriate purpose statement comment for this function.

2 part c

Write an appropriate function header for this function (putting ... ) for its body for now).

2 part d

Write at least two specific tests/check-expect expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer.

2 part e

Only NOW should you replace the ... in the function's body with an appropriate expression to complete this function.

Run and test your function until you are satisfied that it passes its tests and works correctly.

Finally, include at least 2 example calls of your function (such that you will see their results) after your function definition.

Problem 3

Next, in your definitions window, after a blank line, type the comment lines:

;
; Problem 3
;

You decide it would be useful to be able to take an image, and a string caption for that image, and create a new image that includes the given image above its caption, such that the caption is depicted in 20-pixel-high black letters that are actually part of the image.

3 part a

Decide on a good, descriptive name for this function, and write an appropriate signature comment for this function.

3 part b

Write an appropriate purpose statement comment for this function.

3 part c

Write an appropriate function header for this function (putting ... ) for its body for now).

3 part d

Write at least two specific tests/check-expect expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer.

3 part e

Only NOW should you replace the ... in the function's body with an appropriate expression to complete this function.

Run and test your function until you are satisfied that it passes its tests and works correctly.

Finally, include at least 2 example calls of your function (such that you will see their results) after your function definition.

Problem 4

Next, in your definitions window, after a blank line, type the comment lines:

;
; Problem 4
;

Consider a function total-ounces that expects a number of pounds and a number of ounces, and returns the total number of ounces. (For example, the value of the expression (total-ounces 2 5) should be 37, because 2 pounds and 5 ounces is 37 ounces overall.)

4 part a

This part comes BEFORE starting function total-ounces!

FIRST: write a Racket definition for a named constant that will define the name OZ-PER-LB to be the number of ounces in a pound. (OZ-PER-LB is NOT a function! It isjust a number, the number of ounces in a single pound.)

4 part b

NOW you are starting the design recipe for function total-ounces.

NOW, write an appropriate signature comment for the function total-ounces.

4 part c

Write an appropriate purpose statement comment for total-ounces.

4 part d

Write an appropriate function header for total-ounces (putting ... ) for its body for now).

4 part e

Write at least two specific tests/check-expect expressions for total-ounces,

• at least one for a number of pounds of 0, and
• at least one for a number of pounds greater than 1,

...placed either before or after your not-yet-completed function definition, whichever you prefer.

4 part f

Only NOW should you replace the ... in total-ounces' body with an appropriate expression to complete it. For full credit, make sure that you use the named constantOZ-PER-LB appropriately within this expression.

Run and test your function until you are satisfied that it passes its tests and works correctly.

Finally, include at least 2 example calls of your function (such that you will see their results) after your function definition.

Problem 5

Next, in your definitions window, after a blank line, type the comment lines:

;
; Problem 5
;

(This is adapted from Homework 1 of J. Marshall's "The Way of the Program" course at Sarah Lawrence College.)

The Tasty-Waking coffee roasters sells whole-bean coffee at $9.50 per pound plus the cost of shipping. Each order ships for $1.37 per pound plus $3.50 fixed cost for overhead.

(So, if someone buys 1 pound of their whole-bean coffee, the total price is $14.37; if someone buys 2 pounds of their whole-bean coffee, the total price is $25.24; if someone buys 5 pounds, the total is $57.85.)

5 part a

The description above includes three constant, unchanging values. Define an appropriate, descriptive named constant for each of these values.

5 part b

Now consider a function whose purpose is to calculate the total price for an order. Given that you already know the values for the named constants given in Problem 5 part a, how many and what type of additional expressions should such a function expect, to be able to calculate the price of a coffee order?

Write an appropriate signature comment for the function.

(Hint: don't include named constants in the signature! Only consider what the function needs BESIDES the named constants to complete the task.)

5 part c

Write an appropriate purpose statement comment for this function.

5 part d

Write an appropriate function header for this function (putting ... ) for its body for now).

(Hint: remember that named constants do not belong in a function header, either.)

5 part e

Write at least two specific examples/tests/check-expect expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer.

5 part f

Finally, replace the ... in this function's body with an appropriate expression to complete it. For full credit, make sure that NOW you use the named constants from 4 part a appropriately within this expression.

Run and test your function until you are satisfied that it passes its tests and works correctly.

Finally, include at least 2 example calls of your function (such that you will see their results) after your function definition.

Problem 6

Next, in your definitions window, after a blank line, type the comment lines:

;

; Problem 6
;

Decide on a function that will take one or more parameters and return an image as a result. It can be anything not yet written in class or on a previous homework problem (variations on functions done in class or a homework problem are fine).

6 part a

Decide on a good, descriptive name for your function, and write an appropriate signature comment for this function.

6 part b

Write an appropriate purpose statement comment for this function.

6 part c

Write an appropriate function header for this function (putting ... ) for its body for now).

6 part d

Write at least two specific tests/check-expect expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer.

6 part e

Only NOW should you replace the ... in the function's body with an appropriate expression to complete this function.

Run and test your function until you are satisfied that it passes its tests and works correctly.

Finally, include at least 2 example calls of your function (such that you will see their results) after your function definition.

Solution Preview :

Prepared by a verified Expert
Programming Languages: How many and what type of expressions should such a
Reference No:- TGS01577498

Now Priced at $80 (50% Discount)

Recommended (96%)

Rated (4.8/5)