Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91951366
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in Programming Language

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As