100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CS 135 Midterm 1 complete Review Package University of Waterloo

Rating
-
Sold
-
Pages
15
Grade
A+
Uploaded on
26-10-2024
Written in
2024/2025

CS 135 Midterm 1 complete Review Package University of Waterloo

Institution
CS 135
Course
CS 135









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CS 135
Course
CS 135

Document information

Uploaded on
October 26, 2024
Number of pages
15
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Content preview

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)

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
smartzone Liberty University
View profile
Follow You need to be logged in order to follow users or courses
Sold
3192
Member since
5 year
Number of followers
2291
Documents
14354
Last sold
14 hours ago
AMAIZING EDUCATION WORLD

GET ALL KIND OF EXAMS ON THIS PAGE ,COMPLETE TEST BANKS,SUMMARIES,STUDY GUIDES,PROJECT PAPERS,ASSIGNMENTS,CASE STUDIES, YOU CAN ALSO COMMUNICATE WITH THE SELLER FOR ANY PRE-ORDER,ORDER AND ETC.

3.7

584 reviews

5
260
4
93
3
103
2
29
1
99

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions