CSC 160 Computer Programming for Non-Majors Lecture #5a: Defining Functions on Words and Sentences Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
PLEASE CLICK. Once you have logged in you will be greeted with your Home Page See the Administration Section in the lower left The Course Files tab is.
Advertisements

Section 9.3 Multiplying and Dividing Radical Expressions.
January th grade. Tuesday 10 th grade 4 th period  You need your language books.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences (continued) Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #9: Booleans Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #4: Defining Variables Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Images: Another Form of Symbolic Data Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images Prof. Adam M. Wittenstein
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
CSC 160 Computer Programming for Non-Majors Chapter 6: Structures Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #11: Conditionals II Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Syntax Rules Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3c: Working with Pictures (continued) Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 4: Conditional Expressions and Functions 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
CSC 160 Computer Programming for Non-Majors Lecture #2: What are Functions? Prof. Adam M. Wittenstein
5th Grade Common Core Math Practice and Solutions for 5th Grade Common Core Math Standard 5.NBT.3 Multiple Choice Set #1 without Answers Multiple Choice.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #6: Function Composition Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3b: Working with Pictures Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5 (continued): More on Writing Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #12: Syntax and Semantics Prof. Adam M. Wittenstein
Hello, world! Dissect HelloWorld.java Compile it Run it.
Exponential Notation Significant Figures
1 Significant Digits Reflect the accuracy of the measurement and the precision of the measuring device. All the figures known with certainty plus one extra.
Lesson Objective: I can…
CECS 5260 Computer Graphic for Mediated Communications I. SheffieldAssignment 4 August 6, 2012 Solving Equations.
COMP More About Classes Yi Hong May 22, 2015.
Algebraic and Symbolic Reasoning
Chapter P Prerequisites: Fundamental Concepts of Algebra
Welcome to Technology Ms. Swartwout.
Relations And Functions. A relation from non empty set A to a non empty set B is a subset of cartesian product of A x B. This is a relation The domain.
Chapter P Prerequisites: Fundamental Concepts of Algebra P.4: Polynomials.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Roots and Radicals. Radicals (also called roots) are directly related to exponents.
CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables.
CSC 107 – Programming For Science. Today’s Goal  Discuss how to hand data to functions  Review loopholes in variables & scoping rules  Ways to get.
Building Java Programs
Significant Figure Rules. Rule Number 1 All non zero digits are significant. Examples 1179 – 4 significant figures significant figures
CM-220 Unit 1 Seminar Margaret Baker. Seminar Rules Try to be on time. Be respectful. We will have many people attending, so stay on task. If you enter.
Good Morning, Precalculus! To prepare for class: 1. Take out your DO NOW sheet and start today's DO NOW! Do Now: Solve for principal values of x. Express.
Multiplying and Dividing Signed Integers
Grade 8 Number Sense and Numeration Multiplying and Dividing Integers.
Solving an equation with one unknown From arithmetic to algebra Modifying equations in algebra.
Preview Lesson Starter Objectives Accuracy and Precision Significant Figures Scientific Notation Using Sample Problems Direct Proportions Inverse Proportions.
 Chapter 8: Indices By: Yeon. Task  Chapter 8  Section A, B, C Read and make your own notes on PowerPoint Be ready to explain to Mrs. Taher on Monday.
Warm Up = = (-8.27) = – = – (-38.93) =
By Irma Crespo Formal Proof. The Formal Proof A formal proof of a sentence is a sequence of statements wherein each statement follows the form of the.
Warm Up What algebraic equation shows the sentence four plus a number divided by six is equal to the product of twelve and the same number?
Adding and Subtracting Decimals.  Adding Decimals  Subtracting Decimals  Estimating While Adding or Subtracting Decimals  Solving problems by Adding.
Roots and Radicals. Radicals (also called roots) are directly related to exponents. Roots and Radicals.
REVIEW A relation is a set of ordered pairs. {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} This is a relation The domain is the set of all x values.
Significant Figures.
Unit 1/2 Estimation and Computation Students will know that…
CSc 2310 Principles of Programming (Java)
Express the following rule in function notation: “subtract 4, then divide by 5”. Select the correct answer: {image}
Welcome to Science!!! Things to know!.
Bell Ringer Throw Back Thursday
Bell Ringer Throw Back Thursday
Dear Power point User, This power point will be best viewed as a slideshow. At the top of the page click on slideshow, then click from the beginning.
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Lecture #5a: Defining Functions on Words and Sentences Prof. Adam M. Wittenstein

A preview… Last week, we saw how to (and how not to) define functions using several examples involving numbers. Today, we will apply the same rule for defining functions to words and sentences.

Functions without Numbers Here is a function that takes a U.S. state as its argument. Alabama -> Montgomery Arkansas -> Little Rock California -> Sacramento What does this function do?

Functions without Numbers Here is a function that takes a U.S. state as its argument. Alabama -> Montgomery Arkansas -> Little Rock California -> Sacramento What does this function do? It returns the capital of a given state.

Recall the following… Last time, we discussed not using function names as parameter names, as in the following illegal example: (define (area square) (square square)) Also, recall that word and sentence are not only data types, but also the names of two predefined functions.

Words of Caution It is often very tempting to use word or sentence as a parameter name. Do not do this! Why not? Because, then you cannot use the word or sentence functions when defining your function. This is the same reason we could not use the square function when square was a parameter.

Example 1: plural Define a Scheme function that pluralizes a word by adding an “s”. Assume for now that all English words can be made plural simply by adding “s” (even though we know this is not the case). Be sure to write an example in Scheme notation with its expected answer BEFORE defining the function.

Solution ; (plural ‘cat) “should be” cats ; func-name = plural ; param-name = n ; expression = (word n ‘s) (define (plural n) (word n ‘s)) ;As always, after defining a function, make sure ;your example returns the answer that is expected.

Example 2: second Define a Scheme function second that selects any of the following: --the second letter of a word --the second word of a sentence --the second digit of a number. Start by writing examples for each case: ;(second ‘hello) “should be” ‘e ;(second ‘(it is Tuesday)) “should be” ‘is ;(second 10306) “should be” 0

Solution ; func-name = second ; param-name = whole ; expression = (item 2 whole) (define (second whole) (item 2 whole))

CW3: For Section 01 only (the 3:05 class) In Simply Scheme mode: Define a Scheme function greet that takes in a single name (like ‘adam) and says hello to it. Define a Scheme function greet that takes in a single name (like ‘adam) and says hello to it. EXTRA CREDIT: Define a Scheme function greet2 that takes in a full name (like ‘adam ‘wittenstein) and says hello to it. EXTRA CREDIT: Define a Scheme function greet2 that takes in a full name (like ‘adam ‘wittenstein) and says hello to it. Be sure to write an example in Scheme notation, before defining each of the functions. Be sure to write an example in Scheme notation, before defining each of the functions. Submit using the Digital Dropbox on Blackboard with the following file names: Submit using the Digital Dropbox on Blackboard with the following file names: -- CW3-01[LastName]Def.scm

In summary… Regardless of the data type, we can define functions (and write examples) in exactly the same way. We will define functions with images and booleans in the coming weeks. Example 2 (and CW3) show that you can even involve multiple data types at the same time, as long as you are careful to follows the rules of any (predefined) functions you are using. Read How to Design Programs section 2.5 BEFORE our next class.