Data Structures Using C++1 Chapter 4 Standard Template Library (STL)

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Chapter 19 Standard Template Library. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Iterators Constant and mutable.
Chapter 6 Queues and Deques.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Data Structures Using C++ 2E
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Chapter 7: User-Defined Functions II
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 13: Inheritance and Composition.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 12: Inheritance and Composition.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.
C++ for Engineers and Scientists Third Edition
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 12: Inheritance and Composition.
Basic C++ Sequential Container Features
Chapter 10: Inheritance and Polymorphism
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Rossella Lau Lecture 12, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 12: An Introduction to the STL  Basic.
Chapter 11: Inheritance and Polymorphism Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Data Structures Using C++ 2E
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 13: Inheritance and Composition.
Chapter 10: Records (structs)
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Data Structures Using C++ 2E
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 10 Applications of Arrays and Strings. Chapter Objectives Learn how to implement the sequential search algorithm Explore how to sort an array.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 11: Records ( struct s)
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
Chapter 13: Inheritance and Composition
C++ STL CSCI 3110.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
COP 3530 Data Structures & Algorithms Discussion Session 3.
Friends & Standard Template Library CSCI3110 Advanced Data Structures Lecturer: Dr. Carroll and Nan Chen.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Chapter 22 STL Containers §22.1 STL Basics §22.2 STL Iterators §22.3 Sequence Containers §22.4 Associative Containers §22.5 Container Adapters.
 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.
CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Intro to the C++ STL Timmie Smith September 6, 2001.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
Standard Template Library (STL) - Use Vector and Deque
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
C++ Review STL CONTAINERS.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
Programming in C++ Michal Brabec Petr Malý. Standard Template Library Containers - vector, map, set, deque, list Algorithms - copy, replace, sort, find.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Introduction to programming in java Lecture 21 Arrays – Part 1.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
C++ Programming:. Program Design Including
Standard Template Library
Chapter 11: Inheritance and Polymorphism
Standard Template Library (STL)
Chapter 22: Standard Template Library (STL)
CS212: Object Oriented Analysis and Design
Presentation transcript:

Data Structures Using C++1 Chapter 4 Standard Template Library (STL)

Data Structures Using C++2 Chapter Objectives Learn about the Standard Template Library (STL) Become familiar with the three basic components of the STL: containers, iterators, and algorithms Explore how vector and deque containers are used to manipulate data in a program Discover the use of iterators

Data Structures Using C++3 Components of the STL Containers Iterators Algorithms

Data Structures Using C++4 Container Types Sequence containers (sequential containers) Associative containers Container adapters

Data Structures Using C++5 Sequence Containers Vector Deque list

Data Structures Using C++6 Ways to Declare and Initialize a Vector Container

Data Structures Using C++7 Operations to Access the Elements of a Vector Container

Data Structures Using C++8 Operations on a Vector Container

Data Structures Using C++9 Functions to Determine the Size of a Vector Container

Data Structures Using C++10 Member Functions Common to All Containers

Data Structures Using C++11 Member Functions Common to All Containers

Data Structures Using C++12 Member Functions Common to All Sequence Containers

Data Structures Using C++13 Prototype of function template copy template outputItr copy(inputIterator first1, inputIterator last, outputIterator first2);

Data Structures Using C++14 Sequence Container: deque Deque: double-ended queue Implemented as dynamic arrays –Elements can be inserted at both ends To use deque container in a program include statement: #include

Data Structures Using C++15 Ways to Declare a deq Object

Data Structures Using C++16 Operations that Can Be Performed on a deq Object

Data Structures Using C++17 Types of Iteration Input Iterators Output Iterators Forward Iterators Bidirectional Iterators Random Access Iterators

Data Structures Using C++18 Operations on an Input Iterator

Data Structures Using C++19 Operations on an Output Iterator

Data Structures Using C++20 Operations on a Forward Iterator

Data Structures Using C++21 Operations on a Bidirectional Iterator

Data Structures Using C++22 Operations on a Random Access Iterator

Data Structures Using C++23 Iterator Hierarchy

Data Structures Using C++24 typedefs Common to All Containers

Data Structures Using C++25 istream_iterator Used to input data into a program from an input stream General syntax: istream_iterator isIdentifier(istream&);

Data Structures Using C++26 ostream_iterator Contains the definition of an output stream iterator General syntax: ostream_iterator osIdentifier(ostream&); or ostream_iterator osIdentifier(ostream&, char* deLimit);

Data Structures Using C++27 Programming Example: Grade Report (Input) A sample input file follows: 345 Lisa Miller Y 4 Mathematics MTH345 4 A Physics PHY357 3 B ComputerSci CSC478 3 B History HIS356 3 A. InputA file containing the data in the form shown previously. Assume the name of the input file is ch4_GradeData.txt and is on floppy disk A.

Data Structures Using C++28 Programming Example: Grade Report (Output) The desired output for each student is of the following form: Student Name: Lisa Miller Student ID: Number of courses enrolled: 4 Course No Course Name Credits Grade CSC478 ComputerSci 3 B HIS356 History 3 A MTH345 Mathematics 4 A PHY357 Physics 3 B

Data Structures Using C++29 Programming Example: Grade Report Course Component –Set the course information –Print the course information –Show the credit hours –Show the course number –Show the grade

Data Structures Using C++30 UML Diagram of the class courseType

Data Structures Using C++31 Programming Example: Grade Report Student Component –Set the student information –Print the student information –Calculate the number of credit hours taken –Calculate the GPA –Calculate the billing amount –Because the grade report will print the courses in ascending order, sort the courses according to the course number

Data Structures Using C++32 UML Diagram of the class studentType and the Inheritance Hierarchy

Data Structures Using C++33 Programming Example: Grade Report (Main Algorithm) Declare the variables Open the input file If the input file does not exist, exit the program Open the output file Get the tuition rate Load the students’ data Print the grade reports

Data Structures Using C++34 Chapter Summary Components of the STL Types of Containers Operations on Containers Sequence Containers –Deque –Vector

Data Structures Using C++35 Chapter Summary Iterators Types of iteration Operations on iterators Programming example