CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
MA 1128: Lecture 16 – 3/29/11 Rational Equations Roots and Radicals.
Advertisements

Math 191: Mathematics and Geometry for Designers Lecture Notes Based on The Book Mathematics in Our World by Allan G. Bluman.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 8 By Herbert I. Gross and Richard A. Medeiros next.
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 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 #1: What is Programming? 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
Section 2.4: Errors. Common errors ● Mismatched parentheses ● Omitting space after operator or between numbers ● Putting operator between operands.
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
Section 1.1: Flying a UFO (continued). Conversion recipe 1)Expand abbreviations 2)Parenthesize all subexpressions that have an operator. Should end up.
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 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
Student’s registration and class joining. Student’s registration.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5a: Defining Functions on Words and 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
Improving Achievement The CPC Way © James M. Furukawa, J.D., Ph.D.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 5 By Herbert I. Gross and Richard A. Medeiros next.
Exponential Notation Significant Figures
How to Get Started In MyLabsPlus
Multiplication and Division Addition and Subtraction PracticeExponentsParenthesesHomeQuizIntroduction Objective and Standards Please Excuse My Dear Aunt.
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
Computing with Numbers CSC 161: The Art of Programming Prof. Henry Kautz 9/14/2009.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Calculating with Significant Figures
Working with Significant Figures. Exact Numbers Some numbers are exact, either because: We count them (there are 14 elephants) By definition (1 inch =
Welcome to AC301, Intermediate Accounting II Professor Michael J. Bootsma Unit 1 Seminar – Excel Template Guide.
ORDER OF OPERATIONS x 2 Evaluate the following arithmetic expression: x 2 Each student interpreted the problem differently, resulting in.
CSC Programming I Lecture 5 August 30, 2002.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CourseCompass Courseware How to Use Your DVM 0030 CourseCompass Courseware Navigate Success in Mathematics!! to Navigate Your Way to Success in Mathematics!!
Introduction to Programming with RAPTOR
David Stotts Computer Science Department UNC Chapel Hill.
To begin click: File, New, then select Design Familiarize yourself with the controls on the page. Then use the maximise button the make the window fill.
The AP Calculus AB Exam How to Survive and Thrive.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
Ch. 1: Introduction: Physics and Measurement. Estimating.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
1 Excel Lesson 2 Organizing the Worksheet & Formulas Microsoft Office 2010 Introductory Pasewark & Pasewark.
 Columns  Rows  Cells  Ranges  Cell addresses  Column headers  Row headers  Formulas  Spreadsheet.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
An Introduction to Prime Factorization by Mrs. Gress
Few More Math Operators
Exponential Notation 1-3.
Eclipse Navigation & Usage.
MS-Excel Part 1.
We’ll be spending minutes talking about Quiz 1 that you’ll be taking at the next class session before you take the Gateway Quiz today.
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Blackboard Committee 2017 Bb Training Program
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein

A preview… ● Last time we evaluated functions using a program. ● Today, and for the rest of the semester, we will call (aka evaluate) functions using DrScheme directly. ● Since we have not learned how to define our own functions yet, we will just call predefined functions today. ● However, the way you call a user-defined function is the same as the way you call predefined functions.

I. Basic Arithmetic: A Programming Perspective

What's really going on inside ordinary arithmetic?

The operation (addition) is circled. What is being operated on (the numbers) have squares around them.

What's really going on inside ordinary arithmetic?

Ambiguity

We resolve the ambiguity with PEMDAS.

Ambiguity The multiplication occurs before the addition.

Math grammar can be confusing… 1)Some operators go between two operands; others go before one operand; some require parentheses around operand, some don’t. 2)Need PEMDAS to resolve ambiguity. 3)Sometimes there's no visible operator; defaults to multiplication. 4)(3+4) means the same as 3+4, or even ((3+4)).

Scheme has a simpler grammar… 1)All operators go before however many operands they need. 2)All subexpressions must have parentheses around them (including the operator). 3)No hidden operators; if you mean *, say it. 4)No extra parentheses allowed; exactly one pair of parentheses per operator.

Syntax Rule #1: Calling a Function ● (function-name expression expression …) ● Example: ( )

Arithmetic: Old vs. new notation ● ● * 5 ● (3 + 4) * 5

Arithmetic: Old vs. new notation ● ● * 5 ● (3 + 4) * 5 ● (+ 3 4) ● (+ 3 (* 4 5)) ● (* (+ 3 4) 5)

A Note on Numbers The online book explanation may confuse some of you. That is okay. Here is what you need to know… ● Pi (3.14…..) and Square Root of 2 (1.41….) are two examples of numbers where the digits continue without a pattern. ● Since we cannot go on writing indefinitely, we round them off to just a few decimal places, say 3.14 or 1.4. ● When Scheme has rounded a number, it puts #i before the number.

II. Using DrScheme

Using DrScheme

Set to “Simply Scheme” For most of the semester, we will use the Simply Scheme language level. If it is changed (e.g., you are using a public computer on campus), use these steps to restore Simply Scheme mode: ● Select Choose Language... from the Languages menu. A dialog box appears with a choice control (a.k.a. ``pop-up menu'') at the top. ● Choose the Simply Scheme language from the hierarchical choice list, then click OK.

Set to “Simply Scheme” ● Click the Run button. After clicking Run, the lower window indicates that the current language is Simply Scheme. ● You need to set the language level only once until you (or someone else using DrScheme on your computer) change languages. When you quit and restart DrScheme, the language setting is preserved.

Using the two windows ● The top area, the definitions window, is for defining new programs. We'll explain how to use this window next week. ● The bottom area, the interactions window, is for using programs once they are defined. ● Fortunately, Simply Scheme already has some programs written inside of it for us to use. Some examples are +, -, *, /, first, and sentence. ● To find 3 + 4, type it into the interactions window the Scheme way: (+ 3 4). After hitting enter, you should get 7.

Example 1: Translation For each mathematical expression given below, a) find its answer using paper and pen (or a calculator). b) translate it into Scheme notation. c) type into DrScheme’s interactions window and verify that the answer is what you expect. ● 3 * 5 ● ● 8 - (2 * 3) ● (8 - 2) * 3 ● √(5 + 4) hint: sqrt ● √( ) hint: 3 2 really means 3 * 3

III. Preparing for Next Class

In summary… ● Today, we saw how to call functions involving numbers. ● However, what we learned today is not peculiar to numbers. Next time… ● We will see how Scheme steps through multi-step expressions. ● We will call functions involving other types of data. ● Please read all of Chapter 5 in Simply Scheme before next class.