Spring CS Homework 3 p. 1. CS Homework 3

Similar documents
CS Homework 2 p. 1. CS Homework 2

Spring CS Homework 6 p. 1. CS Homework 6

Spring CS Homework 7 p. 1. CS Homework 7

Homework 11 Program Setup (with some IMPORTANT NEW STEPS!)

CS Homework 11 p. 1. CS Homework 11

CS Fall Homework 11 p. 1. CS Homework 11

CS Homework 10 p. 1. CS Homework 10

GOALS [HTDP/2e Chapters 1 through 3.5]

Animations involving numbers

Spring CS Homework 12 p. 1. CS Homework 12

Deadline. Purpose. How to submit. Important notes. CS Homework 9. CS Homework 9 p :59 pm on Friday, April 7, 2017

CS Homework 11 p. 1. CS Homework 11

Homework: Simple functions and conditionals

CS 051 Homework Laboratory #2

The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about

CS Homework 10 p. 1. CS Homework 10

Do a domain analysis by hand-drawing three or more pictures of what the world program will look like at different stages when it is running.

Paint Tutorial (Project #14a)

Animations that make decisions

CISC 1600, Lab 3.1: Processing

Digital Media. Seasons Assignment. 1. Copy and open the file seasonsbegin.fla from the Read folder.

CS 100 Spring Lecture Notes 3/8/05 Review for Exam 2

15-110: Principles of Computing, Spring 2018

COM110: Lab 2 Numeric expressions, strings, and some file processing (chapters 3 and 5)

1 Getting started with Processing

CS 463 Project 1 Imperative/OOP Fractals

Using Inheritance to Share Implementations

TSM Report Designer. Even Microsoft Excel s Data Import add-in can be used to extract TSM information into an Excel spread sheet for reporting.

CISC 1600, Lab 2.1: Processing

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

Assignment 3 Functions, Graphics, and Decomposition

Chapter 2. The Midpoint Formula:

Skill 1: Multiplying Polynomials

Com S 127 Lab 2. For the first two parts of the lab, start up Wing 101 and use the Python shell window to try everything out.

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

Watch the video below to learn more about number formats in Excel. *Video removed from printing pages. Why use number formats?

Week 3: Objects, Input and Processing

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

Photoshop tutorial: Final Product in Photoshop:

Honors Computer Science Python Mr. Clausen Program 7A, 7B

CS Homework 11

CS 134 Programming Exercise 2:

Week 1: Introduction to R, part 1

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

Programming Project 1

Honors Computer Science C++ Mr. Clausen Program 6A, 6B, 6C, & 6G

Unit 21 - Creating a Navigation Bar in Macromedia Fireworks

1. Complete these exercises to practice creating user functions in small sketches.

Lab 7: OCaml 12:00 PM, Oct 22, 2017

Adobe Photoshop How to Use the Marquee Selection Tools

Name: Dr. Fritz Wilhelm Lab 1, Presentation of lab reports Page # 1 of 7 5/17/2012 Physics 120 Section: ####

Copyright. For more information, please read the Disclosures and Disclaimers section at the end of this ebook. First PDF Edition, February 2013

Curves & Splines. Assignment #3. Overview & Objectives. Due Dates. CPSC 453 Fall 2018 University of Calgary

CS 170 Java Programming 1. Week 5: Procedures and Functions

CMSC 201 Fall 2016 Homework 6 Functions

1 Getting started with Processing

Homework #2: Introduction to Images Due 4 th Week of Spring 2018 at the start of lab CSE 7, Spring 2018

The Fundamentals. Document Basics

Slide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto


Part 1 Your First Function

About Freeway. Freeway s Tools and Palettes

PowerPoint Instructions

Name: Student Workbook. Class:

n! = 1 * 2 * 3 * 4 * * (n-1) * n

Chemistry Excel. Microsoft 2007

15-110: Principles of Computing, Spring 2018

CS 106 Winter Lab 05: User Interfaces

Name: Bootstrap:2. Class:

Creating a Flyer. Open Microsoft Publisher. You will see the list of Popular Publication Types. Click the Blank Page Sizes.

How to...create a Video VBOX Gauge in Inkscape. So you want to create your own gauge? How about a transparent background for those text elements?

Style and Submission Guide

Note: Photoshop tutorial is spread over two pages. Click on 2 (top or bottom) to go to the second page.

Introduction To Inkscape Creating Custom Graphics For Websites, Displays & Lessons

Earthwork 3D for Dummies Doing a digitized dirt takeoff calculation the swift and easy way

EEN118 LAB TWO. 1. A Five-Pointed Star.

PowerPoint Slide Basics. Introduction

Creating Web Pages with SeaMonkey Composer

;; ;; Section 1 ;; ;; ;; What is the value of: (+ 2 (* 3 5)) ;; What is the value of: (string-append "Roberto" " " "Luongo")

Tips from the experts: How to waste a lot of time on this assignment

PowerPoint Introduction. Video: Slide Basics. Understanding slides and slide layouts. Slide Basics

Working with images and scenes

Tips from the experts: How to waste a lot of time on this assignment

Designer Reference 1

MITOCW watch?v=r6-lqbquci0

Introduction to Programming with JES

HO-FL1: INTRODUCTION TO FLASH

Homework: More Abstraction, Trees, and Lists

Programming Assignment 8 ( 100 Points )

Magazine-style websites often have lots of small items on a page. First you re going to create a heading and background for your magazine.

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

CS Week 14 Lab Exercise

CS Fall Homework 5 p. 1. CS Homework 5

What can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.

DIRECTV Message Board

Slide 1 CS 170 Java Programming 1

15100 Fall 2005 Final Project

Android Programming Family Fun Day using AppInventor

15-110: Principles of Computing, Spring 2018

Using Flash Animation Basics

Transcription:

Spring 2018 - CS 111 - Homework 3 p. 1 Deadline 11:59 pm on Friday, February 9, 2018 Purpose CS 111 - Homework 3 To try out another testing function, check-within, to get more practice using the design recipe to write and test functions, and to use at least one of those functions as an argument in a big-bang clause to create an animation. How to submit You will submit your 111hw3.rkt file for Homework 3 on the course Canvas site. Each time you would like to submit your work so far: Save your current DrRacket 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! Open a web page to connect to https://canvas.humboldt.edu. Click on the icon for the CS 111 course, then choose the Homework 3 link (in the Homeworks section). Follow the Canvas instructions for uploading your Racket file 111hw3.rkt. 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. NOTE: it is also fine and encouraged to define and use named constants when you notice there is some "set" value you are reusing! You only need to write new signature and purpose statement comments for functions that you are designing and writing yourself you do not write them for named constants, plain compound expressions. or for functions that are already built into the Racket environment or the teachpacks. That said, if you copy one of the in-class functions for use in your homework, DO also copy its signature, purpose, and check- expressions/tests as well as the function definition. Remember: A signature in Racket is written as a comment, and it includes the name of the function, the Racket data types of expressions it expects in the order they're to be expected, and the Racket data type of the expression it produces. This should be written as discussed in class (and you can find examples in the posted in-class examples). For example, signature: triple: number -> number signature: say-bye: string -> string

Spring 2018 - CS 111 - Homework 3 p. 2 signature: avg-trio: number number number -> number signature: purple-star: number -> image Remember: a purpose statement in Racket is written as a comment, and it describes what the function expects and describes what the function produces (and if the function has side-effects, it also describes those side-effects). For example, purpose: expects a number, and produces triple that number purpose: expects a name, and produces the string containing "Goodbye, " followed by their name purpose: expects three numbers, and produces the average of those three numbers purpose: expects a size in pixels (which is the distance between points of a 5-pointed-star), and produces 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) it is ANOTHER course style standard that parameters and function names are to be descriptive and written in all-lowercase -- for example, (define (triple num)...) 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! The design recipe is important! You will receive substantial 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). Homework File Setup Open a new Racket Definitions file (it's a good idea to immediately save your file as 111hw3.rkt, in the folder where you want your Racket file to go, and save often as you go!) and type in comments at the beginning of the file, containing: 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 -- for example: type in YOUR name CS 111 - HW 3 last modified: 2018-02-03 Then put a blank line, and then: (require 2htdp/image) (require 2htdp/universe)

Spring 2018 - CS 111 - Homework 3 p. 3 Problem 1 Problem 1 In this problem, we will introduce a variation on the check-expect expression. You are not writing a function definition in this problem -- you are writing check-within expressions. Sometimes, when a function returns a number that's not an integer, especially a number such as the result of (/ 1 3), it becomes difficult to write an exact expected value in a check-expect expression after all, 1/3 is an infinite decimal, and 0.333 won't exactly match that. It would be better in this case to have the expected value be "close enough" to the actual value. That is why, along with several additional check- functions, Racket also has the built-in check-within function, so we can check to see if the expected answer and the calculated answer are "close enough" to sufficiently test our functions. The check-within function 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 being tested a number that represents 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 an example, let's test whether Racket's built-in constant pi is within 0.001 of our usual estimate of pi, 3.14159 -- the check-within expression would look like this: (check-within pi expression being tested 3.14159 APPROXIMATE expected value.001) how close these must be to be "close enough" (Yes, pi is a Racket named constant but it's not a named constant we defined, so it's not written in upper case characters. We write our self-defined constants in upper case characters!) If you want to know if the pre-defined value of pi is within 0.000001 of 3.14159, the next checkwithin expression can do this. It will fail, because our estimate is not close enough: (check-within pi 3.14159 0.000001) This problem will have you practice writing a few expressions using check-within. 1 part a Write a check-within expression that results in a passing test for testing what the expression (/ 1 6)...should be approximately equal to. Use an estimate that's within 0.01 of the actual value. 1 part b Write a check-within expression that will result in a passing test for testing what the expression (* pi 1000)...should be approximately equal to.

Spring 2018 - CS 111 - Homework 3 p. 4 Problem 2 Problem 2 The Celsius temperature scale, used by most of the rest of the world, is different from the Fahrenheit temperature scale used in the US. Design a function that expects a temperature given in Celsius, and returns the equivalent Fahrenheit 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 that part of the first step of the Design Recipe, the part where you analyze the problem.) 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 START the define expression for this function, including an appropriate function header including appropriate parameter identifier(s) of your choosing, and typing in... for the function body for NOW. 2 part d Write at least 2 specific tests/check-expect or check-within expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer. (Something just to think about: Do you see why check-within might be useful for tests for this function, depending on what values you choose for this function's tests?) 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, write at least 2 expressions of your choice that run your function (so that you will see their results) after your function definition. Problem 3 Problem 3 I decide I'd like a function name-badge that expects a desired name and a desired background color, and returns an image of a "name badge" for that name with that background color and with that name displayed in its middle using black letters. YOU get to decide on the shape of this badge image (the user does not specify it, you will choose it as part of designing this function.) YOU also get to decide on the font-size you want to use for the given name's letters

Spring 2018 - CS 111 - Homework 3 p. 5 on your resulting badge. (It would be good to make your chosen font size a named constant!) Somehow make the width of your "badge" be based on the given name's length. (HINT: reminder: 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 START the define expression for this function, including an appropriate function header including appropriate parameter identifier(s) of your choosing, and typing in... for the function body for NOW. 3 part d Write at least 2 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, write at least 2 expressions of your choice that run your function (so that you will see their results) after your function definition. Problem 4 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 (actually a new data type!) 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 is completely opaque). 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. For example, you can run: (make-color 100 200 150)...but it doesn't return what the color looks like it returns (make-color 100 200 150 255). But, you can see the resulting color if you run something like: (circle 30 "solid" (make-color 100 200 150)) Design a function color-swatch that expects desired red, green, and blue values, and returns a solid square or rectangular image (your choice) whose color has those red, green, and blue values. (You can pick a

Spring 2018 - CS 111 - Homework 3 p. 6 reasonable constant size for this square or rectangular.) OPTIONAL: if you'd like, you can design the function to also expect a transparency value (that is, you can design it to expect 4 arguments instead of 3 arguments). No extra credit, it's just something you can try. If you choose to do so, you should make sure your signature reflects this and purpose statement explains this! 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 START the define expression for this function, including an appropriate function header including appropriate parameter identifier(s) of your choosing, and typing in... for the function body for NOW. 4 part d Write at least 2 specific tests/check-expect expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer. 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, write at least 2 expressions of your choice that run your function (so that you will see their results) after your function definition. Problem 5 Problem 5 5 part a 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 (but not bigger than 600 pixels). define a named constant HEIGHT, a scene height of your choice (but not bigger than 400 pixels). define a named constant BACKDROP, an unchanging, constant scene that will serve as a backdrop scene in some expressions. its size should be WIDTH by HEIGHT pixels it should include at least one placed image of your choice (and you may certainly include additional placed images if you wish). (you may certainly include additional named constants, also, if you wish!)

Spring 2018 - CS 111 - Homework 3 p. 7 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 (and/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 (or images) will 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, or an image's horizontal coordinate within the BACKDROP could be determined by that number, or an image's vertical coordinate within the BACKDROP could be determined by that number, or since you now know about make-color, part an image's color or transparency could be determined by that number, or you could change more than one of these at the same time -- ask long as the changes are all based on a single number, the possibilities are endless! You will design a draw-scene function that expects the current world number and produces a scene placing an image (or multiple images) into your BACKDROP whose location within the scene, or size, or color, or some combination of these things, is somehow based on that world number. Write an appropriate signature comment for this function. 5 part c Write an appropriate purpose statement comment for this function. 5 part d START the define expression for this function, including an appropriate function header including appropriate parameter identifier of your choosing, and typing in... for the function body for NOW. 5 part e Write at least 2 specific tests/check-expect expressions for this function, placed either before or after your not-yet-completed function definition, whichever you prefer. 5 part f Only NOW should you replace the... in the function's body with an appropriate expression to complete this function. 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 write at least 2 expressions of your choice that run your function (so 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?

Spring 2018 - CS 111 - Homework 3 p. 8 decrease by 1? Increase and/or decrease by other 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) Now you can write a big-bang expression consisting of an initial world number value, a to-draw clause with your draw-scene function, and an on-tick clause with the name of your (new or existing) numberchanging function -- something like: (big-bang initial-number-you-choose (to-draw draw-scene) (on-tick name-of-your-number-changing-function)) Now you should see something changing in your scene, and now you are done with this problem. NOTE: you can also change the speed of the ticker in the on-tick clause if you would like by giving on-tick an optional second expression: a number that gives the number of seconds per tick. The default value is (/ 1 28) or 1/28 of a second, which means it ticks 28 times per second. To go slower, put a number greater than 0.036. To go faster, put a number less than 0.035 (but greater than 0). Example: (on-tick add1 0.2) this will move slowly, only 5 ticks per second