What type of expressions should such a function expect

Assignment Help Programming Languages
Reference no: EM131195302

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.

Reference no: EM131195302

Questions Cloud

How would an individual privacy rights be violated : As a future IT manager, imagine that you are being pressured by your company to implement Facial Recognition Technology. You are aware that the general public is not aware of the potential privacy issues. How would you handle this situation?
Discuss the deployment services situations : Please briefly discuss the deployment services situations; what initial facts would best determine what situation should be used? If you were deploying on 150 computers, which would you use? Please give a detailed explanation of everything you wou..
Project that incurs costs in early years and yields benefits : A project that incurs costs in early years and yields benefits in later years has been estimated to have costs just equal to benefits, in present value terms and ignoring risk factors. The project would be reevaluated as having greater benefits than ..
Desirability of proposed government programs : It is often difficult to agree on the desirability of proposed government programs because of different perspectives regarding:
What type of expressions should such a function expect : 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.
Deserving individuals-aiding some undeserving individuals : Which of the following contributes to the unavoidable trade-off between denying aid to some deserving individuals and aiding some undeserving individuals?
Fibonacci sequence in the child process : Write a C program that generates the Fibonacci sequence in the child process. The number of the sequence will be provided in the command line. For example if 10 is provided, the Fibonacci numbers less than 10 will be output by the child process.
Research and understanding of ide : Based on your research and understanding of IDE, post your response to the following question:
Why and how the use of social media can ensure your company : Different types of cloud computing solutions that include your recommendation for the best choice and why you made that choice. An Office Productivity Software solution in a collaborative environment and why it is important to move in that direction.

Reviews

Write a Review

Programming Languages Questions & Answers

  Create the structure with 3 members and fill in data

Create a function that will display() all the data for each member and call it from the main program.

  Advantages of the common language runtime

What are the advantages of the Common Language Runtime in .NET

  Write program which exploit string library functions

Write a program which exploit the string library functions to do the following: prompt the user to enter his name (of four parts), count the number of characters in his name (excluding the white spaces).

  Provide a measure of accuracy of your prediction

Explain how you computed your prediction from the estimates and be sure to provide a measure of accuracy of your prediction.

  Effective design features for site navigation

Screen shot of this example and explanation of effective design features will be included. Callouts are recommended. Ideally, students will locate examples of how they would like their site navigation to work and function.

  Write a program that uses is and else or if and elsif

write a program that uses is and else or if and elsif conditional statementsthat asks the user to enter a value for

  Identify components that perform distinct service

Identify components that perform a distinct service. Although the details can be quite complex, these details are the basic principles of object-oriented programming

  Develop the algorithms needed for designer robot

You have been hired as a system designer to develop the algorithms needed for a designer robot that can paint different patterns on the floor based on the commands it receives.

  Explain application architecture and process design

Explain the application architecture and process design.Create the physical data flow diagrams. Use Microsoft Visio to make examples of flow charts and data flow diagrams.

  Write paper describing xml and json

Write two page paper describing XML and JSON. What are they? Why do we need them? Are there certain applications that favor one of the these over the other? Explain. What is SOAP?

  Write a shell script to send customized mail message to user

Write a shell script to send a customized mail message to the users listed on the command line by login (user) name, only if they are currently logged on. If no users are listed on the command line, an error message should be printed.

  Creating class savingsaccount using static variable

Create class SavingsAccount. Use static variable annualInterestRate to store annual interest rate for all account holders.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd