1. User-Defined Functions & Subroutines Part 2 Outline

Size: px
Start display at page:

Download "1. User-Defined Functions & Subroutines Part 2 Outline"

Transcription

1 User-Defined Functions Subroutines Part 2 Outline 1. User-Defined Functions Subroutines Part 2 Outline 2. Argument Order When Passing Arrays 3. Code Reuse Is GOOD GOOD GOOD 4. Reusing User-Defined Functions via the INCLUDE Statement 5. The Meaning of the INCLUDE Statement 6. INCLUDE Statement Example #1 7. INCLUDE Statement Example #2 8. Example #2 Without INCLUDE Statement 9. Actual Arguments vs. Formal Arguments 10. Argument Order 11. Argument Order Within the Function Is Arbitrary 12. The Order in the Argument List in the Function Definition Needn t Match the Order in the Argument Declaration in the Function Definition 13. Argument Order of Function Definition MUST EXACTLY MATCH Argument Order of Function Call 14. Argument Order Conventions: Pick One and Stick to It 15. Side Effects 16. Side Effects Example 17. A Function That Doesn t Return a Value 18. Subroutines 19. Subroutine Call Example 20. Subroutine Call Example Runs 21. Why Do We Like Code Reuse?/ Why Do We Like User-Defined Procedures? See Programming in Fortran 90/95, 1st or 2nd edition, Chapters Argument Order When Passing Arrays REAL FUNCTION mean (array, REAL,DIMENSION(, INTENT(IN) :: array... END FUNCTION mean When we pass an array to a function as an argument, we also need to pass its length, because the declared length of the array in the main program (that is, in the array s DIMENSION attribute) is not automatically known by the function. When passing an array as a function argument and therefore passing the length of the array as well it does not matter what order the formal arguments appear in the function s formal argument list. (It matters very much, however, that the order of the formal arguments in the function s formal argument list exactly match the order of the actual arguments in the function call.) Inside the function definition, the order of the formal argument declarations MATTERS A LOT. Specifically, the length argument MUST be declared BEFORE the array argument whose length it specifies. Then, in the declaration of the array argument, the length in the array s DIMENSION attribute will be the length argument. IMPORTANT NOTE: the length argument MUST be an INTEGER. 2

2 Code Reuse Is GOOD GOOD GOOD We like to make our programming experiences reasonably efficient. Often, we find ourselves doing a particular task the same way in many different contexts. It doesn t make sense, from a software development point of view, to have to type in the same piece of source code over and over and over. So, in solving a new problem that is, in writing a new program we want to be able to reuse as much existing source code as we possibly can. Not surprisingly, this is called code reuse. Code reuse is GOOD GOOD GOOD. It makes us happy as programmers, because: 1. we can get to the solution of a new problem much more quickly; 2. we can thoroughly test and debug a piece of source code that does a common, well-defined task, and then be confident that it will work well in a new context. Reusing User-Defined Functions via the INCLUDE Statement In the two example programs at the end of the previous slide packet, we saw two copies of the function definition for cube root, and these two copies were character-for-character identical. It d be a big waste of time to have to type the exact same function definition over and over and over if we wanted to use it multiple times, especially if our function definition was, say, 100 lines long (which is not at all unreasonable). So, Fortran 90 allows us to put the function in a completely separate Fortran 90 source file, and to include it when we re compiling, by using an INCLUDE statement. The general form of the INCLUDE statement is: or: For example: INCLUDE "filename" INCLUDE filename INCLUDE "cube root.f90" What does this mean? 3 4

3 The Meaning of the INCLUDE Statement When the compiler encounters an INCLUDE statement, it brings the contents of the included source file into the primary source file that it s currently compiling. So, the upshot is that the compiler ends up treating the primary source file exactly as if you had typed the contents of the included file into it, in the place where the INCLUDE statement is. This promotes code reuse. INCLUDE Statement Example #1 % cat cube_root_scalarinc.f90 PROGRAM cube_root_scalar INTEGER,PARAMETER :: number_of_values = 3 REAL :: input_value1, cube_root_value1 REAL :: input_value2, cube_root_value2 REAL :: input_value3, cube_root_value3 REAL,EXTERNAL :: cube_root! Function return type PRINT *, "What ", number_of_values, " real numbers would you like ", "the cube roots of?" READ *, input_value1, input_value2, input_value3 cube_root_value1 = cube_root(input_value1) cube_root_value2 = cube_root(input_value2) cube_root_value3 = cube_root(input_value3) PRINT *, "The cube root of ", input_value1, " is ", cube_root_value1, "." PRINT *, "The cube root of ", input_value2, " is ", cube_root_value2, "." PRINT *, "The cube root of ", input_value3, " is ", cube_root_value3, "." END PROGRAM cube_root_scalar INCLUDE "cube_root.f90"!! NOTICE NOTICE NOTICE % cat cube_root.f90 REAL FUNCTION cube_root (original_value) REAL,INTENT(IN) :: original_value REAL,PARAMETER :: cube_root_power = 1.0 / 3.0 cube_root = original_value ** cube_root_power END FUNCTION cube_root % f95 -o cube_root_scalarinc cube_root_scalarinc.f90 % cube_root_scalarinc What 3 real numbers would you like the cube roots of? The cube root of is The cube root of is The cube root of E+02 is

