CSCI 62 Data Structures Dr. Joshua Stough December 2, 2008.

Slides:



Advertisements
Similar presentations
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Advertisements

C++ crash course Class 10 practice problems. Pointers The following function is trying to swap the contents of two variables. Why isnt it working? void.
Part 1 Landscape Hannu Laine. Pointer parameters //prototype of swap void swap(int *a, int *b); //application void main(void) { in number1 = 1, number2.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Template. 2 Using templates, it is possible to create generic functions and classes. In a generic function or class, the type of data upon which the function.
Functions Prototypes, parameter passing, return values, activation frams.
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
Chapter 17 Templates. Generic Algorithms Algorithms in which the actions or steps are defined, but the data types of the items being manipulated are not.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
5th MaCS Debrecen On the Turing-Completeness of Generative Metaprograms Zoltán Porkoláb, István Zólyomi Dept. of Programming.
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Procedures and Control Flow CS351 – Programming Paradigms.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
Const Parameters & In Line Functions 04/15/11. Next Time  Quiz, Monday, 04/18/11  Over 5.2 and 5.3 void functions pass-by-reference  Read 7.1 about.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
C++ function call by value The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter.
Generics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
P Improvements - Constructor p Parameter passing Constructors Problem Solving With C++
Learners Support Publications Functions in C++
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
WEEK 2 Introduction to Java II CSE 252 Principles of Programming Languages LAB SECTION.
Overview of C++ Templates
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Functions Sujana Jyothi C++ Workshop Day 2. Functions 3 Parameter transmission modes pass by value (default) pass by reference (&) pass by const reference.
CSI 3125, Preliminaries, page 1 Generic Class & Generic methods.
TOPIC 6 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
C++ Basics II Lecture 2 Seoul National University Graphics & Media Lab.
CSCI 62 Data Structures Dr. Joshua Stough September 11, 2008.
Object-Oriented Programming in C++ Lecture 4 Constants References Operator overloading.
Chapter 3 Templates. Objective In Chapter 3, we will discuss: The concept of a template Function templates Class templates vector and matrix classes Fancy.
CS212: Object Oriented Analysis and Design Lecture 22: Generic Class Design.
Cop3530sp12. Parameter passing call by value- appropriate for small objects that should not be altered by the function call by constant reference- appropriate.
Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
Chapter 7 Constructors and Other Tools Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
1 Parameter passing Call by value The caller evaluates the actual parameters and passes copies of their values to the called function. Changes to the copies.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Functions Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
PROGRAMMING 1 – HELPER INSTRUCTIONS ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
CHAPTER 07 Arrays and Vectors (part II). OBJECTIVES In this part you will learn:  To pass arrays to functions.  Basic searching techniques.
Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
C++ Functions A bit of review (things we’ve covered so far)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Pointers Call-by-Reference.
C++ REVIEW – TEMPLATES. GENERIC PROGRAMMING Programming/developing algorithms with the abstraction of types Algorithms/data is expressed “without type”
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
How to be generic Lecture 10
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Pointers Call-by-Reference CSCI 230
Lec 14 Oct 23, 02.
Functions 2: Stupid Function Tricks
Parameter Passing in Java
CS2011 Introduction to Programming I Methods (II)
Default Arguments.
Seoul National University
Presentation transcript:

CSCI 62 Data Structures Dr. Joshua Stough December 2, 2008

Functions Same as in java but: –Can be defined outside of any class. –Can use default parameters int max(int a = 0, int b = 0); –Parameters after those given a default value must also be default. –Inline functions Rather than jump at run-time, paste in at compile time –inline int max(int a, int b) { return a > b ? a : b; } –More versatile parameter passing.

Parameter passing Call by value – typical Java way. –void swap (int a, int b); Call by reference – can change actual parameters –void swap (int &a, int &b); Call by const reference – function promises not to change actual parameter –int binSearch(const vector &arr, int key); Arrays passed by reference, but vectors passed by value (default).

Templates, Generics Lab.