Computer Programming

Similar documents
Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming. Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay

CS11 Advanced C++ Fall Lecture 1

The Standard Template Library Classes

CS197c: Programming in C++

The Standard Template Library. An introduction

ADT: Design & Implementation

CS24 Week 4 Lecture 2

6.096 Introduction to C++

Standard Library. Lecture 27. Containers. STL Containers. Standard Library

G52CPP C++ Programming Lecture 12

CS240: Programming in C

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi

Lecture 3. Variables. Variables

C++ Programming Lecture 2 Software Engineering Group

(8 1) Container Classes & Class Templates D & D Chapter 18. Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

GridKa School 2013: Effective Analysis C++ Standard Template Library

TEMPLATES AND ITERATORS

G Programming Languages - Fall 2012

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

CPSC 427a: Object-Oriented Programming

Procedural Programming

More on Functions. Lecture 7 COP 3014 Spring February 11, 2018

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

Protection Levels and Constructors The 'const' Keyword

SISTEMI EMBEDDED. Stack, Subroutine, Parameter Passing C Storage Classes and Scope. Federico Baronti Last version:

CMSC 341 Lecture 6 STL, Stacks, & Queues. Based on slides by Lupoli, Dixon & Gibson at UMBC

Run-time Environments - 2

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Chapter 7 Constructors and Other Tools. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Computer Programming

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library

class Polynomial { public: Polynomial(const string& N = "no name", const vector<int>& C = vector<int>());... };

C++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator

G52CPP C++ Programming Lecture 13

LECTURE 11 TREE TRAVERSALS

Containers and the Standard Template Library (STL)

Compiler Design Spring 2017

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli

CS 225. Data Structures. Wade Fagen-Ulmschneider

6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Comp Sci 1MD3 Mid-Term II 2004 Dr. Jacques Carette

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

Launchpad Lecture -10

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers

Introduction. Programming in C++ Pointers and arrays. Pointers in C and C++ Session 5 - Pointers and Arrays Iterators

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lab 2: ADT Design & Implementation

Object-Oriented Programming. Lecture 2 Dr Piotr Cybula

CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists

Tell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation }

CS 101: Computer Programming and Utilization

The smallest element is the first one removed. (You could also define a largest-first-out priority queue)

Chapter 5. The Standard Template Library.

by Pearson Education, Inc. All Rights Reserved. 2

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Lecture 4a Using The Standard Template Library. Jack Applin, Guest Lecturer

CSS 342 Data Structures, Algorithms, and Discrete Mathematics I. Standard Template Library

Winter 2003 MID-SESSION TEST Monday, March 10 6:30 to 8:00pm

Bruce Merry. IOI Training Dec 2013

Function Calls and Stack Allocation

Chapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Function Calls and Stack Allocation

Stack. Stack. Function Calls and Stack Allocation. Stack Popping Popping. Stack Pushing Pushing. Page 1

CS 103 Unit 12 Slides

Brook Spec v0.2. Ian Buck. May 20, What is Brook? 0.2 Streams

CS 101: Computer Programming and Utilization

CSCI-1200 Computer Science II Fall 2008 Lecture 15 Associative Containers (Maps), Part 2

Polymorphism. Programming in C++ A problem of reuse. Swapping arguments. Session 4 - Genericity, Containers. Code that works for many types.

G52CPP C++ Programming Lecture 15

CSE 100: C++ TEMPLATES AND ITERATORS

Transcription:

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

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

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 3 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

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, 4

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, 5

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, 6

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, 7

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, 8

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, 9

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

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, 11

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, 12