CSC 160 Computer Programming for Non-Majors Lecture #2: What are Functions? Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Using CourseCompass Features You must already be registered or enrolled in a current class.
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
Chapter 1 - Introduction to Computers and the Internet Basic functions of a Computer Input – entering info into the computer (e.g. keyboard, mouse, mic,
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
SkillsUSA Membership Website. Creating a Login Access New Users: Create a login by.
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 Introduction Prof. Adam M. Wittenstein
Need your MyMathLab card with your access code Need a Valid Address Need to know Purdue’s zip code is and your course ID for your Class You.
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
Need your MyMathLab card with your access code Need a Valid Address Need to know Purdue’s zip code is and your course ID for your Class You.
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
Need your MyMathLab card with your access code Need a Valid Address Need to know Purdue’s zip code is and your course ID for your Class You.
CSC 160 Computer Programming for Non-Majors Section 1.2: Drawing a UFO 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
Downloading and Installing AutoCAD Architecture 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the software.
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
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
ES 101. Module MS Front Page Tutorial and Web Hosting.
An Introduction to Textual Programming
Dropbox is a tool the CSME will set up for its participants upon request so that participants do not have to upload podcasts to CSME servers via FTP (file.
MSM Computer Orientation PowerSchool MSM Web Page SchoolFusion/Class Pages.
Question and Answer Session for Nonprofit Leadership Faculty Facilitator: Peggy McCoey Assistant Professor and Program Director MS in Computer Information.
CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein
Downloading and Installing Autodesk Revit 2016
COP3502: Introduction to Computer Science Yashas Shankar.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
Go to your school’s web locker site Your user name is the first letter of your first name, the first four letters of.
Math – What is a Function? 1. 2 input output function.
Do Now Find the domain & range:. Answers to Homework
My Python Programmes NAME:.
You have just scheduled an appointment with Margaret Smith, a client, for Thursday, February 19 th at noon. It is currently February 12 th.
Introduction to Taverna Online and Interaction service Aleksandra Pawlik University of Manchester.
Uploading documents to the site Сlick “Add document” on the home page To send several files enable Add-on “Microsoft Office”
You will need Dev C++ to help you with this project. If you do not already have this programming tool on your device you can visit
Thursday 14 th October Save this file! Make sure it goes in your LEO folder. Make a new folder in your LEO folder – call it Toocool. Online conference.
Links Building a Website Lesson 5. Links There are various ways to use links on a website: Link to other sites Link to other pages on the same site .
Copy of the from the secure website - click on the AccoridaLife.zip link.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
PHP Form Processing * referenced from
 This is an online tool that one can use to share with multiple users either by saving and printing their creation or sending the link to someone else.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Development Environment
About Dropbox Dropbox is a tool the CSME will set up for its participants upon request so that participants do not have to upload podcasts to CSME servers.
Functions & Graphing.
Introduction to TouchDevelop
Programming in JavaScript
Programming in JavaScript
Programming in JavaScript
Taking Cornell Notes.
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Lecture #2: What are Functions? Prof. Adam M. Wittenstein

Programs Are Functions Any Scheme program is made up of one or more functions. There are two types of functions: user defined and pre-defined. Certain “pre-defined” functions, like +, and, string-append, image-width, and so on are already written into DrScheme. We look at some of these today. If you wish to write a program that requires a function that is not pre-defined, then you need to write it yourself. (We will see how to do this in Chapter 4 of Simply Scheme.)

Exploring Functions Before we learn how to write functions, we need to understand what they are. In high school, your math teacher wrote f(x) = x + 3 on the board. But what does this mean? And what about functions that involve no numbers or math at all? We will answer these questions today!

Downloads for the semester Download DrScheme Version 301: Download and install the additional file with some predefined functions to practice with: Close and reopen DrScheme. Go to Language>Choose Language>Simply Scheme. Then click Run.

Using Someone’s Program Today, we will actually use a computer program that someone else wrote to learn what functions are. (We could just as easily learn topics not even remotely related to Computers with a computer program.) This program is called “functions.scm”. It was written by the author of our textbook for our use. Notice that we can use programs without knowing how they were written.

Downloading “functions.scm” Only repeat when changing computers Go to the links page on the class website. Download “functions.scm” and save it to the folder “C:\ProgramFiles\PLT”. Repeat every time you use a computer In DrScheme’s Interactions Window, type: --(load “C:\\Program Files\\PLT\\functions.scm”) & Enter. Be careful of spaces and capital letters! --(functions) & Enter twice.

Example 1: The + function Type in the function name, +. Then Enter. Type in the first argument, 3. Then Enter. Type in the second argument, 5. Then Enter. You should get an answer of 8. Try your own example with multiplication, use the * symbol.

Example 2: first Type in the function name, first. Enter. Type in the argument, hello. Enter. You should get an answer of h (the first letter). Try your own example with last. Try your own example with butfirst.

Data Types We have seen two types of data: numbers and words. There are many other types of data that Scheme officially recognizes. Functions can take arguments of any recognized data type. Try the + function again, with arguments 6 and seven. What happens?

Domain and Range The domain is all acceptable inputs (also known as arguments). The range is all acceptable outputs (also known as answers). The domain of + is “all pairs of numbers”. What is the range of +? What is the range of first?

Example 3: sentence Type in the function name, sentence. Enter. Type in the first argument, (when I get). Enter. Type in the second argument, home. Enter. You should get the answer: (when I get home). Try the same example, but put parentheses around home. Try butfirst again but use the arguments: (when I get) and (home).

Example 4: The < function Type in the function name, <. Enter. Type in the argument, 3. Enter. Type in the argument, 5. Enter. You should get an answer of #t (true). Try your own examples with =, >, >=, and <=.

Example 5: number-of-arguments Function name: number-of-arguments. Argument: -. You should get an answer of 2, since - takes in 2 arguments. Try the other functions you have seen today: first, last, sentence, butfirst, and >.

So what are functions? The idea of function is at the heart of Computer Science (just as with Math). However, in Computer Science, functions work on all types of data, not just numbers. Functions give the Programmer a way to think about process. That is, a function takes something and does something to it. For example, + takes something (the numbers 3 and 5) and does something to it (adds them).

More on Data Types Now we have seen 5 data types: --numbers--booleans --words--functions --sentences While functions are themselves a data type (“function as object”), we will rarely use them as a data type this semester. The first goal of a programmer is to understand “function as process”. That means, takes something and does something to it.

Preparing for Next Class

In summary… Today, we learned what a function is. Next time… We will work with functions directly in DrScheme. We will see what happens when a function has more than one operation.

Reminders… Homework #1 is due SUNDAY at 11:59pm. Send by to: Before next class, please read: --Simply Scheme, Chapter 3 (all) --How to Design Programs, Chapter 2 (introduction and Section 1 only) Have a happy Labor Day!