Templates and the STL. Bryce Boe 2012/09/10 CS32, Summer 2012 B

Similar documents
CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

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

COEN244: Class & function templates

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

CE221 Programming in C++ Part 1 Introduction

CS11 Advanced C++ Fall Lecture 1

CS2102, B11 Exam 1. Name:

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Spring 2018

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

Programming Assignment 2

Container Notes. Di erent Kinds of Containers. Types Defined by Containers. C++11 Container Notes C++11

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

+ Abstract Data Types

CSE 100: C++ TEMPLATES AND ITERATORS

Absolute C++ Walter Savitch

Data Structures Review 1 Vectors... 1 Linked List... 2 Trees... 2 Heaps... 2 Hash tables... 2

(the bubble footer is automatically inserted in this space)

Computer Science II Data Structures

7 TEMPLATES AND STL. 7.1 Function Templates

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

CS2013 Course Syllabus Spring 2018 Lecture: Mon/Wed 2:00 P.M. 2:50 P.M. SH C259 Lab: Mon/Wed 2:50 P.M. 4:00 P.M. SH C259

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

COLLEGE OF DUPAGE CIS 2542 Advanced C++ with Data Structure Applications Course Syllabus

Week 8: Operator overloading

GO MOCK TEST GO MOCK TEST I

Containers and the Standard Template Library (STL)

COLLEGE OF THE DESERT

use static size for this buffer

TEMPLATES AND ITERATORS

CISC 3130 Data Structures Fall 2018

CS 4349 Lecture October 18th, 2017

Spare Matrix Formats, and The Standard Template Library

STL Quick Reference for CS 241

Problem Solving with C++

CSE 100: C++ TEMPLATES AND ITERATORS

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

CS 3410, Spring 2014 Computer Science Cornell University. See P&H Chapter: , 5.8, 5.15

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

Dynamic Data Structures

Practical C++ Programming

VE281 Data Structures and Algorithms. Introduction and Asymptotic Algorithm Analysis

Java Application Development

CS 241 Data Organization. August 21, 2018

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

CSE 12 Week Eight, Lecture One

Object Oriented Paradigm

Lecture 09X: C Func/on Pointers Concurrent and Mul/core Programming

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

Standard ADTs. Lecture 19 CS2110 Summer 2009

CS503 Advanced Programming I CS305 Computer Algorithms I

COMP322 - Introduction to C++ Lecture 01 - Introduction

CSE030 Fall 2012 Final Exam Friday, December 14, PM

ECE 468, Fall Midterm 2

1. The term STL stands for?

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s.

Lecture 17: Hash Tables, Maps, Finish Linked Lists

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

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:30-7:00

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

School of Computing & Information Technology. Department of Computer Science & Engineering LAB MANUAL CS-1331 DATA STRUCTURES LAB

JAVA MOCK TEST JAVA MOCK TEST II

Dynamic Memory: Alignment and Fragmentation

Operator overloading

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

Memory and C/C++ modules

Largest Online Community of VU Students

Winter 2018 March 12 th, 2018 CS106X Midterm Examination Solution

Beijing Jiaotong University CS-23: C++ Programming Summer, 2019 Course Syllabus

Compilation/linking revisited. Memory and C/C++ modules. Layout of C/C++ programs. A sample C program demo.c. A possible structure of demo.

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

(the bubble footer is automatically inserted in this space)

INSTRUCTIONS TO CANDIDATES

CSE 100: C++ TEMPLATES AND ITERATORS

Object Oriented Programming with c++ Question Bank

Reminder: compiling & linking

W3101: Programming Languages C++ Ramana Isukapalli

Question Paper Code : 97044

The type of all data used in a C++ program must be specified

During the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.

CSE 373 Spring Midterm. Friday April 21st

Programming Abstractions

Chapter 5. The Standard Template Library.

OOP- 5 Stacks Individual Assignment 35 Points

Data Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003

EE 109 Lab 8a Conversion Experience

G52CPP C++ Programming Lecture 18. Dr Jason Atkin

CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

CPSC 2380 Data Structures and Algorithms

Homework 3: Relational Database Design Theory (100 points)

Lecture 1: CSE 373. Data Structures and Algorithms

Computer Science II Lecture 2 Strings, Vectors and Recursion

Lecture 1b: Why C++?

CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

