Section 2.5: Designing Programs. REVIEW: Design Recipe  Figure out precisely what you need to do.  Tell the computer how to do it.  Check that the.

Slides:



Advertisements
Similar presentations
The only thing all about you is the grade:-]. Critical Analysis Addressing two fundamental questions: What it is I claim to know? How valid are the methods.
Advertisements

Why are most eukaryotic cells between 10 and 100 m in diameter?
CRITICAL WORKPLACE SKILLS Preparing to Get a Job.
Lesson 1.4 Power of a Product and Power of a Quotient Rules
Method Parameters and Overloading. Topics The run-time stack Pass-by-value Pass-by-reference Method overloading Stub and driver methods.
PRIME FACTORIZATION.
CS 106 Introduction to Computer Science I 11 / 09 / 2007 Instructor: Michael Eckmann.
CSC 160 Computer Programming for Non-Majors Lecture #9: Booleans Prof. Adam M. Wittenstein
WEBQUEST Let’s Begin TITLE AUTHOR:. Let’s continue Return Home Introduction Task Process Conclusion Evaluation Teacher Page Credits This document should.
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5: Defining Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 2: Numbers, Expressions, and Simple Programs Prof. Adam M. Wittenstein
Chapter 2: Algorithm Discovery and Design
Imperative programming public int factorial (int N){ int F = 1; for(X=N; X>1; X-- ){ F= F*X; } return F; } Functional programming (defun factorial(N) (cond.
CSC 160 Computer Programming for Non-Majors Introduction Prof. Adam M. Wittenstein
>(setf oldlist ) Constructing a list We know how to make a list in lisp; we simply write it: ‘4321( ) What if we want a new list with that list as a part?
Section 4.4: Designing Conditional Functions. REVIEW: Design Recipe – V. 2  Figure out precisely what you need to do. 1. Understand the problem 2. Function.
Section 1.1: Flying a UFO (continued). Conversion recipe 1)Expand abbreviations 2)Parenthesize all subexpressions that have an operator. Should end up.
CS 106 Introduction to Computer Science I 03 / 28 / 2008 Instructor: Michael Eckmann.
Section 4.3: Conditions and Conditional Functions.
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Introduction Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5b: Designing Programs Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 3: Programs are Functions Plus Variable Definitions Prof. Adam M. Wittenstein
Introduction to C Programming
CSC 160 Computer Programming for Non-Majors Lecture #6: Function Composition Prof. Adam M. Wittenstein
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Chapter 11 Recursion. © 2004 Pearson Addison-Wesley. All rights reserved11-2 Recursion Recursion is a fundamental programming technique that can provide.
CSC 160 Computer Programming for Non-Majors Lecture #5 (continued): More on Writing Functions Prof. Adam M. Wittenstein
Creating Effective Posters & Preparing for Poster Sessions First Year Experience Fall 2013.
Click On The Pictures To Start Finished? Click Here!
MECHANICS OF WRITING C.RAGHAVA RAO.
TeachScheme, ReachJava Adelphi University Monday afternoon July 12, 2010.
Notebooks and Protocols
Scientific Notation. What is scientific notation? Scientific notation is a way of expressing really big numbers or really small numbers. It is most often.
NOTES ON EXPONENTS When working with numbers, exponents are used to tell us how many times a factor is repeated in a multiplication problem. For example,
Invitation to Computer Science, Java Version, Second Edition.
 Turn in pg 123  Estimate 3.55 * * 200 = 800  Write 60,890,000,000 in scientific notation.
