Container Class and Integrators, Proxy Class EC6301-OOPS AND DATA STRUCTURES

Similar documents
Standard Template Library

DELHI PUBLIC SCHOOL TAPI

C++ 8. Constructors and Destructors

Dynamic Data Structures

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming

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

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

READ ALL INSTRUCTIONS

CS197c: Programming in C++

COEN244: Class & function templates

Lecture-5. STL Containers & Iterators

UNIT POLYMORPHISM

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently.

Chapter 17: Linked Lists

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

LECTURE 11 TREE TRAVERSALS

Templates & the STL. CS 2308 :: Fall 2015 Molly O'Neil

Inheritance: Single level inheritance:

Matrix-Vector Multiplication using friend function

The Standard Template Library. An introduction

CS11 Advanced C++ Fall Lecture 1

Abstraction in C++ Abstraction is the concept of exposing only the required essential characteristics and behavior

CSE 100: C++ TEMPLATES AND ITERATORS

STL Standard Template Library

List, Stack, and Queues

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

CIS 190: C/C++ Programming. Lecture 12 Student Choice


Structuur van Computerprogramma s 2

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

CS 261: Data Structures. Dynamic Array Queue

Unit 4 Basic Collections

ICOM 4035 Data Structures. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department

CSE 100: C++ TEMPLATES AND ITERATORS

STL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms

PIC 10A. Lecture 23: Intro to STL containers

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

TEMPLATES AND ITERATORS

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

AN OVERVIEW OF C++ 1

Introduction to ADTs

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

Arrays and Linked Lists

CPSC 427a: Object-Oriented Programming

Chapter 5. The Standard Template Library.

CHAPTER 9 FLOW OF CONTROL

Downloaded from

C++ Programming Basics III

Introduction to ADTs

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class

Lecture 21 Standard Template Library. A simple, but very limited, view of STL is the generality that using template functions provides.

Downloaded from

7 TEMPLATES AND STL. 7.1 Function Templates

Computational Physics

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

CS 216 Exam 1 Fall SOLUTION

CSE202-Lec#4. CSE202 C++ Programming

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

Object Oriented Pragramming (22316)

Vectors. CIS 15 : Spring 2007

Linked List. April 2, 2007 Programming and Data Structure 1

EL2310 Scientific Programming

DataStruct 9. Hash Tables, Maps, Skip Lists, and Dictionaries

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

Data Structures (CS301) LAB

1 Short Answer (7 Points Each)

Types of Containers: Sequences

CSE100. Advanced Data Structures. Lecture 4. (Based on Paul Kube course materials)

Kapi ap l S e S hgal P T C p t u er. r S. c S ienc n e A n A k n leshw h ar ar Guj u arat C C h - 8

Modularity. Modular program development. Language support for modularity. Step-wise refinement Interface, specification, and implementation

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp

1B1b Implementing Data Structures Lists, Hash Tables and Trees

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

Supplement I.A: Glossary. For Introduction to C++ Programming, Second Edition By Y. Daniel Liang

CSCE 110 PROGRAMMING FUNDAMENTALS

DC54 DATA STRUCTURES DEC 2014

CSI33 Data Structures

C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

Downloaded S. from Kiran, PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from

CS32 Summer Object-Oriented Programming in C++ Templates and STL. Victor Amelkin September 12, 2013

Abstract Data Types 1

2016 COMPUTER SCIENCE

Chapter 17: Linked Lists

Review for Test 1 (Chapter 1-5)

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

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

CS 261: Data Structures. Dynamic Array Queue

Object-Oriented Programming

Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

EL2310 Scientific Programming

CSE 100: C++ TEMPLATES AND ITERATORS

STL: C++ Standard Library

EE 355 Unit 10. C++ STL - Vectors and Deques. Mark Redekopp

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

Linked lists. Insert Delete Lookup Doubly-linked lists. Lecture 6: Linked Lists

Abstract Data Types. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Transcription:

Container Class and Integrators, Proxy Class

Container Class A container class is a data type that is capable of holding a collection of items. A container stores many entities and provide sequential or direct access to them. List, vector and strings are such containers in standard template library. Various operations associated with container class are: Create an empty container Insert an object inside the container Remove an object from container Find the number of objects in the container Sort the objects within the container

Components of STL

Container class Categories of container class: Sequence containers Associative containers Container adapters Sequence container: container class that maintain the ordering of elements in the container. Types of Sequence containers: Vector :dynamic array capable of growing,allows random access to its element. Deque: deck, double ended queue, grow from both sides List: Doubly linked list

Container class Associative containers: automatically sort their inputs when those inputs are inserted into the container. Associative containers compare elements using operator <. Types of associative containers: Multiset- duplicate elements are allowed Map(associative array)- key/value pair Multimap(dictionary)-is a map that allows duplicate keys.(key word, value-meaning)

Container class Container adapters: predefined containers that are adapted to specific uses. Stack : LIFO,operations done at end of the container Queue: FIFO, Insertion: back of the container, Deletion: front Priority queue

Container class Iterator It is an object that can traverse a container class without the user having to know how the container is implemented.

Container class #include<iostream.h> #include<conio.h> class bag public: void insert(int); void show(); int size(); bag()count=0;} private: int data[20]; int count; };

Container class void bag::insert(int val) data[count]=val; count++; } void bag::show() for(int i=0;i<count;i++) cout<<" "<<data[i]; } int bag::size() return count; }

Container class void main() bag o; clrscr(); cout<<"\nthe items in container are:\n"; o.insert(20); o.insert(40); o.insert(60); o.show(); cout<<"\n size of the container"<<o.size(); cout<<"\n items in container are\n"; o.insert(80);

Container class o.insert(100); o.show(); cout<<" \n size of container is"<<o.size(); cout<<"\n"; getch(); }

Container class

Proxy Class Proxy class: Used to hide implementation details of a class Class that knows only the public interface of the class being hidden Enables clients to use class services without giving access to class s implementation Forward class declaration: Used when class definition only uses a pointer to another class Prevents the need for including header file Declares a class before it is referenced

Proxy Class: Creation of myclass.h class myclass private: int value; public: myclass(int v):value(v) } void setvalue(int v) value=v; } int getvalue() return value; } };

Proxy Class:myinterface.cpp class myclass; class myinterface private: myclass *ptr; public: myinterface(int); void setvalue(int); int getvalue(); ~myinterface(); };

Proxy Class: Creation of Myinterface.cpp #include"c:\turboc4\tc\bin\myinterf.h" #include"c:\turboc4\tc\bin\myclass.h" myinterface::myinterface(int v):ptr(new myclass(v)) } void myinterface::setvalue(int v) ptr->setvalue(v); } int myinterface::getvalue() return ptr->getvalue(); }

Proxy Class :Creation of Myinterface.cpp myinterface::~myinterface() delete ptr; }

Proxy Class: Creation of test.cpp #include<iostream.h> #include"c:\tc\bin\myinterf.h" void main() myinterf obj(10); cout<<"\n interface contains(before):"<<obj.getvalue(); obj.setvalue(20); cout<<"\n interface contains(after):"<<obj.getvalue(); }