CS115F2008M1

CS115F2008M1 - Uwaterloo CS115 Midterm 1 2008 Fall 2009...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Uwaterloo CS115 Midterm 1 2008 Fall 2009 Oda_Eagle Production CS115/116/125/134/135/136/241/240/246/341/343 Tutor [email protected] The following notes are relevant for all questions: • • we use the term “Scheme” as a short form for “Beginning Student Scheme” We use arithmetic functions as well as the following build in functions, described briefly here for your reference • max determines the largest of two or more numbers • min determines the smallest of two or more numbers • string-length determines the length of a string • sqr determines the square of a number • check-expect is used for testing 招收 CS 大三課程以下学生有意者(具體請見詳表) + [email protected] CELL: 519-729-1582 已经教过 100+的学生 ◦ 经验丰富,童叟无欺,价格合理,内容充实,简单易懂 具體詳細表 CS115 作業答疑,考試複習,有過去考試的卷子和過去所有作業準確答案,也有自出的題,價格面儀 CS116/136 普通作業答疑不收費,如果一對一輔導價格面議 CS134 擁有最全的資料,無論作業還是近四個 term 所有考試卷子(不包括 final),價格面儀 CS240 答疑解惑,不收費 CS241 答疑+Debug 需要請請吃飯 CS246 答疑解惑 免費 ,Debug 需要請吃飯 CS245/251 愛莫能助 CS341 答疑解惑 不收費 CS350 答疑解惑 + Debug 不收費 CS343 答疑解惑 + Debug 不收費 CS360 跟我討論問題,我請你吃飯 其他課程諸如 Math135/136/137/138,可以給你介紹好老師 想學 Flash 的同學也可以找我,不過價格會比 CS 課貴 想學唱歌的別找我,謝謝 喝酒的找我,隨時奉陪 1. For each row in the table below, determine what would happen if you opened DrScheme and tried to evaluate the given code. If there is an error, briefly explain what is wrong. If there is no error, give the value produced by DrScheme. The first two rows have been completed for you Scheme Code (+12) (+12)) (* - 3 4 ) (/(+35)1) ( * “cat” “dog” ) ( sqr 3 2 ) ( + ( * ( - ( min 1 1 ) 1 ) 1 ) 1 ) ((*23)(-43)) (/5(-33) ( + 1 ( string-length “dog” ) ) 3 Error. There is an extra ). 2. Write the Scheme definition of the function f(x) = x2-2x+ 6. For the questions. You do not have to follow the steps of the design recipe. 3. Trace the following Scheme program ( - ( + ( sqr 1 ) ( * 2 3 ) ) 5 ) put one step on each line, you may not need all the lines. 4. Suppose you wish to write a Scheme function how-many-vowels that consumes a string and produces the number of vowels ( a,e,i,o,u ) in the string. In the spaces below, write the contract, purpose, one example, and header of the function how-many-vowels. You do not need to write the function itself Contract Purpose Example Header 5. The function rich-richer produces twice the maximum of two salaries. (define ( rich-richer salary1 salary2 ) ( * 2 ( max salary1 salary2 ) ) Write a test for rich-richer 6. Using all the steps of the design recipe, create a Scheme function median-of-3 that consumes three distinct integers. It produces the median of the integer. ( the Integer that is neither the largest, nor the smallest ) All of the steps of the design recipe are important: only a small of marks will be given to correctness of the definition of median-of-3 Hint: median-of-3 can be defined using the build-in functions min and max. ...
View Full Document

This note was uploaded on 10/24/2009 for the course CS 115 taught by Professor Graham during the Fall '08 term at Waterloo.

Ask a homework question - tutors are online