Write an appropriate signature comment for the function

Assignment Help Computer Engineering
Reference no: EM131390764

Assignment

Purpose

To get more practice using the design recipe to write and test functions.

How to submit

Each time you would like to submit your work:

• save your current Definitions window contents in a file with the name 111hw3.rkt

- Note: please use that *exact* name -- do not change the case, add blanks, etc. If I search for a file with that name in your submission, I want it to show up! 8-)

• transfer/copy that file to a directory on nrs-labs.humboldt.edu (preferably in a folder/directory named 111hw3)

- If you are in a campus lab, you can do so by copying them to a folder on the U: drive
- If you are not in a campus lab, you can do so by using sftp (secure file transfer) and connecting to nrs-labs.humboldt.edu, and then transferring them.

Graphical versions of sftp include WinSCP and Secure Shell Transfer Client for Windows, Cyberduck and Fugu for Mac OS X, and FileZilla that has versions for both Windows and Mac OS X. (Mac OS X and Linux also come with a command-line sftp -- an intro to this is included in the posted handout, "useful details - sftp, ssh, and ~st10/111submit", available on the public course web site in the References section.)

- Whichever version of sftp you are using, use a host name of nrs-labs.humboldt.edu if you are not in a campus lab (you can get away with just nrs-labs for the host name in a campus lab), your campus username, and when you are prompted for it, your campus password. IF you need to give a port number, give a port number of 22.

• Now that your file is on nrs-labs.humboldt.edu, you need to log onto nrs-labs.humboldt.edu using ssh, so you can submit your file to me.

