Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty

Slides:



Advertisements
Similar presentations
Chapter 18 Vectors and Arrays
Advertisements

Object Oriented Programming Lect. Dr. Daniel POP Universitatea de Vest din Timişoara Facultatea de Matematică şi Informatică.
Data Structures Using C++ 2E
Chapter 18 Vectors and Arrays John Keyser’s Modification of Slides by Bjarne Stroustrup
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
Lecture 8. MIPS Instructions #4 – Branch Instructions #2
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 9: Pass-by-Value.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Lecture From Chapter 6 & /8/10 1 Method of Classes.
Sorting and Vectors Mechanism for representing lists JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Data Structures Using C++ 2E
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
 2003 Prentice Hall, Inc. All rights reserved.m ECE 2552 Dr. Këpuska based on Dr. S. Kozaitis Summer Chapter 15 - Class string and String Stream.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
University of Malta CSA2090: Lecture 4 © Chris Staff 1 of 20 CSA2090: Systems Programming Introduction to C Dr. Christopher Staff.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.
Const declares immutable value void Test(char* t) { t++;// OK, address is not const t[0] = 'a'; // OK, char is not const } void Test2(const char* t) {
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 26 Clicker Questions December 3, 2009.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review 2.
CHAPTER 07 Arrays and Vectors (part II). OBJECTIVES In this part you will learn:  To pass arrays to functions.  Basic searching techniques.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Vectors Updated 11/4/2003 by Kip Irvine. Copyright Kip Irvine Overview What is a vector? Declaring vector objects Inserting and removing items Using.
IIT Bombay Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay Session: Operator.
IIT Bombay Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay Session: Friends.
IIT Bombay Data Structures and Algorithms Prof. Ajit A. Diwan Prof. Ganesh Ramakrishnan Prof. Deepak B. Phatak Department of Computer Science and Engineering.
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
How to be generic Lecture 10
Data Structures and Algorithms
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
CISC181 Introduction to Computer Science Dr
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
Data Structures and Algorithms
Data Structures and Algorithms
Templates in C++.
Data Structures and Algorithms
More Object Oriented Programming
ADT Implementations: Templates and Standard Containers
Pass by Reference, const, readonly, struct
Vectors.
Object-Oriented Programming (OOP) Lecture No. 36
An Introduction to Java – Part II
Classes & Objects: Examples
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Constructors and Other Tools
Templates. Templates Example: Swap Template Mechanism.
Objects with Functions and Arrays
Introduction to Programming
Reference Parameters.
CS148 Introduction to Programming II
Parasol Lab, Texas A&M University
Method of Classes Chapter 7, page 155 Lecture /4/6.
CS149D Elements of Computer Science
Guidelines for Writing Functions
Standard Template Library
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
Standard Template Library
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
Presentation transcript:

Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay Session : Concluding Comments on C++ Standard Library Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Quick Recap of Relevant Topics C++ Standard Library The “string” class The “vector” class The “map” class The “list” class Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Overview of This Lecture Comments about passing container objects as function parameters/return values Use of “typedef” to simplify complex container class definitions Overview of some useful C++ Standard Library modules Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Acknowledgment Some parts of this lecture are motivated by the treatment in An Introduction to Programming Through C++ by Abhiram G. Ranade McGraw Hill Education 2014 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Using Container Classes in Function Calls Passing container objects as parameters by value: void func1(vector<int> v1, map<string, int> m1) Vector v1 and map m1 must be copied to activation record of func1 Copy constructor of vector<int> and map<string, int>used for copying values Default copy constructor copies values of all data members Can be highly inefficient (both time- and memory-wise) if large container objects passed as parameters Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Using Container Classes in Function Calls Passing container objects as parameters by reference: void func1(vector<int> &v1, map<string, int> &m1) No copying of data member values to activation record of func1. Time and memory overhead independent of size of parameter container object Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Using Container Classes in Function Calls If parameters passed by reference must be prevented from being modified by callee void func1(vector<int> const &v1, map<string, int> const &m1) Container objects can have huge memory footprints. Parameter passing mechanism must be chosen with discretion. Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Using Container Classes in Function Calls map<string, double> func2(vector<int> const &v1) Result map computed by func2 must be copied to activation record of caller when func2 returns Copy constructor can be inefficient if map is large void altFunc2(vector<int> const &v1, map<string, double> &res) No copying of result map needed – much more efficient in practice Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Using Simple Type Names in Container Classes Declarations like vector<map<string, map<double, list<V3> > > > myVec; difficult to read, understand, modify C++ provides typedef to give custom names to types typedef list<V3> listOfV3; typedef map<double, listOfV3> mapDoubleListOfV3; typedef map<string, mapDoubleListOfV3> myType; typedef vector<myType> vecOfMyType; vecOfMyType myVec; Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

C++ Standard Library: Additional Useful Modules Several useful container class libraries queue deque stack set forward_list … Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

C++ Standard Library: Additional Useful Modules Several other useful libraries of utilities algorithm complex exception random memory … Several excellent online references http://www.cplusplus.com/reference http://en.wikipedia.org/wiki/C++_Standard_Library Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Summary Use of container classes in function calls Use of “typedef“ to simplify complex container class definitions High-level view of useful modules in C++ Standard Library Strongly encouraged to read more about C++ Standard Library and use it in your programs Extremely well-designed, thoroughly tested and well-documented Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay