100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CS 135 Midterm 1 complete Review Package University of Waterloo $12.49   Add to cart

Exam (elaborations)

CS 135 Midterm 1 complete Review Package University of Waterloo

 15 views  0 purchase
  • Course
  • CS 135
  • Institution
  • CS 135

CS 135 Midterm 1 complete Review Package University of Waterloo

Preview 2 out of 15  pages

  • October 26, 2024
  • 15
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • CS 135
  • CS 135
avatar-seller
smartzone
CS 135 Midterm 1 complete Review Package University
of Waterloo
Introduction to Scheme

Writing Arithmetic Expressions

 4 - 5 * (3 + 2) => (- 4 (* 5 (+ 3 2)))
 3 * 5 / (2 + 7) + 3 => (+ 3 / (* 3 5) (+ 2 7))

Things to Remember:

 Extra parentheses, while okay in mathematics, affect expressions in Scheme
 Operations are written before the associated arguments
 Operations need two arguments
 Substitutions are done left to right

Functions in Scheme

(define (f x y) (+ (* x x) y))

 The word define is used to bind a name to an expression
 f is the name of the function
 x and y are the parameters
 Values that are passed as x and y are the arguments of the function
 (+ (* x x) y) is the body expression, and tells us what the function does
 x and y have no meaning in any other part of the program

(define b “constant”)

 b is a constant
 If b is used in any body expressions, “constant” will be used
 Constants can make programs easier to understand

, Design Recipe

Contract

 Describes the arguments that your function takes as well as the type that your function will
produce
 Some possibilities are Int, Nat, Symbol, String, Posn, etc.
 For the output of your function, None is also a possibility

Examples:
Symbol -> None
String Int -> Boolean
Posn Symbol Int[>= 7] -> Posn

Purpose

 Explains what your function does using the names of your parameters
 Purpose comes from the question

Example:
The unit of speed most often used in physics is meters per second (m/s). A common
Imperial unit of speed is miles per hour (mph). Write a function mph->m/s which
consumes a speed in the units of mph and produces the same speed in units of m/s.

Purpose: converts the given speed, s, from mph to m/s

Examples

 Used to make sure you understand how the function is supposed to work
 Written below the purpose and above the function
 Don’t necessarily test all cases; mostly try and get a general idea about what your function
should do

Example:
Write a function final-cs135-grade that consumes four numbers:
(a) the first midterm grade (10%),
(b) the second midterm grade (20%),
(c) the final exam grade (45%), and
(d) the assignments grade (20%).
This function should produce the final grade in the course. You may need to review the mark
allocation in the course. You can assume that all input marks are percentages and are given
as integers between 0 and 100, inclusive. Also, assume a grade of 100 for participation (5%).

Examples:
(check-expect (final-cs135-grade 50 50 50 50) 52.5)
(check-expect (final-cs135-grade 75 87 72 83) 78.9)

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller smartzone. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $12.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75323 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$12.49
  • (0)
  Add to cart