ITEC 109 Lecture 14/15 Strings + Functions. Review Strings –What can we do? –Why?

Slides:



Advertisements
Similar presentations
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Advertisements

Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
ITEC 109 Lecture 15 Advanced functions. Functions (2) Review Functions –Parameters –Return statements –Variable scope.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
1 Lecture 6 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
1 Modularity In “C”. 2 General Syntax data_type function_Name (parameter list) { … return expression; // return output } Body of the function is a compound.
Chapter 6: User-Defined Functions I
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
ITEC 320 Lecture 16 Packages (1). Review Questions? –HW –Exam Nested records –Benefits –Downsides.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Programming.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
CS346 Javascript -3 Module 3 JavaScript Variables.
JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
Passing Arguments, Local/Global Variables Writing Functions( ) (Part 2)
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Python Let’s get started!.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Week 8 - Friday.  What did we talk about last time?  Static methods.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
ITEC 109 Lecture 20 Arrays / Lists. Arrays Review For loops –Rationale –Syntax –Examples.
Loops and Simple Functions COSC Review: While Loops Typically used when the number of times the loop will execute is indefinite Typically used when.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
Functions Skill Area 314 Part B. Lecture Overview Functions Function Prototypes Function Definitions Local Variables Global Variables Default Parameters.
JavaScript Modularity. Goals By the end of this lecture, you should … Understand why programmers use modularity. Understand how to create a function in.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Topics Introduction to Functions Defining and Calling a Void Function
Chapter 6: User-Defined Functions I
Topic Pre-processor cout To output a message.
Python Let’s get started!.
CS 1110 Introduction to Programming Spring 2017
Week 8 - Friday CS 121.
Functions CIS 40 – Introduction to Programming in Python
Functions.
User-Defined Functions
Method Mark and Lyubo.
Introduction to C++ Programming
Functions A function is a “pre-packaged” block of code written to perform a well-defined task Why? Code sharing and reusability Reduces errors Write and.
Example 1.
Writing Functions.
Topics Introduction to Functions Defining and Calling a Void Function
Topics Introduction to Functions Defining and Calling a Function
Loops and Simple Functions
COMPUTER PROGRAMMING SKILLS
ITM 352 Functions.
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Presentation transcript:

ITEC 109 Lecture 14/15 Strings + Functions

Review Strings –What can we do? –Why?

Functions Example Find the first character in the first name and store it in a string called formatted Print out “Welcome” then print out the value of formatted then a. then a space then the last name Andrew RayA. Ray

Functions Backgroun d

Functions Methods Any that you remember? Caesar A->C, B->D, etc… Substitution –Replace A with 7 –Replace E with 3

Functions Sample What code would you need to write to create this encryption ?

Functions Objectives Functions –Parameters –Return statements –Scope –Examples

Functions Basics What is the purpose of functions? What are the benefits? What are the downsides?

Functions Visualizatio n Current view of a program New view 0 – x=3; 1 – y=x*2; 2 – printNow(y); Function call Function return

Functions Function Syntax def [Name] (): –def firstFunction(): Name is just like a variable name ( begins parameters ) ends parameters : begins the code Tab delimited (function begin / end implied)

Functions Syntax def FunctionName(): printNow(“I am a function”) def FunctionName(): printNow(“I am a function”) FunctionName() Function call Function body

Functions Visualizatio n def FunctionName(): printNow(“I am a function”) FunctionName() Step 1: Ignore function Step 2: Call Function Step 3: Execute Function Step 4: Return back to main Print Step 5: End program

Functions Return Have a function send info back 2 way street Return trip def secretValue(): return 15 myValue = secretValue() printNow(myValue)

Functions Parameter s Provide input to a function –Comma separated list A copy of other variables Required when function is called def add(var1,var2): return var1+var2; result = add(3,4) printNow(result)

Functions Scope Where variables can be used def example(): test=“Hello” printNow(test) test=“apple” example() printNow(test) Is this test the same as this test? Answer: not it isn’t

Functions Rules Functions are like prisons, you don’t have the freedom to go outside One way in –Parameters One way out –Return statement

Functions Example Writing a function that reads an int, squares, and returns it [Math.pow(var,2)]

Functions Example Writing a function that performs the quadratic formula

Functions Example Write two functions that return a separate piece of the of a string First|Last getFirst / getLast

Functions Philosophy Group information together Make it useful Subdivide tasks to developers

Functions Review Functions Parameters Return types