M.C.A DEGREE EXAMINATION,NOVEMBER/DECEMBER 2010 Second Semester MC 9222-OBJECT ORIENTED PROGRAMMING (Regulation 2009)

CS 202, Fall 2017 Homework #4 Balanced Search Trees and Hashing Due Date: December 18, 2017

Transcription:

Templates and the STL Bryce Boe 2012/09/10 CS32, Summer 2012 B

Overview Variable Types and Storage Review Templates STL Final InformaHon AlternaHve Final

Review

Where is all the data stored? int a1[5]; char *msg; int main { int blah[16]; string *tmp = new string( some message ); return 0; }

...0101 010000010100001001000011010001001100... What is? address 802340 address 802341 address 802342 address 802343 Could be four chars: A, B, C, D Or it could be two shorts: 16961, 17475 All numerical values shown here are for a "li]le endian" machine (more about endian next slide) Maybe it s a long or an int: 1145258561 It could be a floahng point number too: 781.035217 address 802340...0101010000010100001001000011010001001100... 802340 char* b ASCII code for 'A' address 802340...0101 010000010100001001000011010001001100... 802340 short* s address 802340 binary code for short 16916 (on a little endian machine)...010101000001010000100100001101000100 1100... 802340 int* p address 802340 binary code for int 1145258561 (on a little endian machine)...0101 01000001010000100100001101000100 1100... 802340 float* f binary code for float 781.035217 (on a little endian machine)

Templates Templates allow you to code by the DRY method (don t repeat yourself) Write a single funchon or class that can be used with many different types Implicitly a copy is made by the compiler for each type needed

FuncHon Templates template <class T> T add(const T &arg1, const T &arg2) { return arg1 + arg2; } add(1, 2); // integers add(1.5, 3.0); // floats or doubles add( hello, world); // strings

Class Templates template <class T1, class T2> class Pair { public: Pair(T1 a, T2 b): a(a), b(b) {} T1 a; T2 b; }; Pair<int, int> a(1, 2); Note the space Pair<string, string> b( hello, world); Pair<Pair<int, int>, Pair<string, string> > c(a, b);

Standard Template Library A set of abstract data types that are incredibly convenient to use Reference: h]p://www.cplusplus.com/reference/stl/ The STL will not be on the final

STL Sequence Containers vector A dynamic array that grows and shrinks in size as necessary deque Double ended queue that supports random access and efficient addihon or removal to either end of the deque list Doubly linked list implementahon

STL container adaptors Adapters require some other container to operate stack Implements the stack ADT (using deque by default) queue Implements the queue ADT (deque by default) priority_queue Implements a priority queue ADT (vector used by default)

AssociaHve Containers (mulh)set stores unique elements, mulhset allows for storing mulhple copies of the same element (mulh)map A key/value ADT (hash table), mulhmap allows for non- unique keys bitset Provides convenient means to single bit access (saves space)

C++ See Also Boost C++ Libraries h]p://www.boost.org /r/cpp on reddit h]p://www.reddit.com/r/cpp C++ tag on stackoverflow h]p://stackoverflow.com/queshons/tagged/c++

Final InformaHon On material following the midterm Friend funchons Operator overloading Inheritance (polymorphism) Programs in memory (segments) Variables in memory (padding, overflow, types) Templates There should be very few free- response type queshons (if any)

AlternaHve Final Full the same score you received on your midterm (adjusted), write a 2- page reflechon paper on CS32 Ideally will only take you ~3 hours (same Hme as review + final) ReflecHon paper references: h]p://goo.gl/df834

ReflecHon Paper Should be an assessment (not a summary) of what you ve learned in the class You want to answer how queshons, not what queshons. Example: How has what you learned in this class affected the way you approach solving problems Provide specific examples to jushfy your statements Fewer and more complete examples are be]er than mulhple fragmented ideas

ReflecHon Paper ConHnued You may also reflect on how my teaching had either a posihve or negahve impact on you Neutral impacts aren t worth wrihng about Don t bullshit (don t write about what you think I want to read, write about how you actually feel) Spend nearly as much Hme edihng as wrihng

ReflecHon Paper Grading Submission due via submission on CSIL by 13:55 on Wednesday (the same end- of- final Hme) If sahsfactory effort was made, you will get full credit (same score as midterm), otherwise you will be asked to revise. If shll not sahsfactory axer a single revision you will receive some frachon of your midterm score

Thanks!