COMPUTER SCIENCE PROJECTS
COMPUTER SCIENCE PROJECTS COMP 490
Popular in Course
Popular in ComputerScienence
This 14 page Class Notes was uploaded by Cleora Stiedemann on Monday October 19, 2015. The Class Notes belongs to COMP 490 at Rice University taught by Staff in Fall. Since its upload, it has received 11 views. For similar materials see /class/224959/comp-490-rice-university in ComputerScienence at Rice University.
Reviews for COMPUTER SCIENCE PROJECTS
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/19/15
Simple Programs Reduction the i Recipe and Errors Course Overview Datadriven program design Abstraction and good design Algorithms Accumulators Side effects Mutable structures and objects Design Recipes Introduced and used throughout the course COMP 210 Fall 2007 217 19 23 25 28 30 32 34 37 39 43 Today s Goals Numbers as examples of basic types Primitive operations on numbers Rules for reducing programs Simple programs 2 Variables Function de nitions Function application The design recipe Errors COMP 210 Fall 2007 Numbers as basic types Used in math and in computing Naturals O 1 2 Number theory Integers 1 12 include negatives Rational numbers 34 56 Inexact numbers iO 12 3 For all but the last kind Scheme computes exact results COMP 490 project What about the real numbers COMP 210 Fall 2007 4 Primitive Computation Most languages provide basic operations on values of basic types sqrt expt remainder log sin Primitive computation 2 application of a basic operation Basic operation Basic function Soon we Will see how to de ne our own non primitive functions Function application Syntax varies from language to language In most languages it is mixed Most languages use in X notation for math and pre x notation in general Scheme uses pre X notation uniformly for everything A B sqrt A remainder A B Biggerexample l 2 3 4 How does this compare to writing 12 34 Scheme syntaX keeps things simple and avoids possible ambiguity COMP 210 Fall 2007 5 Reduction for primitive functions A reduction 2 a computational atom The smallest step of computation Example l 2 3 4 3 3 4 3 7 2 1 Goes left to right Why do we care The following is not an atomic step and so not a reduction l 3 l 3 O COMP 210 Fall 2007 6 Simple Programs Variables are simply names for values pi my SSN album name tax rate x Function de nitions define area of box x x x define half X X 2 Function applications just as we saw before area of box 2 half area of box 3 Almost all functions can be written this way COMP 210 Fall 2007 Reductions for de ned functions Assume we declared the two functions define area of box x x X define half X X 2 Then Scheme can perform these reductions half area of box 3 half 3 3 2 half 9 e 9 2 45 Reduction stops when we get to a value or an error COMP 210 Fall 2007 8 The Design Recipe How should I go about writing programs 1 Analyze problem and de ne data types 2 State contract and purpose for function 3 Give examples of function use and result 4 Write the function itself 5 Test it and record actual results of tests The order of the steps of the recipe is important COMP 210 Fall 2007 Example Area of disk Contract area of ring number number gt number SRpZ Purpose To compute the area of a ring whose radius is outer and whose hole has a radius of inner Examples area of ring 5 3 should produce 5024 Sup3 area of ring 5 0 should produce 785 Definition refines steps 1 4 Sup4 define area of ring outer inner area of disk outer area of disk inner Tests SRpS quotTesting area of ringquot Help your grader equal area of ring 5 3 5024 equal area of ring 5 0 785 m and other examples NowIDOHELmeequalorm ngsthefinitionye USe onWinTests COMP 210 Fa2007 1O g The Design Recipe Big Picture Encourages systematic problem solving Works best if keep our functions small We Will learn how to decompose problems to decompose a problem 2 to structure our understanding of a problem Solution structure follows that of problem This is part of datatype driven program design COMP 210 Fall 2007 Syntax Errors A syntactically correct program can be An atom like anumber 17 45 i034 a variable radius or A compound program starting With followed by operator then one or more programs and nally ending With Syntax errors 3 34 3 COMP 210 Fall 2007 Runtime Errors Happen when operators are surprised Consider the following examples sqrt l 2 3 4 syntax error l 8 l 7 syntax error l O runtime error l quotaquot runtime error Try things like that in DrSCheme and make a mental note of the error messages you get back COMP 210 Fa2007 13 Logistics New homework is posted online Sign up for mailing list to get any updates discussions Make absolutely sure you follow the recipe Partners Talk to people after class at lab etc Go to lab at any time this week sign up there Next online quiz Will cover Chapters 1 2 3 We ll let you know when the new system is up COMP 210 Fa2007 14
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'