Exponents and Squares Numbers and Operations. Exponents and Powers Power – the result of raising a base to an exponent. Ex. 3 2 Base – the number being.
Scientific Notation. Scientific Notation At the conclusion of our time together, you should be able to: 1.Define scientific notation 2.Convert numbers.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Introduction to JavaScript CS101 Introduction to Computing.
Scientific Notation Helping us write really tiny or really big numbers.
Scientific Notation. Pages of notebook Essential question: How do I write small and large numbers using scientific notation? Objective: I can write.
Scientific Notation. How wide is our universe (in miles)? 210,000,000,000,000,000,000,000 miles (22 zeros) This number is written in standard notation.
????????? x x x x x What do the numbers to the left have in common? They all start with a number.
Method Parameters and Overloading Version 1.0. Topics The run-time stack Pass-by-value Pass-by-reference Method overloading Stub and driver methods.
Scientific Notation Helping us write really tiny or really big numbers.
CPSC 217 T03 Week VI Part #1: A2 Post-Mortem and Functions Hubert (Sathaporn) Hu.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
Welcome To the School Year Objectives: Sign into class, Pick up a Student Information Sheet, and the Laboratory rules sheet. Also, get the student.
Be able to carry out basic mathematical operations using numbers expressed in scientific notation, without changing them to decimal notation. Be able to.
How To Be a Star How do I write an Exciting Expository Essay? First, consider the PROMPT carefully Do not rewrite or write about quote. Do not write.
R-6 How are Exponents & Radicals Simplified?
Arithmetic Expressions Function Calls Output
CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1
Method Parameters and Overloading
Creating Effective Posters & Preparing for Poster Sessions
Higher-Order Procedures
These drawings for designs show how it will be constructed both graphically and through annotation. How they will adjust, rotate or fix to surfaces. During.
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Get your homework out and check your answers.
CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1
Presentation transcript:

Section 2.5: Designing Programs

REVIEW: Design Recipe  Figure out precisely what you need to do.  Tell the computer how to do it.  Check that the computer does it right.

Design Recipe – Version 1  Figure out precisely what you need to do. 1. Understand the problem 2. Function contract 3. Write examples (in Scheme notation)  Tell the computer how to do it. 4. Write a skeleton. 5. Fill in the function body.  Check that the computer does it right. 6. Testing and debugging.

Example: X ;Purpose: ;To determine the left->right location of a UFO. ;Contract: ;X: number -> number ;Examples: (X 3) “should be” 50 (X 1.5) “should be” 35 (X 0) “should be” 0

Example: X ;Skeleton: ;(define (X t) ; …) ;Function (define (X t) (+ (* 10 t) 20)) ;Testing/Debugging ;Check over yourself, then have DrScheme check ;over, then press Run and type in each example.

Why do we need a recipe? ●Programming requires creativity, and sometimes that’s enough. ●But when programs get big and complex, it helps to have a structure to follow. ●Analogous to rules of counterpoint, harmony, etc. in music. Sonata, rondo, virelai, fugue, … ●Helps avoid “blank page syndrome”.

What are function contracts? A contract does three things: ● Specify function name ● Specify how many arguments, and what type(s) ● Specify what type is returned !

What are function contracts? A contract does three things: ● Specify function name ● Specify how many arguments, and what type(s) ● Specify what type is returned NOTE: So far we are focusing on numbers. Soon we will see other types of data.

What are function contracts? A contract does three things: ● Specify function name ● Specify how many arguments, and what type(s) ● Specify what type is returned NOTE: So far we are focusing on numbers. Soon we will see other types of data. Can’t use any function correctly without knowing its contract!

Examples of contracts + takes two or more numbers & returns a number / takes two numbers & returns a number sqrt takes one number & returns a number cos takes one number & returns a number etc.

Shorter contract notation + : number number … -> number / : number number -> number sqrt : number -> number cos : number -> number etc.

“cube”: Figure out what to do. 1. Understand the assignment yourself. Take any number and multiply it by itself. Then multiply that product by the original number. 2. Write a function contract. ; cube : takes in a number and returns a number 3. Write examples (in Scheme notation). ; (cube 0) “should be” 0 ; (cube 5) “should be” 125 ; (cube -6) “should be” -216

“cube”: Tell the computer how to do it. 4. Write the function skeleton. ; (define (cube num) ; … something involving num … ) 5. Write the function body. (define (cube num) (* num num num))

“cube”: Check if its done right. 6. Testing and debugging. Testing Type in (cube 0). Did you get 0? Type in (cube 5). Did you get 125? Type in (cube -6). Did you get -216? Debugging If the answers to any of these questions is no, look back to find your mistake.

In conclusion… The Design Recipe does not replace the need for thinking. It does guide the thinking process. It does have some concrete, automatic steps. Step 5 – Writing the function body – should hopefully be easier because of the first 4 steps. However, thinking and content-area knowledge are also essential, even when using a Design Recipe.

Next time… We have now seen Scheme functions that take in and return numbers. Next time, we will write Scheme functions that take in and return other data types, like strings and images.