Introduction to Programming

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Stack and Queues using Linked Structures Kruse and Ryba Ch 4.
Overloading Operators Overloading operators Unary operators Binary operators Member, non-member operators Friend functions and classes Function templates.
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.
Introduction to Programming Lecture 31. Operator Overloading.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
Stacks.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 22 - C++ Templates Outline 22.1Introduction 22.2Class Templates 22.3Class Templates and Non-type.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - Templates Outline 11.1 Introduction 11.2 Function Templates 11.3 Overloading Function Templates.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
1 Lecture 8: Introduction to C++ Templates and Exceptions  C++ Function Templates  C++ Class Templates.
Templates Outlines 1. Introduction 2. Function Templates 3. Overloading Function Templates 4. Class Templates.
Data Structures Lecture-12 : STL Azhar Maqsood NUST Institute of Information Technology (NIIT)
Templates Zhen Jiang West Chester University
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - Templates Outline 11.1 Introduction 11.2 Function Templates 11.3 Overloading Function Templates.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 12 - Templates Outline 12.1Introduction 12.2Function Templates 12.3Overloading Template Functions.
Chapter 7 Templates. Objectives Introduction Function Templates Class Templates Standard Template Library.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 14: Overloading and Templates Overloading will not be covered.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 22 - C++ Templates Outline 22.1Introduction.
TEMPLATESTEMPLATES BCAS,Bapatla B.mohini devi. Templates Outline 22.1Introduction 22.2Class Templates 22.3Class Templates and Non-type Parameters 22.4Templates.
CS212: Object Oriented Analysis and Design Lecture 22: Generic Class Design.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
 2000 Deitel & Associates, Inc. All rights reserved. 12.1Introduction Templates - easily create a large range of related functions or classes –function.
Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Session 03 - Templates Outline 03.1Introduction 03.2Function Templates 03.3Overloading Template Functions 03.4Class Templates 03.5Class Templates and Non-type.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
Chapter 22 - C++ Templates
Programming with ANSI C ++
18 Chapter Stacks and Queues
Chapter 18: Stacks and Queues.
C++ Templates.
Examples of Classes & Objects
Stack and Queue APURBO DATTA.
CS212: Object Oriented Analysis and Design
CMSC 341 Lecture 5 Stacks, Queues
Object-Oriented Programming (OOP) Lecture No. 32
CSC 253 Lecture 8.
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 19: Stacks and Queues.
Pass by Reference, const, readonly, struct
CSC 253 Lecture 8.
Object-Oriented Programming (OOP) Lecture No. 36
Stack Memory 2 (also called Call Stack)
Introduction to Programming
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Visit for more Learning Resources
UNIT-II.
Stacks.
CS150 Introduction to Computer Science 1
Template.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Chapter 22 - C++ Templates
Chapter 22 - C++ Templates
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Data Structures & Programming
Presentation transcript:

Introduction to Programming Lecture 42

template <class T>

Template Classes

Stack

Last In First Out

template <class T> class ClassName { definition }

Member function template <class T> Class_Name <T> :: Function_Name (Arguments) { // body of function }

Class_Name :: Function_Name ( Arguments ) { // body of function }

Example template <class T> class Number { private : T MyNumber ; public: Number ( T n ) ; display ( ) ; }

Example Number <int> x ; Number <double> y ;

Non Type Parameters

template <class T , int elements>

int x [ 100 ] ;

Static Member Variables

Number <int> x ;

Example class PhoneCall { private : int lengthOfCall ; char billCode ; public : PhoneCall ( const int i , char b ) ; PhoneCall ( PoneCall & p ) ; PhoneCall PhoneCall :: operator - ( void ) ; void display ( void ) ; } ;

Example PhoneCall PhoneCall :: operator -( void ) { PhoneCall temp ( * this ) ; temp.billCode = 'C' ; return ( temp ) ; }

Friend Function

‘a’ is a object of a class 2 is an integer value ‘a’ is a object of a class a + 2 ;

a + 2 ; should be same as 2 + a ;

friend f ( ) ;

friend f ( x <T> & ) ;

friend f ( X <int> & ) ;

friend class Y ;

friend A :: f ( ) ;

friend A :: f ( X< T > & )

Example template <class T> class Stack { private : int size ; T array [ ] ; public : Stack ( ) ; void push ( T ) ; T pop ( ) ; bool isEmpty ( ) ; bool isFull ( ) ; // Etc. } ;

Example Stack <int> x ; Stack <double> x ;

Last In First Out

Queue Link List

First In First Out

STL Standard Template Library