4 INCLUDE Statement Example #2 % cat cube_root_arrayinc.f90 PROGRAM cube_root_array INTEGER,PARAMETER :: first_input = 1 INTEGER,PARAMETER :: number_of_inputs = 5 REAL,DIMENSION(number_of_inputs) :: input_value, cube_root_value INTEGER :: index REAL,EXTERNAL :: cube_root PRINT *, "What ", number_of_inputs, " real numbers" PRINT *, " would you like the cube roots of?" READ *, (input_value(index), index = first_input, number_of_inputs) DO index = first_input, number_of_inputs cube_root_value(index) = cube_root(input_value(index)) END DO!! index = first_input, number_of_inputs DO index = first_input, number_of_inputs PRINT *, "The cube root of ", input_value(index), " is ", cube_root_value(index), "." END DO!! index = first_input, number_of_inputs END PROGRAM cube_root_array INCLUDE "cube_root.f90" % cat cube_root.f90 REAL FUNCTION cube_root (original_value) REAL,INTENT(IN) :: original_value REAL,PARAMETER :: cube_root_power = 1.0 / 3.0 cube_root = original_value ** cube_root_power END FUNCTION cube_root % f95 -o cube_root_arrayinc cube_root_arrayinc.f90 % cube_root_arrayinc What 5 real numbers would you like the cube roots of? The cube root of is The cube root of is The cube root of E+02 is The cube root of E+02 is The cube root of E+02 is Example #2 Without INCLUDE Statement % cat cube_root_array.f90 PROGRAM cube_root_array INTEGER,PARAMETER :: first_input = 1 INTEGER,PARAMETER :: number_of_inputs = 5 REAL,DIMENSION(number_of_inputs) :: input_value, cube_root_value INTEGER :: index REAL,EXTERNAL :: cube_root PRINT *, "What ", number_of_inputs, " real numbers" PRINT *, " would you like the cube roots of?" READ *, (input_value(index), index = first_input, number_of_inputs) DO index = first_input, number_of_inputs cube_root_value(index) = cube_root(input_value(index)) END DO!! index = first_input, number_of_inputs DO index = first_input, number_of_inputs PRINT *, "The cube root of ", input_value(index), " is ", cube_root_value(index), "." END DO!! index = first_input, number_of_inputs END PROGRAM cube_root_array REAL FUNCTION cube_root (original_value) REAL,INTENT(IN) :: original_value REAL,PARAMETER :: cube_root_power = 1.0 / 3.0 cube_root = original_value ** cube_root_power END FUNCTION cube_root % f95 -o cube_root_array cube_root_array.f90 % cube_root_array What 5 real numbers would you like the cube roots of? The cube root of is The cube root of is The cube root of E+02 is The cube root of E+02 is The cube root of E+02 is

5 Actual Arguments vs. Formal Arguments In our cube root examples, we ve seen function calls that look like this: We say that cube root value1 = cube root(input value1) this assignment statement calls the user-defined function cube root using as its actual argument the variable input value1 which corresponds to the function definition s formal argument original value and returns the cube root of the value of stored in the variable input value1. The actual argument is the argument that appears in the call to the function (for example, in the main program). The formal argument which in Fortran 90 is also called the dummy argument is the argument that appears in the definition of the function. Argument Order Suppose that a function has multiple arguments. Does their order matter? No, no, yes and yes. No, in the sense that the order of arguments in the function definition is arbitrary. No, in the sense that the order of arguments in the function definition does not have to match the order of argument declarations in the function definition. Yes, in the sense that the order of the formal arguments in the function definition must EXACTLY MATCH the order of the actual arguments in the function call. Yes, in the sense that it s a good idea to set a convention for how you re going to order your arguments, and then to stick to that convention. Not surprisingly, the mathematical case is the same. In a mathematical function definition like if we want the value of then is the formal argument of the function argument., and is the actual 9 10

