In this module we explain the difference between computation and programming, and introduce the basic syntax for the Beginning Student Language (BSL) along with the coding style that we will follow in this class.

We demonstrate how to use the Racket Stepper on a BSL expression. We also show the one-to-one correspondence between the evaluation steps taken to reduce the BSL expression to a value and the steps taken by the Stepper.

  1. Explain what is meant by computation.
  2. Write an example of a computation.
  3. Explain the difference between program and computation.
  4. List the four properties that define a value.
  5. Given a sequence of instructions, transcribe them into a Scheme program.
  6. Name the four steps that make up a computation.
  7. Given a Scheme expression, write down the sequence of steps taken during evaluation.
  8. Write a constant definition using the keyword define.
  9. Write a function definition using the keyword define.
  10. Write a call to a function with the appropriate number of inputs.
  11. Write a conditional statement using the keyword cond.
  12. Use all capitalization for constant names.
  13. Use the naming conventions for functions.

  • DUE DATE: 21 January, 2016 @ 12:00pm

Problem 1

  1. Desing a function that calculates the volume of a frustum given its height and the radius of the upper and lower base.
  2. Desing a function that calculates the total surface area of a frustum given its height and the radius of the upper and lower base.

Problem 2

Design a program that given a year as a 4 digit number, returns #true if the year is a leap year, and #false otherwise.

Make sure to read the Wikipedia article on leap year, which contains an algorithm for figuring out if a year is a leap year.

NOTE: ensure that you have at least one test for each case.

Problem 3

  1. Design a program called string-add-prefix that will consume two strings, a word w and a prefix p , and that will return a new word which is the composition of the prefix p followed by the word w, e.g.,
    
    (string-add-prefix "define" "re-")  ;; returns "re-define"
    (string-add-prefix "view" "re")     ;; returns "review"
    
  2. Design a program called string-add-suffix that will consume two strings, a word w and a suffix s, and that will return a new word which is the composition of the word w followed by the suffix s, e.g.,
    
    (string-add-suffix "game" "s")  ;; returns "games"
    (string-add-suffix "low" "er")  ;; returns "lower"
    
  3. Design a program called string-join that will consume two strings, and returns a new string comprised of the first string followed by a comma followed by the second string. e.g.,
    
    (string-join "this" "that")  ;; returns "this,that"
    (string-join "is" " this ") ;; returns "is, this "
    
    Hint: Consider how you can use the functions you already designed for this question.

Problem 4

One of the operators in logic is the if and only if operator. Design a program called iff that consumes two boolean variables and returns a boolean. The program should have the same behavior as the logical if and only if operator.

Problem 5

Design a program that given the total yearly salary calculate the total tax that needs to be payed. Your function should follow the following table for rates based on total yearly income.

Income Tax Percentage
0 to 9,275 10%
$9,275 to $37,650 15%
$37,650 to $91,150 25%
$91,150 to $190,150 28%
$190,150 to $413,350 33%
$413,350 to $415,050 35%
$415,050 and over 39.6%

Problem 6

A friend is working on a side project developing a new piece of software for presentations and is asking for you help. We would like to have a program that would consume a piece of text, and a style category, and would stylize the text accordingly. The style categories are given as symbols

  • 'title
  • 'body
  • 'code

Title text should be displayed in a font size of 36 and in blue color. Body text should be displayed in a font size 24 and in black color. Code text should be displayed in font size 20 and in red color.

Design a function called text-stylize that consumes the text to be stylized as a string and the style category as a symbol. Your function should return an image. To use Racket's image library add the following line of code to your file


(require 2htdp/image)

You should also familiarize yourself with the documentation for the function text in the image library.

Problem 7

We are asked to help out with a new software for manipulating images. The team needs us to write a function that will detect if an image is larger than some other image. An image is larger than another image when both the width and height of the first image is larger than the width and height of the second image.

Design a function called image>? that consumes two images and returns #true when the height and width of the first image is larger than the height and width of the second image.

Hint: Lookup the functions image-width and image-height in DrRacket's documentation.

SUMMARY OF ASSIGNMENT

Item Points
Code Coverage (black lines) 5
Problem 1 6
Problem 2 6
Problem 3 7
Problem 4 5
Problem 5 5
Problem 7 4
GRAND TOTAL: 38