- In BSS 313, the Windows computers have a graphical version of ssh called PuTTY. There is a graphical version of ssh for Mac OS X named Jelly FiSSH, (although Mac OS X and Linux also come with command-line ssh, and an intro to this is also included in the "useful details - sftp, ssh, and

~st10/111submit" handout.)

- Again, whichever version of ssh you are using, use a host name of nrs-labs.humboldt.edu if you are not in a campus lab (you can get away with just nrs-labs for the host name in a campus lab), your campus username, and when you are prompted for it, your campus password. IF you need to give a port number, give a port number of 22.

• WHILE you are logged onto nrs-labs:

- IF you saved your file in a folder, use cd to change to the folder/directory where you saved it -- for example, if you saved it in the folder 111hw3, then you would go to that directory by saying:
cd 111hw3

- use the ls command to make sure your 111hw3.rkt file is really there:

ls
- type the command:
~st10/111submit

...and when asked, enter a homework number of 3

...and when asked, enter y, you do want to submit all files with an appropriate suffix (I don't mind getting some extra files, as long as I also get 111hw3.rkt; I'd rather receive too many files than too few due to typos.)

...make sure to carefully check the list of files submitted, and make SURE it lists 111hw3.rkt as having been submitted! (The most common error is to try to run ~st10/111submit while in a different directory than where your files are...)

Important notes

• NOTE: it is usually fine and often encouraged if you would like to write one or more helper functions to help you write a homework problem's required functions.

- HOWEVER -- whenever you do so, EACH function you define IS EXPECTED TO follow ALL of the design recipe steps: after thinking about the function and the kind of data involved, write its signature, then its purpose statement, then its function header, then its tests/check- expressions, then replace its

... body with an appropriate expression

• Remember: 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 (and you can find examples in the posted in-class examples). 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 up DrRacket, (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 3,
• 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 3
; last modified: 2017-02-04
;

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

;
; Problem 1
;

Note: you are NOT writing a function in this problem -- you are just writing two compound expressions. Sometimes, when a function returns a number with a fractional part, especially a number such as the result of (/ 1 3), it becomes difficult to give an expected value in a check-expect that is "exact enough" for a passing test. Yet, if the expected value is "close enough" to the actual value, we might like to be able to decide that that is good enough for our purposes.

That is why, along with several additional check- functions, BSL Racket also includes check-within, which expects THREE arguments:

• the expression being tested, which in check-within's case should be of type number

• an approximate expected value for that expression

• a number that is the largest that the difference between the expression and the expected value can be and still consider this to be a passing test. (In math, this maximum difference is also called a delta.)

As a quick example, what if you simply wanted to test whether BSL Racket's predefined pi was within .001 of 3.14159? This check-within expression can do this, and show that it is:

; passing test

(check-within pi ; expression being tested 3.14159 ; APPROXIMATE expected value
.001) ; how close these must be to be "close enough"

But if you want to know if its predefined pi is within .000001 of 3.14159, this check-within

expression can do this, and show that it is not:

; failing test

(check-within pi
3.14159
.000001)

Just to PRACTICE writing a few expressions using check-within:

• write a check-within expression that will result in a passing test for testing what the expression
(/ 1 7)

...should be approximately equal to;

• write a check-within expression that will result in a passing test for testing what the expression
(* pi 100)
...should be approximately equal to.

Problem 2

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

;
; Problem 2
;

True story: my spouse likes to set every item that displays a temperature to display that temperature in Celsius. That prompts an idea: design a function that expects a temperature given in Celsius, and returns the equivalent Fahreheit temperature. Write such a function cels->fahr, using the following design recipe steps:

(It is reasonable to search the web or an appropriate reference for the conversion formula for this -- consider it problem research.)

2 part a

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 2 specific tests/check-expect or check-within expressions for this function.

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
;

I decide I'd like a function name-badge that expects a name and a color, and returns an image of a "name badge" for that name with letters of that color: a shape (of your choice of shape, style, and background color) with the given name (of your choice of font size, but using letters of the given color) in its middle. Somehow make the width of your "badge" be based on the name's length.

(HINT: remember that string-length expects a string and returns how many characters are in that string.)

3 part a

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 2 specific tests/check-expect expressions for this function.
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

FUN FACT: BSL Racket includes a make-color function.

make-color expects three arguments, each an integer number in [0, 255], representing its red, green, and blue values, respectively, and returns a color made up of those red, green, and blue values. Optionally, it can take a 4th argument, another integer in [0, 255], giving the transparency of that color (0 is completely transparent, 255 has no transparency).

But - to play with this is a little inconvenient, because to "see" what the returned color looks like, you have to use the resulting color in some image function.

Design a function color-box that expects desired red, green, and blue values, and returns a solid square image whose color has those red, green, and blue values. (You can pick a reasonable constant size for this square.)

OPTIONAL: if you'd like, you can design this to also expect a transparency value (that is, you can design it to expect 4 arguments instead of 3 arguments).

4 part a

Write an appropriate signature comment for this function.

4 part b

Write an appropriate purpose statement comment for this function.

4 part c

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

4 part d

Write at least 2 specific tests/check-expect or check-within expressions for this function.

4 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 5

Next, in your definitions window, type the comment lines:

;
; Problem 5
;

5 part a

Remember that place-image expects a scene expression for its 4th argument. It can be convenient to use a named constant for this scene, especially if you will be using it in a number of place-image expressions and if it might itself include several unchanging elements.

You are going to be creating some scenes in later parts of this problem, so for this part, define the following named constants:

• define a named constant WIDTH, a scene width of your choice (except it should not be bigger than 1300 pixels).
• define a named constant HEIGHT, a scene height of your choice (except it should not be bigger than 400 pixels).
• define a named constant BACKDROP, an unchanging, constant scene that will serve as a backdrop scene in some future problems.

- its size should be WIDTH by HEIGHT pixels

- it should include at least one visible unchanging image of your choice (and you may certainly include additional visible unchanging images if you wish).

• (you may certainly include additional named constants, also, if you wish!)

5 part b

Consider a "world" of type number -- starting from a given initial number, in which that number changes as a ticker ticks, and in which the number determines what is shown where (or how) in a scene.

For this world, big-bang's to-draw clause will need a scene-drawing function that expects a number, and produces a scene based on that number. Don't get too far ahead of yourself, here! Just decide what image(s) is/are going to be ADDED to your BACKDROP scene from 5 part a based on a number value.

Do something that is at least slightly different than the posted class examples, and at least slightly different than what you did for the Week 3 Lab Exercise.

(For example, an image could be placed in the BACKDROP whose size depends on that number -- and/or an image's x-coordinate within the BACKDROP could be determined by that number -- and/or an image's y- coordinate within the BACKDROP could be determined by that number -- and/or part an image's color or transparency could be determined by that number -- and/or some combination, letting it determine both the x- and y-coordinate, or both its color and and its size, for example.)

Write an appropriate signature comment for this function.

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).

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 you use your BACKDROP scene from 5 part a appropriately within this expression.

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

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

5 part g

What change do you want to happen to your world number as the world ticker ticks? Will it increase by 1? decrease by 1? Increase and/or decrease by varying amounts?

Decide how your world number will change on each ticker tick. If your change can be done by a built-in function such as add1 or sub1, that is fine. Otherwise, using the design recipe, develop this function, that expects a number and produces a number.

• (if you develop your own function here, REMEMBER to do all the steps you have been doing for the other functions in this homework -- first write its signature, then its purpose statement, then its function header, then its tests/check-expect expressions, then replace its ... body with an appropriate expression)

Then write a big-bang expression consisting of an initial number, and a to-draw clause with the name of your scene-drawing function from 5 parts b-f, and an on-tick clause with the name of your (new or existing) number-changing function -- something like:

(big-bang initial-number-you-choose

(to-draw name-of-your-scene-drawing-function) (on-tick name-of-your-number-changing-function))

(By the way, you can also change the speed of the ticker in this on-tick clause if you would like to -- give it an optional 2nd expression, a number that is a ticker-rate-expression, and the ticker will tick every ticker-rate-expression seconds.)

Now you should see something changing in your scene, and now you are done with this problem.

Reference no: EM131390764

Questions Cloud

Write a menu based program to do the following : Do an In order traversal of T.6. Output the height of the T7. Count and Print the number of leafs in T8. Print all Single Parents, i.e nodes in T that have only one child9. Count and Print the number of nodes in T
Chapters in the microbiology etext : Read the following chapters in the Microbiology etext available at https://www.boundless.com/microbiology/textbooks/boundless-microbiology-textbook/
Create a structure to specify data on students given below : Create a structure to specify data on students given below: Roll number, Name, Department, Course, and Year of joining Assume that there are not more than 450 students in the collage.
Tell the basic facts about the art : Tell the basic facts about the art (see citing your image). Get the reader interested in the image by using one of the following methods (often referred to as hooks) Describe the image vividly so the reader can see it. (Paint a picture for the aud..
Write an appropriate signature comment for the function : CS 111- Write an appropriate signature comment for this function. Write an appropriate function header for this function (putting ... ) for its body for now).
Create a cost model for higher-level operations in c++ : Exercise 7-7 involved writing a program to measure the cost of various operations in C++. Use the ideas of this section to create another version of the program.
Determine the period and frequency of the motion : A 35-kg block is supported by the spring arrangement shown. The block is moved vertically downward from its equilibrium position and released.
Whether chapmans contract violates truth in lending act : The front side had a notice referring to provisions on the back side. Explain whether Chapman's contract violates the Truth-in-Lending Act.
Terry project - adjusting the financial statements : Acct 414 The Terry Project: Adjusting the Financial Statements. Terry Co. sells backpacks, laptop bags, briefcases, and other bags. The bags are purchased already made, then the Terry branding and finish is added

Reviews

Write a Review

Computer Engineering Questions & Answers

  Encode the same sequence using run-length

Encode the following bit sequence using run-length encoding with 4-bit codes.

  Find the original sequence

A sequence is encoded using the Burrows-Wheeler transform. Given L = elbkkee, and index = 5 (we start counting from 1, not 0), find the original sequence.

  Listing each prompt that is used in this program.

Write down a new program in pseudo-code, it should input-and calculate the average of 5 numbers entered.

  Design the layout of users and domains

Design the layout of users, domains, trusted domains, anonymous users, etc for a start-up open source software company ABC.

  Create a compensation structure

Evaluates both approaches (job-based and person-based) and creates a compensation structure based on both approaches. In considering both approaches, what would the compensation structure look like for each position? Justify your recommendations w..

  Compare power loss if 500 kw of power is transmitted

A program to analyze the power loss in a transmission line with a resistance of 0.05 ohms/mile. Compare the power loss if 500 kw of power is transmitted from a power generating station to cities at distances of 20, 30, 40, 50... 100 miles at 100 V..

  Tests performed to ensure the fault tolerance of servers

How could you determine the level of fault tolerance needed for a particular business operational function.

  Evaluate the concept that it is becoming the new core of

evaluate the concept that it is becoming the new core of modern business. how might you justify or negate this

  Write m8c assembly code to add the 24-bit value

Write M8C assembly code to add the 24-bit value 0x123456 to the 24-bit value 0x020304 stored in memory locations 0x11-0x13 (MSB in 0x11).

  How can we use foreign key constraints

How can we use Foreign Key constraints. How may we create new View on one or more tables ?

  Customers may purchase recordings by making a selection

as Napster is going out of business, you have decided to start your own on-line music sharing site. You will provide individual music files at your site.

  Why would items move from a slower layer to a faster layer

Determining the time quantum for a job is a critical task. Given the assumptions that the average switching time between processes is s, and the average amount of time an 110 bound process uses before generating an I/O request is t (t » s). Discus..

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