Study Guides (238,105)
Canada (114,924)
CS 135 (13)


56 Pages
Unlock Document

University of Waterloo
Computer Science
CS 135
Uzma Rehman

CS 135 Exam Review Package This package includes the packages from the first and second midterm sessions CS 135 Midterm 1 Review Package Introduction to Scheme Writing Arithmetic Expressions4532 453 235273 3 3 52 7 Things to RememberExtra parentheses while okay in mathematics affect expressions in SchemeOperations are written before the associated argumentsOperations need two argumentsSubstitutions are done left to right Functions in Scheme define f x y x x yThe word define is used to bind a name to an expressionf is the name of the functionx and y are the parametersValues that are passed as x and y are the arguments of the functionx x y is the body expression and tells us what the function doesx and y have no meaning in any other part of the program define b constantb is a constantIf b is used in any body expressions constant will be usedConstants can make programs easier to understandDesign Recipe ContractDescribes the arguments that your function takes as well as the type that your function will produceSome possibilities are Int Nat Symbol String Posn etcFor the output of your function None is also a possibility ExamplesSymbolNoneString IntBooleanPosn Symbol Int 7Posn PurposeExplains what your function does using the names of your parametersPurpose comes from the question ExampleThe unit of speed most often used in physics is meters per second ms A common Imperial unit of speed is miles per hour mph Write a function mphms which consumes a speed in the units of mph and produces the same speed in units of ms Purpose converts the given speed s from mph to ms ExamplesUsed to make sure you understand how the function is supposed to workWritten below the purpose and above the functionDont necessarily test all cases mostly try and get a general idea about what your function should do ExampleWrite a function finalcs135grade 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 Examplescheckexpect finalcs135grade 50 50 50 50 525 checkexpect finalcs135grade 75 87 72 83 789 DefinitionThis is where you write your functionMust include the header and the bodyThe header is the name of your function as well as the parametersThe body is the expression what your function actually does with the parametersThe header should be written before your purpose is written so that you can refer to parameters in your purposeExamples should be written after your header is complete so that you know all necessary parameters Exampledefine finalcs135grade mid1 mid2 final assign mid1 010mid2 020final 045assign 020 5Note using constants for the weight of each section would make your program more readable TestsTests are written at the very end of the design recipeUsed to find any errors in code or logicUse checkexpect to test your functionForm of checkexpect is o checkexpect functionname argument1 argument2answer o If the function evaluates to the given answer it will produce true o Otherwise checkexpect evaluates to false and you then need to check your calculations andor your codeMake sure to test helper functions as well to better locate any errorsTest one or two general cases in addition to all special cases or those cases with the potential to cause problems Example For the previous function checkexpect finalcs135grade 0 0 0 0 5 checkexpectfinalcs135grade 100 100 100 100 100 checkexpectfinalcs135grade 100 0 0 0 15 checkexpectfinalcs135grade 0 100 0 0 25 checkexpectfinalcs135grade 0 0 100 0 50 checkexpectfinalcs135grade 0 0 0 100 25
More Less

Related notes for CS 135

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.