6 Argument Order Within the Function Is Arbitrary REAL FUNCTION mean (array, REAL,DIMENSION(, INTENT(IN) :: array REAL, PARAMETER :: initial_sum = 0.0 INTEGER,PARAMETER :: minimum_number_of_elements = 1 REAL :: sum INTEGER :: element IF (number_of_elements < minimum_ THEN PRINT *, "ERROR: can t have an array ", "of length ", number_of_elements, ":" PRINT *, " it must have at least ", minimum_number_of_elements, " element." END IF!! (number_of_elements < min...) sum = initial_sum DO element = first_element, number_of_elements sum = sum + array(element) END DO!! element = first_element, number_of_elements mean = sum / number_of_elements END FUNCTION mean REAL FUNCTION mean (number_of_elements, array)!! <-- NOTICE! REAL,DIMENSION(, INTENT(IN) :: array REAL, PARAMETER :: initial_sum = 0.0 INTEGER,PARAMETER :: minimum_number_of_elements = 1 REAL :: sum INTEGER :: element IF (number_of_elements < minimum_ THEN PRINT *, "ERROR: can t have an array ", "of length ", number_of_elements, ":" PRINT *, " it must have at least ", minimum_number_of_elements, " element." END IF!! (number_of_elements < min...) sum = initial_sum DO element = first_element, number_of_elements sum = sum + array(element) END DO!! element = first_element, number_of_elements mean = sum / number_of_elements END FUNCTION mean The Order in the Argument List in the Function Definition Needn t Match the Order of Argument Declarations in the Function Definition REAL FUNCTION mean (array, REAL,DIMENSION(, INTENT(IN) :: array REAL, PARAMETER :: initial_sum = 0.0 INTEGER,PARAMETER :: minimum_number_of_elements = 1 REAL :: sum INTEGER :: element IF (number_of_elements < minimum_ THEN PRINT *, "ERROR: can t have an array ", "of length ", number_of_elements, ":" PRINT *, " it must have at least ", minimum_number_of_elements, " element." END IF!! (number_of_elements < min...) sum = initial_sum DO element = first_element, number_of_elements sum = sum + array(element) END DO!! element = first_element, number_of_elements mean = sum / number_of_elements END FUNCTION mean 11 12

7 Argument Order of Function Definition MUST EXACTLY MATCH Argument Order of Function Call % cat meanfunctestrevarg.f90 PROGRAM mean_function_test... input_mean = mean(input_value,... END PROGRAM mean_function_test REAL FUNCTION mean (number_of_elements, array)!! <-- NOTICE! REAL,DIMENSION(, INTENT(IN) :: array REAL, PARAMETER :: initial_sum = 0.0 INTEGER,PARAMETER :: minimum_number_of_elements = 1 REAL :: sum INTEGER :: element IF (number_of_elements < minimum_ THEN PRINT *, "ERROR: can t have an array ", "of length ", number_of_elements, ":" PRINT *, " it must have at least ", minimum_number_of_elements, " element." END IF!! (number_of_elements < min...) sum = initial_sum DO element = first_element, number_of_elements sum = sum + array(element) END DO!! element = first_element, number_of_elements mean = sum / number_of_elements END FUNCTION mean % f95 -o meanfunctestrevarg meanfunctestrevarg.f90 Error: meanfunctestrevarg.f90: Argument NUMBER_OF_ELEMENTS (no. 1) in reference to MEAN from MEAN_FUNCTION_TEST has the wrong data type Error: meanfunctestrevarg.f90: Argument ARRAY (no. 2) in reference to MEAN from MEAN_FUNCTION_TEST has the wrong data type [f95 error termination] Argument Order Conventions: Pick One and Stick to It In general, it s good practice to pick a convention for how you will order your argument lists, and to stick with that convention. The reason for this is that, as you develop your program, you ll jump around a lot from place to place in the program, and you ll forget what you did in the other parts of the program. So, pick an argument order convention and stick to it. Here s an example: 1. all arrays with INTENT(OUT), in alphabetical order, and then 2. all arrays with INTENT(IN), in alphabetical order, and then 3. all lengths of arrays with INTENT(OUT), in the same order as those arrays, and then 4. all lengths of arrays with INTENT(IN), in the same order as those arrays, and then 5. all non-length scalars, in alphabetical order. Given this convention: when you define a new function, you know what order to use in the function definition; when you call a function that you ve defined, you know what order to use in the function call

8 Side Effects A side effect of a function is something that the function does other than calculate and return its return value, and that affects something other than the values of local variables. For example, consider this function: INTEGER FUNCTION input_number_of_elements () INTEGER,PARAMETER :: minimum_number_of_elements = 1 PRINT *, "" PRINT *, " the array to have (at least ", minimum_number_of_elements, ")?" READ *, input_number_of_elements IF (input_number_of_elements < minimum_ THEN PRINT *, "Too few, idiot!" END IF!! (input_number_of_elements <... ) END FUNCTION input_number_of_elements This function has the side effect of outputting a prompt message to the user, as well as of idiotproofing (i.e., outputting an error message and terminating if needed). Side Effects Example % cat userarray.f90 PROGRAM user_array_test INTEGER,PARAMETER :: allocate_success = 0 REAL,DIMENSION(:),ALLOCATABLE :: element INTEGER :: number_of_elements INTEGER :: allocate_status INTEGER,EXTERNAL :: input_number_of_elements number_of_elements = input_number_of_elements() PRINT *, "The number of elements that you ", "plan to input is ", number_of_elements, "." ALLOCATE(element(, STAT=allocate_status) IF (allocate_status /= allocate_success) THEN PRINT *, "ERROR: couldn t allocate the ", "array named element" PRINT *, " of ", number_of_elements, " elements." END IF!! (allocate_status /= allocate_success) END PROGRAM user_array_test INCLUDE "inputnumelts.f90" % cat inputnumelts.f90 INTEGER FUNCTION input_number_of_elements () INTEGER,PARAMETER :: minimum_number_of_elements = 1 PRINT *, "" PRINT *, " the array to have (at least ", minimum_number_of_elements, ")?" READ *, input_number_of_elements IF (input_number_of_elements < minimum_ THEN PRINT *, "Too few, idiot!" END IF!! (input_number_of_elements <... ) END FUNCTION input_number_of_elements f95 -o userarray userarray.f90 % userarray 0 Too few, idiot! % userarray 10 The number of elements that you plan to input is 10. % userarray The number of elements that you plan to input is ERROR: couldn t allocate the array named element of elements

9 A Function That Doesn t Return a Value Suppose we wanted, for example, to read values into an array of a specified length. We might define a function like so: INTEGER FUNCTION input_elements (element, REAL,DIMENSION(, INTENT(OUT) :: element INTEGER :: index PRINT *, "What are the ", number_of_elements, " elements of the array?" READ *, (element(index), index = first_element, input_elements =??? END FUNCTION input_elements What on earth are we going to return? The best answer is, we re not going to return anything. But if we re not returning anything, then it s not a function. So, we have a special construct in case we don t want to return anything: a subroutine. Subroutines A subroutine is exactly like a function, except that: 1. The keyword FUNCTION is replaced by the keyword SUBROUTINE. So, the subroutine has a SUBROUTINE statement and an END SUBROUTINE statement, which are analogous to a function s FUNCTION statement and END FUNCTION statement. 2. A subroutine has no return type and no return variable. SUBROUTINE input_elements (element, REAL,DIMENSION(, INTENT(OUT) :: element INTEGER :: index PRINT *, "What are the ", number_of_elements, " elements of the array?" READ *, (element(index), index = first_element, END SUBROUTINE input_elements A subroutine is invoked using a CALL statement (e.g., in the main program): CALL input_elements(project1_score, number_of_students) Notice that a subroutine has to have side effects to be useful. The general term for functions and subroutines is procedure. That is, a procedure is either a function or a subroutine

10 Subroutine Call Example % cat userarray2.f90 PROGRAM user_array_test2 INTEGER,PARAMETER :: allocate_success = 0 REAL,DIMENSION(:),ALLOCATABLE :: element INTEGER :: number_of_elements INTEGER :: allocate_status, index INTEGER,EXTERNAL :: input_number_of_elements number_of_elements = input_number_of_elements() PRINT *, "The number of elements that you ", "plan to input is ", number_of_elements, "." ALLOCATE(element(, STAT=allocate_status) IF (allocate_status /= allocate_success) THEN PRINT *, "ERROR: couldn t allocate the ", "array named element" PRINT *, " of ", number_of_elements, " elements." END IF!! (allocate_status /= allocate_success) CALL input_elements(element, PRINT *, "The ", number_of_elements, " elements are:" PRINT *, (element(index), index = first_element, END PROGRAM user_array_test2 INCLUDE "inputnumelts.f90" INCLUDE "inputarray.f90" % cat inputnumelts.f90 INTEGER FUNCTION input_number_of_elements () INTEGER,PARAMETER :: minimum_number_of_elements = 1 PRINT *, "" PRINT *, " the array to have (at least ", minimum_number_of_elements, ")?" READ *, input_number_of_elements IF (input_number_of_elements < minimum_ THEN PRINT *, "Too few, idiot!" END IF!! (input_number_of_elements <... ) END FUNCTION input_number_of_elements % cat inputarray.f90 SUBROUTINE input_elements (element, REAL,DIMENSION(, INTENT(OUT) :: element INTEGER :: index PRINT *, "What are the ", number_of_elements, " elements of the array?" READ *, (element(index), index = first_element, END SUBROUTINE input_elements Subroutine Call Example Runs % f95 -o userarray2 userarray2.f90 % userarray2 0 Too few, idiot! % userarray The number of elements that you plan to input is ERROR: couldn t allocate the array named element of elements. % userarray2 3 The number of elements that you plan to input is 3. What are the 3 elements of the array? The 3 elements are:

11 Why Do We Like Code Reuse? 1. Bug avoidance: Since we don t have to retype the procedure from scratch every time we use it, we aren t constantly making new and exciting typos. 2. Implementation efficiency: We aren t wasting valuable programming time ($8 - $100s per programmer per hour) on writing commonly used procedures from scratch. 3. Verification: We can test a procedure under every conceivable case, so that we re confident that it works, and then we don t have to worry about whether the procedure has bugs when we use it in a new program. Why Do We Like User-Defined Procedures? 1. Code Reuse (see above) 2. Encapsulation: We can write a procedure that packages an important concept (e.g., the cube root). That way, we don t have to litter our program with cube root calculations. So, someone reading our program will be able to tell immediately that, for example, a particular statement has a cube root in it, rather than constantly having to figure out the meaning of x ** (1.0 / 3.0) 3. Modular Programming: If we make a bunch of encapsulations, then we can have our main program simply call a bunch of procedures. That way, it s easy for someone reading our code to tell what s going on in the main program, and then to look at individual procedures to see how they work. 21

1. User-Defined Functions & Subroutines Part 1 Outline

1. User-Defined Functions & Subroutines Part 1 Outline User-Defined Functions Subroutines Part 1 Outline 1. User-Defined Functions Subroutines Part 1 Outline 2. Intrinsic Functions Are Not Enough 3. User-Defined Functions 4. A User-Defined Function for Mean

More information

User Defined Functions 2 Outline

User Defined Functions 2 Outline User Defined Functions 2 Outline 1. User Defined Functions 2 Outline 2. Argument Order When Passing Arrays #1 3. Argument Order When Passing Arrays #1 4. Code Reuse Is GOOD GOOD GOOD #1 5. Code Reuse Is

More information

User Defined Functions 1 Outline

User Defined Functions 1 Outline User Defined Functions 1 Outline 1. User Defined Functions 1 Outline 2. Standard Library Not Enough #1 3. Standard Library Not Enough #2 4. Calling a Function Instead 5. Why User-Defined Functions? 6.

More information

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November CS 1313 010: Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November 7 2018 This fifth programming project will give you experience writing programs

More information

Search Lesson Outline

Search Lesson Outline 1. Searching Lesson Outline 2. How to Find a Value in an Array? 3. Linear Search 4. Linear Search Code 5. Linear Search Example #1 6. Linear Search Example #2 7. Linear Search Example #3 8. Linear Search

More information

Lab 7 Unit testing and debugging

Lab 7 Unit testing and debugging CMSC160 Intro to Algorithmic Design Blaheta Lab 7 Unit testing and debugging 13 March 2018 Below are the instructions for the drill. Pull out your hand traces, and in a few minutes we ll go over what you

More information

Review Functions Subroutines Flow Control Summary

Review Functions Subroutines Flow Control Summary OUTLINE 1 REVIEW 2 FUNCTIONS Why use functions How do they work 3 SUBROUTINES Why use subroutines? How do they work 4 FLOW CONTROL Logical Control Looping 5 SUMMARY OUTLINE 1 REVIEW 2 FUNCTIONS Why use

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

CS 103 Lab The Files are *In* the Computer

CS 103 Lab The Files are *In* the Computer CS 103 Lab The Files are *In* the Computer 1 Introduction In this lab you will modify a word scramble game so that instead of using a hardcoded word list, it selects a word from a file. You will learn

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

Subroutines and Functions

Subroutines and Functions Subroutines and Functions Procedures: Subroutines and Functions There are two types of procedures: SUBROUTINE: a parameterized named sequence of code which performs a specific task and can be invoked from

More information

Arrays. 1. Derived Data Types Outline

Arrays. 1. Derived Data Types Outline Derived Data Types Outline 1. Derived Data Types Outline 2. Arrays 3. A Company and Its Employees 4. Multiple Employees 5. A New Data Type 6. Breaking Down a Derived Type Definition 7. Declaring an Instance

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

Table of Laplace Transforms

Table of Laplace Transforms Table of Laplace Transforms 1 1 2 3 4, p > -1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Heaviside Function 27 28. Dirac Delta Function 29 30. 31 32. 1 33 34. 35 36. 37 Laplace Transforms

More information

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Statistics Case Study 2000 M. J. Clancy and M. C. Linn Statistics Case Study 2000 M. J. Clancy and M. C. Linn Problem Write and test functions to compute the following statistics for a nonempty list of numeric values: The mean, or average value, is computed

More information

Review More Arrays Modules Final Review

Review More Arrays Modules Final Review OUTLINE 1 REVIEW 2 MORE ARRAYS Using Arrays Why do we need dynamic arrays? Using Dynamic Arrays 3 MODULES Global Variables Interface Blocks Modular Programming 4 FINAL REVIEW THE STORY SO FAR... Create

More information

Introduction to Fortran Programming. -Internal subprograms (1)-

Introduction to Fortran Programming. -Internal subprograms (1)- Introduction to Fortran Programming -Internal subprograms (1)- Subprograms Subprograms are used to split the program into separate smaller units. Internal subprogram is not an independent part of a program.

More information

Numerical Methods in Scientific Computation

Numerical Methods in Scientific Computation Numerical Methods in Scientific Computation Programming and Software Introduction to error analysis 1 Packages vs. Programming Packages MATLAB Excel Mathematica Maple Packages do the work for you Most

More information

Testing and Debugging

Testing and Debugging 130 Chapter 5 Testing and Debugging You ve written it so it must work, right? By now you know that is not necessarily true. We all make mistakes. To be a successful programmer you need to be able to reliably

More information

6.096 Introduction to C++

6.096 Introduction to C++ MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.096 Lecture 3 Notes

More information

Array Lesson 2 Outline

Array Lesson 2 Outline 1. Outline 2. Reading Array Values Using for Loop #1 3. Reading Array Values Using for Loop #2 4. for Loop: Like Many Statements #1 5. for Loop: Like Many Statements #2 6. for Loop: Like Many Statements

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Programming Tips for Plugins

Programming Tips for Plugins Programming Tips for Plugins Chad Neufeld Centre for Computational Geostatistics Department of Civil & Environmental Engineering University of Alberta Working in a university based research environment

More information

Lecture 1: Overview

Lecture 1: Overview 15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant

More information

Subroutines, Functions and Modules

Subroutines, Functions and Modules Subroutines, Functions and Modules Subdividing the Problem Most problems are thousands of lines of code. Few people can grasp all of the details. Good design principle: Exhibit the overall structure in

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

(Refer Slide Time: 1:27)

(Refer Slide Time: 1:27) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

CSCE 120: Learning To Code

CSCE 120: Learning To Code CSCE 120: Learning To Code Module 9.0: Organizing Code I Introduction to Functions This module is designed to get you started working with functions which allow you to organize code into reusable units

More information

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1 Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to

More information

(Refer Slide Time 01:41 min)

(Refer Slide Time 01:41 min) Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 03 C Programming - II We shall continue our study of

More information

CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #11 Procedural Composition and Abstraction c 2005, 2004 Jason Zych 1 Lecture 11 : Procedural Composition and Abstraction Solving a problem...with

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Static Methods. Why use methods?

Static Methods. Why use methods? Static Methods A method is just a collection of code. They are also called functions or procedures. It provides a way to break a larger program up into smaller, reusable chunks. This also has the benefit

More information

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 COMPUTER SCIENCE 61AS 1. What is functional programming? Give an example of a function below: Functional Programming In functional programming, you do not

More information

Reliable programming

Reliable programming Reliable programming How to write programs that work Think about reliability during design and implementation Test systematically When things break, fix them correctly Make sure everything stays fixed

More information

First of all, it is a variable, just like other variables you studied

First of all, it is a variable, just like other variables you studied Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)

More information

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017 FORTRAN 90: Functions, Modules, and Subroutines Meteorology 227 Fall 2017 Purpose First step in modular program design Cannot always anticipate all of the steps that will be needed to solve a problem Easier

More information

Outline of Fortran 90 Topics

Outline of Fortran 90 Topics Outline of Fortran 90 Topics Overview of Computing Computer Organization Languages Problem Solving Data Fortran 90 Character Set Variables Basic Data Types Expressions Numeric Non-numeric Control Structures

More information

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) CSE 11 Winter 2017 Program Assignment #2 (100 points) START EARLY! Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) PROGRAM #2: DoubleArray11 READ THE ENTIRE ASSIGNMENT BEFORE STARTING In lecture,

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Old Questions Name: a. if b. open c. output d. write e. do f. exit

Old Questions Name: a. if b. open c. output d. write e. do f. exit Old Questions Name: Part I. Multiple choice. One point each. 1. Which of the following is not a Fortran keyword? a. if b. open c. output d. write e. do f. exit 2. How many times will the code inside the

More information

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want

More information

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)... Remembering numbers (and other stuff)... Let s talk about one of the most important things in any programming language. It s called a variable. Don t let the name scare you. What it does is really simple.

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

OrbBasic Lesson 1 Goto and Variables: Student Guide

OrbBasic Lesson 1 Goto and Variables: Student Guide OrbBasic Lesson 1 Goto and Variables: Student Guide Sphero MacroLab is a really cool app to give the Sphero commands, but it s limited in what it can do. You give it a list of commands and it starts at

More information

Chapter 7 Functions. Now consider a more advanced example:

Chapter 7 Functions. Now consider a more advanced example: Chapter 7 Functions 7.1 Chapter Overview Functions are logical groupings of code, a series of steps, that are given a name. Functions are especially useful when these series of steps will need to be done

More information

Understanding Recursion

Understanding Recursion Understanding Recursion Brian L. Stuart February 23, 2015 It has been suggested that the single most original contribution that the field of Computer Science has made to the tapestry of human intellect

More information

Introduction. A Brief Description of Our Journey

Introduction. A Brief Description of Our Journey Introduction If you still write RPG code as you did 20 years ago, or if you have ILE RPG on your resume but don t actually use or understand it, this book is for you. It will help you transition from the

More information

Why C? Because we can t in good conscience espouse Fortran.

Why C? Because we can t in good conscience espouse Fortran. C Tutorial Why C? Because we can t in good conscience espouse Fortran. C Hello World Code: Output: C For Loop Code: Output: C Functions Code: Output: Unlike Fortran, there is no distinction in C between

More information

Debugging Your Python Code: For Dummies

Debugging Your Python Code: For Dummies Debugging Your Python Code: For Dummies Tyler J. Metivier University of Connecticut Dept. of Physics May 4, 2018 1 What s the problem? It doesn t matter if you ve written 1 script or programmed a space

More information

OrbBasic 1: Student Guide

OrbBasic 1: Student Guide OrbBasic 1: Student Guide Sphero MacroLab is a really cool app to give the Sphero commands, but it s limited in what it can do. You give it a list of commands and it starts at the top and goes to the bottom,

More information

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

CS Spring 2018 Homework #11 Quiz to be held in class 9:30-9:45am Mon Apr

CS Spring 2018 Homework #11 Quiz to be held in class 9:30-9:45am Mon Apr CS 1313 010 Spring 2018 Homework #11 Quiz to be held in class 9:30-9:45am Mon Apr 16 2018 1. Suppose that you are using the C standard math library function sqrt in a program that you are writing. GIVE

More information

AMath 483/583 Lecture 8

AMath 483/583 Lecture 8 AMath 483/583 Lecture 8 This lecture: Fortran subroutines and functions Arrays Dynamic memory Reading: class notes: Fortran Arrays class notes: Fortran Subroutines and Functions class notes: gfortran flags

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And

More information

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x ); Chapter 5 Methods Sections Pages Review Questions Programming Exercises 5.1 5.11 142 166 1 18 2 22 (evens), 30 Method Example 1. This is of a main() method using a another method, f. public class FirstMethod

More information

CSC 220: Computer Organization Unit 10 Arithmetic-logic units

CSC 220: Computer Organization Unit 10 Arithmetic-logic units College of Computer and Information Sciences Department of Computer Science CSC 220: Computer Organization Unit 10 Arithmetic-logic units 1 Remember: 2 Arithmetic-logic units An arithmetic-logic unit,

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer Introduction to Computers II Lecture 4 Dr Ali Ziya Alkar Dr Mehmet Demirer 1 Contents: Utilizing the existing information Top-down design Start with the broadest statement of the problem Works down to

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #29 Arrays in C (Refer Slide Time: 00:08) This session will learn about arrays in C. Now, what is the word array

More information

Cypress Adopts Questa Formal Apps to Create Pristine IP

Cypress Adopts Questa Formal Apps to Create Pristine IP Cypress Adopts Questa Formal Apps to Create Pristine IP DAVID CRUTCHFIELD, SENIOR PRINCIPLE CAD ENGINEER, CYPRESS SEMICONDUCTOR Because it is time consuming and difficult to exhaustively verify our IP

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative

More information

Lab 6 Vectors and functions

Lab 6 Vectors and functions CMSC160 Intro to Algorithmic Design Blaheta Lab 6 Vectors and functions 11 October 2016 The drill for this lab is another part of the Chapter 4 drill. Come to lab on Tuesday either with it completed or

More information

Excel programmers develop two basic types of spreadsheets: spreadsheets

Excel programmers develop two basic types of spreadsheets: spreadsheets Bonus Chapter 1 Creating Excel Applications for Others In This Chapter Developing spreadsheets for yourself and for other people Knowing what makes a good spreadsheet application Using guidelines for developing

More information

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Relations Let s talk about relations! Grade 6 Math Circles November 6 & 7 2018 Relations, Functions, and

More information

Outline. When we last saw our heros. Language Issues. Announcements: Selecting a Language FORTRAN C MATLAB Java

Outline. When we last saw our heros. Language Issues. Announcements: Selecting a Language FORTRAN C MATLAB Java Language Issues Misunderstimated? Sublimable? Hopefuller? "I know how hard it is for you to put food on your family. "I know the human being and fish can coexist peacefully." Outline Announcements: Selecting

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES Introduction In this preliminary chapter, we introduce a couple of topics we ll be using throughout the book. First, we discuss how to use classes and object-oriented programming (OOP) to aid in the development

More information

function at the given point. Thus, for our previous example we would find that lim f(x) = 0

function at the given point. Thus, for our previous example we would find that lim f(x) = 0 Limits In order to introduce the notion of the it, we will consider the following situation. Suppose you are given a function, defined on some interval, except at a single point in the interval. What,

More information

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class? Administration Objects and Arrays CS 99 Summer 2000 Michael Clarkson Lecture 6 Read clarified grading policies Lab 6 due tomorrow Submit.java files in a folder named Lab6 Lab 7 Posted today Upson Lab closed

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

8 Understanding Subtyping

8 Understanding Subtyping Object-Oriented Design Lecture 8 CS 3500 Fall 2010 (Pucella) Friday/Tuesday, Oct 8/12, 2010 8 Understanding Subtyping Subtpying is a great way to enable client-side reuse, requiring a client to write a

More information

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 3 Matrix Math Introduction Reading In this lab you will write a

More information

Testing! Prof. Leon Osterweil! CS 520/620! Spring 2013!

Testing! Prof. Leon Osterweil! CS 520/620! Spring 2013! Testing Prof. Leon Osterweil CS 520/620 Spring 2013 Relations and Analysis A software product consists of A collection of (types of) artifacts Related to each other by myriad Relations The relations are

More information

Pointers, Arrays and Parameters

Pointers, Arrays and Parameters Pointers, Arrays and Parameters This exercise is different from our usual exercises. You don t have so much a problem to solve by creating a program but rather some things to understand about the programming

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

QUIZ. What are 3 differences between C and C++ const variables?

QUIZ. What are 3 differences between C and C++ const variables? QUIZ What are 3 differences between C and C++ const variables? Solution QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Solution The C/C++ preprocessor substitutes mechanically,

More information

1 GB FLIP INTRODUCTION Introduction. This is GB FLIP, the module used by GraphBase programs to generate random numbers.

1 GB FLIP INTRODUCTION Introduction. This is GB FLIP, the module used by GraphBase programs to generate random numbers. 1 GB FLIP INTRODUCTION 1 1. Introduction. This is GB FLIP, the module used by GraphBase programs to generate random numbers. To use the routines in this file, first call the function gb init rand (seed

More information

Laboratory 5: Implementing Loops and Loop Control Strategies

Laboratory 5: Implementing Loops and Loop Control Strategies Laboratory 5: Implementing Loops and Loop Control Strategies Overview: Objectives: C++ has three control structures that are designed exclusively for iteration: the while, for and do statements. In today's

More information

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3 Programming in C main Level 2 Level 2 Level 2 Level 3 Level 3 1 Programmer-Defined Functions Modularize with building blocks of programs Divide and Conquer Construct a program from smaller pieces or components

More information

Topic Notes: Java and Objectdraw Basics

Topic Notes: Java and Objectdraw Basics Computer Science 120 Introduction to Programming Siena College Spring 2011 Topic Notes: Java and Objectdraw Basics Event-Driven Programming in Java A program expresses an algorithm in a form understandable

More information

Intrinsic Functions Outline

Intrinsic Functions Outline Intrinsic Functions Outline 1. Intrinsic Functions Outline 2. Functions in Mathematics 3. Functions in Fortran 90 4. A Quick Look at ABS 5. Intrinsic Functions in Fortran 90 6. Math: Domain Range 7. Programming:

More information

Chapter 1 Welcome Aboard

Chapter 1 Welcome Aboard Introduction to Computing Systems: From Bits and Gates to C and Beyond 2 nd Edition Yale N. Patt Sanjay J. Patel Slides prepared by Gregory T. Byrd, North Carolina State University Modified by Chao Gong,

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise

More information

Congruence Arithmetic

Congruence Arithmetic Module 4 Congruence Arithmetic Popper 4 Introduction to what is like Modulus choices Partitions by modulus Mod 5 Mod 7 Mod 30 Modular Arithmetic Addition Subtraction Multiplication INTEGERS! Mod 12 Cayley

More information

6.001 Notes: Section 1.1

6.001 Notes: Section 1.1 6.001 Notes: Section 1.1 Slide 1.1.1 This first thing we need to do is discuss the focus of 6.001. What is this course all about? This seems quite obvious -- this is a course about computer science. But

More information

Basic Reliable Transport Protocols

Basic Reliable Transport Protocols Basic Reliable Transport Protocols Do not be alarmed by the length of this guide. There are a lot of pictures. You ve seen in lecture that most of the networks we re dealing with are best-effort : they

More information

Object Oriented Methods : Deeper Look Lecture Three

Object Oriented Methods : Deeper Look Lecture Three University of Babylon Collage of Computer Assistant Lecturer : Wadhah R. Baiee Experience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces,

More information

CS221: Algorithms and Data Structures. Asymptotic Analysis. Alan J. Hu (Borrowing slides from Steve Wolfman)

CS221: Algorithms and Data Structures. Asymptotic Analysis. Alan J. Hu (Borrowing slides from Steve Wolfman) CS221: Algorithms and Data Structures Asymptotic Analysis Alan J. Hu (Borrowing slides from Steve Wolfman) 1 Learning Goals By the end of this unit, you will be able to Define which program operations

More information

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 4 C Pointers and Arrays 1/25/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Pointers (1) Common C Error There is a difference

More information

EE355 Lab 5 - The Files Are *In* the Computer

EE355 Lab 5 - The Files Are *In* the Computer 1 Introduction In this lab you will modify a working word scramble game that selects a word from a predefined word bank to support a user-defined word bank that is read in from a file. This is a peer evaluated

More information

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5 C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................

More information

Using loops and debugging code

Using loops and debugging code Using loops and debugging code Chapter 7 Looping your code pp. 103-118 Exercises 7A & 7B Chapter 8 Fixing Bugs pp. 119-132 Exercise 8 Chapter 7 Looping your code Coding a For loop Coding a Do loop Chapter

More information

Sum or difference of Cubes

Sum or difference of Cubes Sum or difference of Cubes Factoring Cubes 5 practice problems EVERY time you look at a factoring problem, start with the question: Is there a GCF? What s a GCF? It s a number or a variable that all the

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names for containers of values don t need to know which register or memory location Provides abstraction of underlying

More information