Functions. 6.1 Modular Programming. 6.2 Defining and Calling Functions. Gaddis: 6.1-5,7-10,13,15-16 and 7.7
|
|
- Francis Howard
- 6 years ago
- Views:
Transcription
1 Functions Unit 6 Gaddis: 6.1-5,7-10,13,15-16 and 7.7 CS 1428 Spring 2018 Ji Seaman 6.1 Moduar Programming Moduar programming: breaking a program up into smaer, manageabe components (modues) Function: a coection of statements that perform a task, grouped into a singe named unit. Why is moduar programming important? Improves maintainabiity/readabiity of programs by giving structure and organization to the code Simpifies the process of writing programs: programmer can write one sma function at a time Defining and Caing Functions Function definition: statements that make up a function, aong with its name, parameters and return type. return-type function-name (parameters) statements Function ca: statement (or expression) that causes a function to execute function-name (arguments) 3 4
2 Function Definition A Function definition incudes: return type: data type of the vaue that the function returns to the part of the program that caed it. function-name: name of the function. Function names foow same rues as variabes. parameters: optiona ist of variabe definitions. These wi be assigned vaues each time the function is caed. body: statements that perform the function s task, encosed in. 5 Function header (in the box) Function Definition return-type function-name (parameters) statements 6 Function Return Type Caing a Function If a function computes and returns a vaue, the type of the vaue it returns must be indicated as the return type: int getrate() return 8; If a function does not return a vaue, its return type is void: void printheading() cout << "Monthy Saes\n"; 7 To execute the statements in a function, you must ca it from within another function (ike main). To ca a function, use the function name foowed by a ist of expressions (arguments) in parens: printheading(); Whenever caed, the program executes the body of the caed function (it runs the statements). After the function terminates, execution resumes in the caing function after the function ca. 8
3 Exampe: Functions in a program #incude <iostream> void dispaymessage() cout << Heo from the function dispaymessage.\n ; Functions in a program Heo from main. Heo from the function dispaymessage. Back in function main again. Fow of Contro (order of statements): int main() cout << Heo from Main.\n ; dispaymessage(); cout << Back in function Main again.\n ; 9 Contro aways starts at main 10 Caing Functions: rues 6.3 Function Prototypes A program is a coection of functions, one of which must be caed main. Function definitions can contain cas to other functions. A function must be defined before it can be caed In the program text, the function definition must occur before a cas to the function Uness you use a prototype 11 Compier must know the foowing about a function before it can process a function ca: name, return type and data type (and order) of each parameter Not necessary to have the body of the function before the ca. Sufficient to put just the function header before a functions containing cas to that function The compete function definition must occur ater in the program. The header aone is caed a function prototype 12
4 #incude <iostream> // function prototypes void first(); void second(); Prototypes in a program cout << "I am starting in function main.\n"; first(); // function ca second(); // function ca cout << "Back in function main again.\n"; Prototype Stye Notes Pace prototypes near the top of the program (before any other function definitions)--good stye. Using prototypes, you can pace function definitions in any order in the source fie // function definitions void first() cout << "I am now inside the function first.\n"; void second() cout << "I am now inside the function second.\n"; 13 Common stye: a function prototypes at beginning, foowed by definition of main, foowed by other function definitions Sending Data into a Function You can pass (or send) vaues to a function in the function ca statement. This aows the function to work over different vaues each time it is caed. Arguments: Expressions (or vaues) passed to a function in the function ca. Parameters: Variabes defined in the function definition header that are assigned the vaues passed as arguments. A Function with a Parameter void dispayvaue(int num) cout << "The vaue is " << num << end; num is the parameter. Cas to this function must provide an argument (expression) that has an integer vaue: dispayvaue(5); 5 is the argument
5 Function with parameter in program #incude <iostream> // Function Prototype void dispayvaue(int); cout << "I am passing 5 to dispayvaue.\n"; dispayvaue(5); cout << "Back in function main again.\n ; dispayvaue(8); //ca again with diff. argument // Function definition void dispayvaue(int num) cout << "The vaue is " << num << end; I am passing 5 to dispayvaue. The vaue is 5 Back in function main again. The vaue is 8 17 Parameter Passing Semantics Given this function ca, with the argument of 5: dispayvaue(5); Before the function body executes, the parameter (num) is initiaized to the argument (5), ike this: int num = 5; //this stmt is executed impicity Then the body of the function is executed, using num as a reguar variabe: cout << "The vaue is " << num << end; 18 Parameters in Prototypes and Function Definitions The prototype must incude the data type of each parameter inside its parentheses: void evenorodd(int); //prototype The definition must incude a definition for each parameter in its parens void evenorodd(int num) //header if (num%2==0) cout << even ; ese cout << odd ; The ca must incude an argument (expression) for each parameter, inside its parentheses evenorodd(x+10); //ca 19 Passing Mutipe Arguments When caing a function that has mutipe parameters: the foowing must a match: the number and order of data types in the prototype the number and order of parameters in the function definition the number and order of arguments in the function ca the first argument wi be used to initiaize the first parameter, the second argument to initiaize the second parameter, etc. they are assigned in order. void power(int, int); //prototype 20
6 Exampe: function cas function Exampe: ca function more than once void deeper() cout << I am now in function deeper.\n ; void deep() cout << Heo from the function deep.\n ; deeper(); cout << Back in function deep.\n ; cout << Heo from Main.\n ; deep(); cout << Back in function Main again.\n ; Heo from Main. Heo from the function deep. I am now in function deeper. Back in function deep. Back in function Main again. 21 #incude <iostream> #incude <cmath> void puses(int count) for (int i = 0; i < count; i++) cout << "+"; cout << end; int x = 2; puses(4); puses(x); puses(x+5); puses(pow(x,3.0)); Exampe: mutipe parameters 6.7 The return statement #incude <iostream> #incude <cmath> void puses(char ch, int count) for (int i=0; i < count; i++) cout << ch; cout << end; int x = 2; char cc = '!'; puses('#',4); puses('*',x); puses(cc,x+5); puses('x',pow(x,3.0)); #### **!!!!!!! xxxxxxxx return; Used to stop the execution of a void function Can be paced anywhere in the function body the function immediatey transfers contro back to the statement that caed it. Statements that foow the return statement wi not be executed In a void function with no return statement, the compier adds a return statement before the ast 23 24
7 The return statement: exampe void somefunc (int x) if (x < 0) cout << x must not be negative. << end; ese // Continue with ots of statements, indented //... // so many it s hard to keep track of matching void somefunc (int x) This is equivaent, easier to read if (x < 0) cout << x must not be negative. << end; return; // Continue with ots of statements, ess indentation, // no brackets to try to match Returning a vaue from a function You can use the return statement in a non-void function to send a vaue back to the function ca: return expr; The vaue of the expr wi be sent back. The data type of expr must be paced in the function header: Return type: int doubeit(int x) return x*2; Vaue being returned 26 Caing a function that returns a vaue If the function returns void, the function ca is a statement: puses(4); If the function returns a vaue, the function ca is an expression: int y = doubeit(4); The vaue of the function ca (underined) is the vaue of the expr returned from the function, and you shoud do something with it. 27 Returning the sum of two ints #incude <iostream> int sum(int,int); int vaue1; int vaue2; int tota; cout << "Enter 2 numbers: " << end; cin >> vaue1 >> vaue2; tota = sum(vaue1, vaue2); cout << "The sum is " << tota << end; int sum(int x, int y) return x + y; Enter 2 numbers: The sum is 60 28
8 Data transfer The function ca from main: sum(vaue1, vaue2) passes the vaues stored in vaue1 and vaue2 (20 and 40) to the function, assigning them to x and y. The resut, x+y (60), is returned to the ca and stored in tota. x x y y 29 Function ca expression When a function ca cas a function that returns a vaue, it is an expression. The function ca can occur in any context where an expression is aowed: assign to variabe (or array eement) output via cout use in a more compicated expression pass as an argument to another function tota = sum(x,y); cout << sum(x,y); cout << sum(x,y)*.1; z = pow(sum(x,y),2); The vaue of the function ca is determined by the vaue of the expression returned from the 30 function. 6.9 Returning a booean vaue boo isvaid(int number) boo status; if (number >=1 && number <= 100) status = true; ese status = fase; return status; the above function is equivaent to this one: boo isvaid (int number) return (number >=1 && number <= 100); 31 Returning a booean vaue You can ca the function in an if or whie: boo isvaid(int); int va; cout << Enter a vaue between 1 and 100: cin >> va; whie (!isvaid(va)) cout << That vaue was not in range.\n ; cout << Enter a vaue between 1 and 100: cin >> va; //... 32
9 6.5 Passing Data by Vaue (review) Pass by vaue: when an argument is passed to a function, its vaue is copied into the parameter. Parameter passing is impemented using variabe initiaization (behind the scenes): int param = argument; Changes to the parameter in the function definition cannot affect the vaue of the argument in the ca 33 #incude <iostream> void changeme(int); Exampe: Pass by Vaue int number = 12; cout << "number is " << number << end; changeme(number); cout << "Back in main, number is " << number << end; int myvaue = number; void changeme(int myvaue) myvaue = 200; cout << "myvaue is " << myvaue << end; changeme faied! number is 12 myvaue is 200 Back in main, number is Pass by Vaue notes When the argument is a variabe (as in f(x)): The parameter is initiaized to a copy of the argument s vaue. Even if the body of the function changes the parameter, the argument in the function ca is unchanged. The parameter and the argument are stored in separate variabes, separate ocations in memory Passing Data by Reference Pass by reference: when an argument is passed to a function, the function has direct access to the origina argument. Pass by reference in C++ is impemented using a reference parameter, which has an ampersand (&) in front of it: void changeme (int &myvaue); A reference parameter acts as an aias to its argument. Changes to the parameter in the function DO affect the vaue of the argument 36
10 Exampe: Pass by Reference #incude <iostream> void changeme(int &); number is 12 myvaue is 200 Back in main, number is 200 int number = 12; cout << "number is " << number << end; changeme(number); cout << "Back in main, number is " << number << end; myvaue is an aias for number, ony one shared variabe void changeme(int &myvaue) this statement changes number myvaue = 200; cout << "myvaue is " << myvaue << end; 37 Using Pass by Reference for input doube square(doube number) return number * number; void getradius(doube &rad) cout << "Enter the radius of the circe: "; cin >> rad; const doube PI = ; doube radius; doube area; cout << fixed << setprecision(2); getradius(radius); area = PI * square(radius); cout << "The area is " << area << end; During the function execution, rad is an aias to radius in the main program. 38 Pass by Reference notes Changes made to a reference parameter are actuay made to its argument The & must be in the function header AND the function prototype. The argument passed to a reference parameter must be a variabe it cannot be a constant or contain an operator (ike +) Use when appropriate don t use when: the argument shoud not be changed by function (!) the function returns ony 1 vaue: use return stmt! Loca and Goba Variabes Variabes defined inside a function are oca to that function. They are hidden from the statements in other functions, which cannot access them. Because the variabes defined in a function are hidden, other functions may have separate, distinct variabes with the same name. This is not bad stye. These are easy to keep straight Parameters are aso oca to the function in which they are defined. 40
11 Loca variabes are hidden from other functions #incude <iostream> void anotherfunction(); In main, num is 1 In anotherfunction, num is 20 Back in main, num is 1 This num variabe is visibe int num = 1; ony in main cout << "In main, num is " << num << end; anotherfunction(); cout << "Back in main, num is " << num << end; void anotherfunction() This num variabe is visibe ony in anotherfunction int num = 20; cout << "In anotherfunction, num is " << num << end; 41 Loca Variabe Lifetime A function s oca variabes and parameters exist ony whie the function is executing. When the function begins, its parameters and oca variabes (as their definitions are encountered) are created in memory, and when the function ends, the parameters and oca variabes are destroyed. This means that any vaue stored in a oca variabe is ost between cas to the function in which the variabe is decared. 42 Goba Variabes A goba variabe is any variabe defined outside a the functions in a program. The scope of a goba variabe is the portion of the program starting from the variabe definition to the end of the fie This means that a goba variabe can be accessed by a functions that are defined after the goba variabe is defined A oca variabe may have the same name as a goba variabe. The goba variabe is hidden in that variabe s bock. 43 Goba Variabes: exampe #incude <iostream> void anotherfunction(); int num = 2; cout << "In main, num is " << num << end; anotherfunction(); cout << "Back in main, num is " << num << end; In main, num is 2 In anotherfunction, num is 2 But now it is changed to 50 Back in main, num is 50 void anotherfunction() cout << "In anotherfunction, num is " << num << end; num = 50; cout << "But now it is changed to " << num << end; 44
12 Goba Variabes/Constants Do not use goba variabes!!! Because: They make programs difficut to debug. If the wrong vaue is stored in a goba var, you must scan the entire program to see where the variabe is changed Functions that access gobas are not sefcontained cannot easiy reuse the function in another program. cannot understand the function without understanding how the goba is used everywhere It is ok (and good) to use goba constants because their vaues do not change. 45 const doube PI = ; doube getarea(doube number) return PI * number * number; doube getperimeter(doube number) return PI * 2 * number; doube radius; cout << fixed << setprecision(2); cout << "Enter the radius of the circe: "; cin >> radius; Goba Constants: exampe Enter the radius of the circe: 2.2 The area is The perimeter is cout << "The area is " << getarea(radius) << end; cout << "The perimeter is " << getperimeter(radius) << end; 46 Functions and Array Eements Functions and Array Eements An array eement can be passed to any parameter of the same (or compatibe) type: doube square (doube); doube numbers[5] = 2.2, 3.3, 5.11, 7.0, 3.2; for (int i=0; i<5; i++) cout << square(numbers[i]) << " "; cout << end; doube square (doube x) return x * x; An array eement can be passed by reference. What is output by this program? void changeme(int &myvaue) myvaue = 200; int numbers[5] = 2, 3, 5, 7, 3; for (int i=0; i<5; i++) changeme(numbers[i]); for (int i=0; i<5; i++) cout << numbers[i] << " "; cout << end; 48
13 7.7 Arrays as Function Arguments An entire array can(!) be passed to a function that has an array parameter void showarray(int[], int); int numbers[5] = 2, 3, 5, 7, 3; showarray(numbers,5); void showarray(int vaues[], int size) for (int i=0; i<size; i++) cout << vaues[i] << " "; cout << end; Passing arrays to functions In the function definition, the parameter type is a variabe name with an empty set of brackets: [ ] Do NOT give a size for the parameter void showarray(int vaues[], int size) In the prototype, empty brackets go after the eement datatype. void showarray(int[], int); In the function ca, use the variabe name for the array (no brackets!). showarray(numbers, 5); 50 Passing arrays to functions An array is aways passed by reference. The parameter name is an aias to the array being passed in, even though it has no &. Changes made to the array (eements) inside the function DO affect the array in the function ca. 51 Passing arrays to functions Changing an array inside a function: void incrarray(int[], int); void showarray(int[], int); int numbers[5] = 2, 3, 5, 7, 3; incrarray(numbers,5); showarray(numbers,5); void incrarray(int vaues[], int size) for (int i=0; i<size; i++) (vaues[i])++; //vaues[i]=vaues[i]+1; 52
14 Passing arrays to functions Usuay functions that have an array parameter aso have an int parameter for the count of the number of eements in the array. so the function knows how many eements to process. The count parameter is just a reguar int parameter and must be incuded in the parameter ist and a corresponding argument vaue must appear in the function ca. 53
Ch 6. Functions. Example: function calls function
Ch 6. Functions Part 2 CS 1428 Fall 2011 Jill Seaman Lecture 21 1 Example: function calls function void deeper() { cout
More informationArrays. Array Data Type. Array - Memory Layout. Array Terminology. Gaddis: 7.1-3,5
Arrays Unit 5 Gaddis: 7.1-3,5 CS 1428 Spring 2018 Ji Seaman Array Data Type Array: a variabe that contains mutipe vaues of the same type. Vaues are stored consecutivey in memory. An array variabe decaration
More informationArrays. Array Data Type. Array - Memory Layout. Array Terminology. Gaddis: 7.1-4,6
Arrays Unit 5 Gaddis: 7.1-4,6 CS 1428 Fa 2017 Ji Seaman Array Data Type Array: a variabe that contains mutipe vaues of the same type. Vaues are stored consecutivey in memory. An array variabe definition
More informationStraight-line code (or IPO: Input-Process-Output) If/else & switch. Relational Expressions. Decisions. Sections 4.1-6, , 4.
If/ese & switch Unit 3 Sections 4.1-6, 4.8-12, 4.14-15 CS 1428 Spring 2018 Ji Seaman Straight-ine code (or IPO: Input-Process-Output) So far a of our programs have foowed this basic format: Input some
More informationIntro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?
Intro to Programming & C++ Unit 1 Sections 1.1-3 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2018 Ji Seaman 1.1 Why Program? Computer programmabe machine designed to foow instructions Program a set of
More informationVariable Definitions and Scope
Variable Definitions and Scope The scope of a variable is the part of the program where the variable may be used. For a variable defined inside a function, its scope is the function, from the point of
More informationIntro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components Illustrated
Intro to Programming & C++ Unit 1 Sections 1.1-3 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Fa 2017 Ji Seaman 1.1 Why Program? Computer programmabe machine designed to foow instructions Program instructions
More informationl A program is a set of instructions that the l It must be translated l Variable: portion of memory that stores a value char
Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fa 2018 Ji Seaman Programming A program is a set of instructions that the computer foows to perform a task It must be transated from
More information3.1 The cin Object. Expressions & I/O. Console Input. Example program using cin. Unit 2. Sections 2.14, , 5.1, CS 1428 Spring 2018
Expressions & I/O Unit 2 Sections 2.14, 3.1-10, 5.1, 5.11 CS 1428 Spring 2018 Ji Seaman 1 3.1 The cin Object cin: short for consoe input a stream object: represents the contents of the screen that are
More informationSearching, Sorting & Analysis
Searching, Sorting & Anaysis Unit 2 Chapter 8 CS 2308 Fa 2018 Ji Seaman 1 Definitions of Search and Sort Search: find a given item in an array, return the index of the item, or -1 if not found. Sort: rearrange
More informationWeek 4. Pointers and Addresses. Dereferencing and initializing. Pointers as Function Parameters. Pointers & Structs. Gaddis: Chapters 9, 11
Week 4 Pointers & Structs Gaddis: Chapters 9, 11 CS 5301 Spring 2017 Ji Seaman 1 Pointers and Addresses The address operator (&) returns the address of a variabe. int x; cout
More informationl A set is a collection of objects of the same l {6,9,11,-5} and {11,9,6,-5} are equivalent. l There is no first element, and no successor of 9.
Sets & Hash Tabes Week 13 Weiss: chapter 20 CS 5301 Spring 2018 What are sets? A set is a coection of objects of the same type that has the foowing two properties: - there are no dupicates in the coection
More information6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions.
6 Functions TOPICS 6.1 Focus on Software Engineering: Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5 Passing Data by Value 6.6 Focus
More informationStructures. Data Types Structures. Data Types (C/C++) Gaddis: A Data Type consists of: Unit 7. example: Integer. CS 1428 Spring 2018
Structures Data Types A Data Type consists of: Unit 7 Gaddis: 11.2-8 set of vaues set of operations over those vaues CS 1428 Spring 2018 Ji Seaman exampe: Integer whoe numbers, -32768 to 32767 +, -, *,
More informationl Tree: set of nodes and directed edges l Parent: source node of directed edge l Child: terminal node of directed edge
Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fa 2016 Ji Seaman 1 Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Spring 2018 Jill Seaman 1 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements...
More informationLECTURE 06 FUNCTIONS
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 06 FUNCTIONS IMRAN
More informationChapter 6: Functions
Chapter 6: Functions 6.1 Modular Programming Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection of statements to perform
More informationFunctions, Arrays & Structs
Functions, Arrays & Structs Unit 1 Chapters 6-7, 11 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where a parameter is: datatype identifier
More informationSearching & Sorting. Definitions of Search and Sort. Other forms of Linear Search. Linear Search. Week 11. Gaddis: 8, 19.6,19.8. CS 5301 Spring 2017
Searching & Sorting Week 11 Gaddis: 8, 19.6,19.8 CS 5301 Spring 2017 Ji Seaman 1 Definitions of Search and Sort Search: find a given item in a ist, return the position of the item, or -1 if not found.
More informationl A set is a collection of objects of the same l {6,9,11,-5} and {11,9,6,-5} are equivalent. l There is no first element, and no successor of 9.
Sets & Hash Tabes Week 13 Weiss: chapter 20 CS 5301 Fa 2017 What are sets? A set is a coection of objects of the same type that has the foowing two properties: - there are no dupicates in the coection
More informationIntroduction to the Stack. Stacks and Queues. Stack Operations. Stack illustrated. elements of the same type. Week 9. Gaddis: Chapter 18
Stacks and Queues Week 9 Gaddis: Chapter 18 CS 5301 Spring 2017 Ji Seaman Introduction to the Stack Stack: a data structure that hods a coection of eements of the same type. - The eements are accessed
More informationProfessor: Alvin Chao
Professor: Avin Chao CS149 For Each and Reference Arrays Looping Over the Contents of an Array We often use a for oop to access each eement in an array: for (int i = 0; i < names.ength; i++) { System.out.printn("Heo
More informationSearching & Sorting. Definitions of Search and Sort. Other forms of Linear Search. Linear Search. Week 11. Gaddis: 8, 19.6,19.8.
Searching & Sorting Week 11 Gaddis: 8, 19.6,19.8 CS 5301 Fa 2017 Ji Seaman 1 Definitions of Search and Sort Search: find a given item in a ist, return the position of the item, or -1 if not found. Sort:
More informationRegister Allocation. Consider the following assignment statement: x = (a*b)+((c*d)+(e*f)); In posfix notation: ab*cd*ef*++x
Register Aocation Consider the foowing assignment statement: x = (a*b)+((c*d)+(e*f)); In posfix notation: ab*cd*ef*++x Assume that two registers are avaiabe. Starting from the eft a compier woud generate
More information6.1. Chapter 6: What Is A Function? Why Functions? Introduction to Functions
Chapter 6: 6.1 Functions Introduction to Functions What Is A Function? Why Functions? We ve been using functions ( e.g. main() ). C++ program consists of one or more functions Function: a collection of
More informationProfessor: Alvin Chao
Professor: Avin Chao Anatomy of a Java Program: Comments Javadoc comments: /** * Appication that converts inches to centimeters. * * @author Chris Mayfied * @version 01/21/2014 */ Everything between /**
More information! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body
Week 3 Pointers, References, Arrays & Structures Gaddis: Chapters 6, 7, 9, 11 CS 5301 Fall 2013 Jill Seaman 1 Arguments passed by value! Pass by value: when an argument is passed to a function, its value
More informationBottom-Up Parsing LR(1)
Bottom-Up Parsing LR(1) Previousy we have studied top-down or LL(1) parsing. The idea here was to start with the start symbo and keep expanding it unti the whoe input was read and matched. In bottom-up
More informationFunctions, Arrays & Structs
Functions, Arrays & Structs Unit 1 Chapters 6-7, 11 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where a parameter is: datatype identifier
More informationunderstood as processors that match AST patterns of the source language and translate them into patterns in the target language.
A Basic Compier At a fundamenta eve compiers can be understood as processors that match AST patterns of the source anguage and transate them into patterns in the target anguage. Here we wi ook at a basic
More informationNearest Neighbor Learning
Nearest Neighbor Learning Cassify based on oca simiarity Ranges from simpe nearest neighbor to case-based and anaogica reasoning Use oca information near the current query instance to decide the cassification
More informationSpecial Edition Using Microsoft Excel Selecting and Naming Cells and Ranges
Specia Edition Using Microsoft Exce 2000 - Lesson 3 - Seecting and Naming Ces and.. Page 1 of 8 [Figures are not incuded in this sampe chapter] Specia Edition Using Microsoft Exce 2000-3 - Seecting and
More informationThis is a CLOSED-BOOK-CLOSED-NOTES exam consisting of five (5) questions. Write your answer in the answer booklet provided. 1. OO concepts (5 points)
COMP2012H Object Oriented Programming and Data Structures Spring Semester 2013 Midterm Exam Soution March 26, 2013, 10:30-11:50am in Room 3598 Instructor: Chi Keung Tang This is a CLOSED-OOK-CLOSED-NOTES
More informationRDF Objects 1. Alex Barnell Information Infrastructure Laboratory HP Laboratories Bristol HPL November 27 th, 2002*
RDF Objects 1 Aex Barne Information Infrastructure Laboratory HP Laboratories Bristo HPL-2002-315 November 27 th, 2002* E-mai: Andy_Seaborne@hp.hp.com RDF, semantic web, ontoogy, object-oriented datastructures
More informationPL/SQL, Embedded SQL. Lecture #14 Autumn, Fall, 2001, LRX
PL/SQL, Embedded SQL Lecture #14 Autumn, 2001 Fa, 2001, LRX #14 PL/SQL,Embedded SQL HUST,Wuhan,China 402 PL/SQL Found ony in the Orace SQL processor (sqpus). A compromise between competey procedura programming
More informationLecture outline Graphics and Interaction Scan Converting Polygons and Lines. Inside or outside a polygon? Scan conversion.
Lecture outine 433-324 Graphics and Interaction Scan Converting Poygons and Lines Department of Computer Science and Software Engineering The Introduction Scan conversion Scan-ine agorithm Edge coherence
More informationTutorial 3 Concepts for A1
CPSC 231 Introduction to Computer Science for Computer Science Majors I Tutoria 3 Concepts for A1 DANNY FISHER dgfisher@ucagary.ca September 23, 2014 Agenda script command more detais Submitting using
More informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More informationCSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Synchronization: Semaphore
CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Synchronization: Synchronization Needs Two synchronization needs Mutua excusion Whenever mutipe threads access a shared data, you need to worry
More informationOuterjoins, Constraints, Triggers
Outerjoins, Constraints, Triggers Lecture #13 Autumn, 2001 Fa, 2001, LRX #13 Outerjoins, Constraints, Triggers HUST,Wuhan,China 358 Outerjoin R S = R S with danging tupes padded with nus and incuded in
More informationChapter 5: Transactions in Federated Databases
Federated Databases Chapter 5: in Federated Databases Saes R&D Human Resources Kemens Böhm Distributed Data Management: in Federated Databases 1 Kemens Böhm Distributed Data Management: in Federated Databases
More informationSolutions to the Final Exam
CS/Math 24: Intro to Discrete Math 5//2 Instructor: Dieter van Mekebeek Soutions to the Fina Exam Probem Let D be the set of a peope. From the definition of R we see that (x, y) R if and ony if x is a
More informationindex.pdf March 17,
index.pdf March 17, 2013 1 ITI 1121. Introduction to omputing II Marce Turcotte Schoo of Eectrica Engineering and omputer Science Linked List (Part 2) Tai pointer ouby inked ist ummy node Version of March
More informationChapter 5 Combinational ATPG
Chapter 5 Combinationa ATPG 2 Outine Introduction to ATPG ATPG for Combinationa Circuits Advanced ATPG Techniques 3 Input and Output of an ATPG ATPG (Automatic Test Pattern Generation) Generate a set of
More informationIntroduction to OpenMP
MPSoC Architectures OpenMP Aberto Bosio, Associate Professor UM Microeectronic Departement bosio@irmm.fr Introduction to OpenMP What is OpenMP? Open specification for Muti-Processing Standard API for defining
More informationA Memory Grouping Method for Sharing Memory BIST Logic
A Memory Grouping Method for Sharing Memory BIST Logic Masahide Miyazai, Tomoazu Yoneda, and Hideo Fuiwara Graduate Schoo of Information Science, Nara Institute of Science and Technoogy (NAIST), 8916-5
More informationIBC DOCUMENT PROG007. SA/STA SERIES User's Guide V7.0
IBC DOCUMENT SA/STA SERIES User's Guide V7.0 Page 2 New Features for Version 7.0 Mutipe Schedues This version of the SA/STA firmware supports mutipe schedues for empoyees. The mutipe schedues are impemented
More informationFunctions. Lecture 6 COP 3014 Spring February 11, 2018
Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a mini-program (or subprogram) in its
More informationSample of a training manual for a software tool
Sampe of a training manua for a software too We use FogBugz for tracking bugs discovered in RAPPID. I wrote this manua as a training too for instructing the programmers and engineers in the use of FogBugz.
More informationShape Analysis with Structural Invariant Checkers
Shape Anaysis with Structura Invariant Checkers Bor-Yuh Evan Chang Xavier Riva George C. Necua University of Caifornia, Berkeey SAS 2007 Exampe: Typestate with shape anaysis Concrete Exampe Abstraction
More informationFunctions. Arizona State University 1
Functions CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 6 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationArray Elements as Function Parameters
Arrays Class 26 Array Elements as Function Parameters we have seen that array elements are simple variables they can be used anywhere a normal variable can unsigned values [] {10, 15, 20}; unsigned quotient;
More informationfile://j:\macmillancomputerpublishing\chapters\in073.html 3/22/01
Page 1 of 15 Chapter 9 Chapter 9: Deveoping the Logica Data Mode The information requirements and business rues provide the information to produce the entities, attributes, and reationships in ogica mode.
More informationStandard Version of Starting Out with C++, 4th Edition. Chapter 6 Functions. Copyright 2003 Scott/Jones Publishing
Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions Copyright 2003 Scott/Jones Publishing Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes
More informationA METHOD FOR GRIDLESS ROUTING OF PRINTED CIRCUIT BOARDS. A. C. Finch, K. J. Mackenzie, G. J. Balsdon, G. Symonds
A METHOD FOR GRIDLESS ROUTING OF PRINTED CIRCUIT BOARDS A C Finch K J Mackenzie G J Basdon G Symonds Raca-Redac Ltd Newtown Tewkesbury Gos Engand ABSTRACT The introduction of fine-ine technoogies to printed
More informationDistance Weighted Discrimination and Second Order Cone Programming
Distance Weighted Discrimination and Second Order Cone Programming Hanwen Huang, Xiaosun Lu, Yufeng Liu, J. S. Marron, Perry Haaand Apri 3, 2012 1 Introduction This vignette demonstrates the utiity and
More informationMCSE Training Guide: Windows Architecture and Memory
MCSE Training Guide: Windows 95 -- Ch 2 -- Architecture and Memory Page 1 of 13 MCSE Training Guide: Windows 95-2 - Architecture and Memory This chapter wi hep you prepare for the exam by covering the
More informationA Petrel Plugin for Surface Modeling
A Petre Pugin for Surface Modeing R. M. Hassanpour, S. H. Derakhshan and C. V. Deutsch Structure and thickness uncertainty are important components of any uncertainty study. The exact ocations of the geoogica
More informationReview. Modules. CS 151 Review #6. Sample Program 6.1a:
Review Modules A key element of structured (well organized and documented) programs is their modularity: the breaking of code into small units. These units, or modules, that do not return a value are called
More informationAs Michi Henning and Steve Vinoski showed 1, calling a remote
Reducing CORBA Ca Latency by Caching and Prefetching Bernd Brügge and Christoph Vismeier Technische Universität München Method ca atency is a major probem in approaches based on object-oriented middeware
More informationUser s Guide. Eaton Bypass Power Module (BPM) For use with the following: Eaton 9155 UPS (8 15 kva)
Eaton Bypass Power Modue (BPM) User s Guide For use with the foowing: Eaton 9155 UPS (8 15 kva) Eaton 9170+ UPS (3 18 kva) Eaton 9PX Spit-Phase UPS (6 10 kva) Specia Symbos The foowing are exampes of symbos
More informationMCSE TestPrep SQL Server 6.5 Design & Implementation - 3- Data Definition
MCSE TestPrep SQL Server 6.5 Design & Impementation - Data Definition Page 1 of 38 [Figures are not incuded in this sampe chapter] MCSE TestPrep SQL Server 6.5 Design & Impementation - 3- Data Definition
More informationFunctions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92
L E S S O N S E T 6.2 Functions that Return a Value PURPOSE PROCEDURE 1. To introduce the concept of scope 2. To understand the difference between static, local and global variables 3. To introduce the
More informationNCH Software Spin 3D Mesh Converter
NCH Software Spin 3D Mesh Converter This user guide has been created for use with Spin 3D Mesh Converter Version 1.xx NCH Software Technica Support If you have difficuties using Spin 3D Mesh Converter
More informationWeek 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.
Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than
More informationRevisions for VISRAD
Revisions for VISRAD 16.0.0 Support has been added for the SLAC MEC target chamber: 4 beams have been added to the Laser System: X-ray beam (fixed in Port P 90-180), 2 movabe Nd:Gass (ong-puse) beams,
More informationCPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)
Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value
More informationIf your PC is connected to the Internet, you should download a current membership data file from the SKCC Web Server.
fie:///c:/users/ron/appdata/loca/temp/~hhe084.htm Page 1 of 54 SKCCLogger, Straight Key Century Cub Inc. A Rights Reserved Version v03.00.11, 24-Oct-2018 Created by Ron Bower, AC2C SKCC #2748S SKCCLogger
More information3GPP TS V7.1.0 ( )
TS 29.199-7 V7.1.0 (2006-12) Technica Specification 3rd Generation Partnership Project; Technica Specification Group Core Network and Terminas; Open Service Access (OSA); Paray X Web Services; Part 7:
More informationSQL3 Objects. Lecture #20 Autumn, Fall, 2001, LRX
SQL3 Objects Lecture #20 Autumn, 2001 #20 SQL3 Objects HUST,Wuhan,China 588 Objects in SQL3 OQL extends C++ with database concepts, whie SQL3 extends SQL with OO concepts. #20 SQL3 Objects HUST,Wuhan,China
More informationAn Optimizing Compiler
An Optimizing Compier The big difference between interpreters and compiers is that compiers have the abiity to think about how to transate a source program into target code in the most effective way. Usuay
More informationHour 3: The Network Access Layer Page 1 of 10. Discuss how TCP/IP s Network Access layer relates to the OSI networking model
Hour 3: The Network Access Layer Page 1 of 10 Hour 3: The Network Access Layer At the base of the TCP/IP protoco stack is the Network Access ayer, the coection of services and specifications that provide
More informationLecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR
1 Statements: A statement in a computer carries out some action. There are three types of statements used in C++; they are expression statement, compound statement and control statement. Expression statement
More informationOutline. Parallel Numerical Algorithms. Forward Substitution. Triangular Matrices. Solving Triangular Systems. Back Substitution. Parallel Algorithm
Outine Parae Numerica Agorithms Chapter 8 Prof. Michae T. Heath Department of Computer Science University of Iinois at Urbana-Champaign CS 554 / CSE 512 1 2 3 4 Trianguar Matrices Michae T. Heath Parae
More informationDatabases and PHP. Accessing databases from PHP
Databases and PHP Accessing databases from PHP PHP & Databases PHP can connect to virtuay any database There are specific functions buit-into PHP to connect with some DB There is aso generic ODBC functions
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More informationBITG 1113: Function (Part 2) LECTURE 5
BITG 1113: Function (Part 2) LECTURE 5 1 Learning Outcomes At the end of this lecture, you should be able to: explain parameter passing in programs using: Pass by Value and Pass by Reference. use reference
More informationNCH Software Express Accounts Accounting Software
NCH Software Express Accounts Accounting Software This user guide has been created for use with Express Accounts Accounting Software Version 5.xx NCH Software Technica Support If you have difficuties using
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationWelcome - CSC 301. CSC 301- Foundations of Programming Languages
Wecome - CSC 301 CSC 301- Foundations of Programming Languages Instructor: Dr. Lutz Hame Emai: hame@cs.uri.edu Office: Tyer, Rm 251 Office Hours: TBA TA: TBA Assignments Assignment #0: Downoad & Read Syabus
More informationCSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Lecture 4: Threads
CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Lecture 4: Threads Announcement Project 0 Due Project 1 out Homework 1 due on Thursday Submit it to Gradescope onine 2 Processes Reca that
More informationECEn 528 Prof. Archibald Lab: Dynamic Scheduling Part A: due Nov. 6, 2018 Part B: due Nov. 13, 2018
ECEn 528 Prof. Archibad Lab: Dynamic Scheduing Part A: due Nov. 6, 2018 Part B: due Nov. 13, 2018 Overview This ab's purpose is to expore issues invoved in the design of out-of-order issue processors.
More informationInfinity Connect Web App Customization Guide
Infinity Connect Web App Customization Guide Contents Introduction 1 Hosting the customized Web App 2 Customizing the appication 3 More information 8 Introduction The Infinity Connect Web App is incuded
More informationLab Instructor : Jean Lai
Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.
More informationProgramming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1
300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard
More informationFunctions. CS111 Lab Queens College, CUNY Instructor: Kent Chin
Functions CS111 Lab Queens College, CUNY Instructor: Kent Chin Functions They're everywhere! Input: x Function: f Output: f(x) Input: Sheets of Paper Function: Staple Output: Stapled Sheets of Paper C++
More informationNCH Software Express Delegate
NCH Software Express Deegate This user guide has been created for use with Express Deegate Version 4.xx NCH Software Technica Support If you have difficuties using Express Deegate pease read the appicabe
More informationProfessor: Alvin Chao
Professor: Avin Chao CS149 More with Casses and Objects OverLoading Let's ook at the Car cass... Terminoogy Method definition pubic void acceerate(doube amount) { speed += amount; if (speed > MAX_SPEED)
More informationConcurrent programming: From theory to practice. Concurrent Algorithms 2016 Tudor David
oncurrent programming: From theory to practice oncurrent Agorithms 2016 Tudor David From theory to practice Theoretica (design) Practica (design) Practica (impementation) 2 From theory to practice Theoretica
More informationA Fast Block Matching Algorithm Based on the Winner-Update Strategy
In Proceedings of the Fourth Asian Conference on Computer Vision, Taipei, Taiwan, Jan. 000, Voume, pages 977 98 A Fast Bock Matching Agorithm Based on the Winner-Update Strategy Yong-Sheng Chenyz Yi-Ping
More informationGetting started with C++ (Part 2)
Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output
More informationCS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil
CS 1428 Review CS 2308 :: Spring 2016 Molly O Neil Structure of a C++ Program Hello world // This program prints a greeting to the screen #include using namespace std; int main() { cout
More informationAutomatic Grouping for Social Networks CS229 Project Report
Automatic Grouping for Socia Networks CS229 Project Report Xiaoying Tian Ya Le Yangru Fang Abstract Socia networking sites aow users to manuay categorize their friends, but it is aborious to construct
More informationChapter 7 - Notes User-Defined Functions II
Chapter 7 - Notes User-Defined Functions II I. VOID Functions ( The use of a void function is done as a stand alone statement.) A. Void Functions without Parameters 1. Syntax: void functionname ( void
More informationFurther Optimization of the Decoding Method for Shortened Binary Cyclic Fire Code
Further Optimization of the Decoding Method for Shortened Binary Cycic Fire Code Ch. Nanda Kishore Heosoft (India) Private Limited 8-2-703, Road No-12 Banjara His, Hyderabad, INDIA Phone: +91-040-3378222
More informationECE 172 Digital Systems. Chapter 14 Itanium EPIC Processor Architecture. Herbert G. Mayer, PSU Status 5/10/2018
ECE 172 Digita Systems Chapter 14 Itanium EPIC Processor Architecture Herbert G. Mayer, PSU Status 5/10/2018 1 Syabus Introduction Inte Itanium Architecture Data and Memory Itanium Registers Instruction
More informationEnd To End Software Developer Training
Page 1 of 13 Software Deveoper Boot Camp www. End To End Software Deveoper Training C# Training ASP.NET Training Software Deveoper Boot Camp.NET FRAMEWORK Training ADO.NET Training About The Software Deveoper
More informationHigh Performance Computing - Introduction to GPGPU Programming. Prof Matt Probert
High Performance Computing - Introduction to GPGPU Programming Prof Matt Probert http://www-users.york.ac.uk/~mijp1 Overview What are GPUs? GPU Architecture Memory Programming in CUDA The Future What is
More information