Templates & the STL. CS 2308 :: Fall 2015 Molly O'Neil
|
|
- Denis Allison
- 6 years ago
- Views:
Transcription
1 Templates & the STL CS 2308 :: Fall 2015 Molly O'Neil
2 Function Templates Let's say we have a program that repeatedly needs to find the maximum value in an array In one place in our code, we need the max of an array of ints but in another place, it's an array of doubles and in a third place, it's an array of Time objects! We can declare three findmaximum() functions and duplicate a lot of code, or We can use a function template: a pattern for a function that can work with multiple data types Data types in the function are specified as parameters Compiler generates code for the function to match the specific data type(s) used where the function is called 2
3 Function Template Example template <class T> T findmaximum(t arr[], int size) { T max = arr[0]; // don't call this fn with size <= 0! for(int i = 1; i < size; i++) { if(max < arr[i]) max = arr[i]; return max; int main() { int intarr[10]; double doublearr[7]; Time timearr[5]; int imax = findmaximum(intarr, 10); double dmax = findmaximum(doublearr, 7); Time tmax = findmaximum(timearr, 5); 3
4 Function Template Example This function call int main() { int intarr[10]; int imax = findmaximum(intarr, 10); Causes the compiler to generate this function: int findmaximum(int arr[], int size) { int max = arr[0]; for(int i = 1; i < size; i++) { if(max < arr[i]) max = arr[i]; return max; 4
5 Function Template Example And this function call int main() { double doublearr[7]; double dmax = findmaximum(doublearr, 7); Causes the compiler to generate this function: double findmaximum(double arr[], int size) { double max = arr[0]; for(int i = 1; i < size; i++) { if(max < arr[i]) max = arr[i]; return max; 5
6 Function Template Example And this function call int main() { Time timearr[5]; Time tmax = findmaximum(timearr, 5); Causes the compiler to generate this function: Time findmaximum(time arr[], int size) { Time max = arr[0]; for(int i = 1; i < size; i++) { if(max < arr[i]) max = arr[i]; return max; Note that this only works because we have overloaded the < operator for the Time class! 6
7 More About Function Templates Function template is a pattern only; no actual code is generated until the function is called You can define a template to use multiple data types: template<class T1, class T2> Just like functions can be overloaded, function templates can be overloaded Must have unique parameter lists template <class T> T sumall(t num) template<class T1, class T2> T1 sumall(t1 num1, T2 num2) When passing a class object to a function template, be sure that all operators in the template are defined/ overloaded in the class definition! 7
8 Class Templates Classes can also be represented by templates A class template is a pattern for a class definition that parameterizes the type of class member variables Also called a templated class or a parameterized class An object of a templated class is a specialization When a class object is created, type information is supplied to define the type of the class member variables Object instantiation requires supplying the type name at object definition 8
9 Class Template Example For example, we can design a generic Linked List class as a templated class Rather than writing separate IntList, DoubleList, TimeList, SongList, etc. classes template <class T> class LinkedList { private: class Node { public: T data; Node *next; ; Node *head; public: LinkedList(); ~LinkedList(); void insert(t); void remove(t); void display(); 9
10 Using Class Templates Programmer passes the type information to the class template when an object of the class is instantiated: LinkedList<int> intlist; LinkedList<double> doublelist; LinkedList<Song> songlist; Once defined, the object can be treated as an ordinary object Song s1("hey Jude", "The Beatles", 2.5); songlist.insert(s1); 10
11 The Standard Template Library (STL) The Standard Template Library (STL) is a library containing templates for frequently used data structures and algorithms Not a part of C++ and unsupported by older compilers But standard in newer versions and commonly-used Two important types of data structures in the STL: Containers: classes that store data and impose some organization on it Iterators: mechanism for accessing elements in a container (somewhat like pointers) 11
12 STL Containers Sequence containers: organize and access data sequentially. E.g.: Vector An array that can dynamically change in size (by internal re-allocation). Good for insertion/removal at back; random access to elements Dequeue (pronounced "deck") A double-ended queue, usually (but not mandatorily) implemented as multiple dynamic arrays linked together internally. Good for insertion/ removal at front or back; random access to elements List A doubly-linked list. Good for insertion/removal at front or back; must iterate list for random access Associative containers: use keys to allow data elements to be quickly accessed (you'll learn more about these in Data Structures). E.g.: Set / Multiset Map / Multimap 12
13 STL Iterators A generalization of pointers, used to access elements of a container Five overlapping types: Forward (can be incremented, i.e. ++) Bidirectional (can also be decremented, i.e. ++ and --) Random-access (can access elements at arbitrary positions relative to the element they point to) Input (can be used in input operations with cin/istream objects) Output (can be used in output operations with cout/ostream objects) 13
14 STL Algorithms STL also contains algorithms implemented as function templates to perform operations on the STL containers Must #include <algorithm> Includes (among others): binary_search sort count find find_if for_each min_element max_element random_shuffle 14
Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)
Chapter 16: Exceptions, Templates, and the Standard Template Library (STL) 6.1 Exceptions Exceptions Indicate that something unexpected has occurred or been detected Allow program to deal with the problem
More informationExceptions, Templates, and the STL
Exceptions, Templates, and the STL CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 16 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/
More informationTEMPLATES AND ITERATORS
TEMPLATES AND ITERATORS Problem Solving with Computers-I https://ucsb-cs24-sp17.github.io/ 2 Announcements Checkpoint deadline for pa04 (aka lab05) is due today at 11:59pm Be sure to push your code to
More informationLecture 21 Standard Template Library. A simple, but very limited, view of STL is the generality that using template functions provides.
Lecture 21 Standard Template Library STL: At a C++ standards meeting in 1994, the committee voted to adopt a proposal by Alex Stepanov of Hewlett-Packard Laboratories to include, as part of the standard
More informationModularity. Modular program development. Language support for modularity. Step-wise refinement Interface, specification, and implementation
Modular program development Step-wise refinement Interface, specification, and implementation Language support for modularity Procedural abstraction Abstract data types Packages and modules Generic abstractions
More informationCS11 Advanced C++ Fall Lecture 1
CS11 Advanced C++ Fall 2006-2007 Lecture 1 Welcome! ~8 lectures Slides are posted on CS11 website http://www.cs.caltech.edu/courses/cs11 ~6 lab assignments More involved labs 2-3 week project at end CS
More informationThe Standard Template Library. An introduction
1 The Standard Template Library An introduction 2 Standard Template Library (STL) Objective: Reuse common code Common constructs: Generic containers and algorithms STL Part of the C++ Standard Library
More informationUnit 1: Preliminaries Part 4: Introduction to the Standard Template Library
Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library Engineering 4892: Data Structures Faculty of Engineering & Applied Science Memorial University of Newfoundland May 6, 2010 ENGI
More informationStructuur van Computerprogramma s 2
Structuur van Computerprogramma s 2 dr. Dirk Deridder Dirk.Deridder@vub.ac.be http://soft.vub.ac.be/ Vrije Universiteit Brussel - Faculty of Science and Bio-Engineering Sciences - Computer Science Department
More informationChapter 5. The Standard Template Library.
Object-oriented programming B, Lecture 11e. 1 Chapter 5. The Standard Template Library. 5.1. Overview of main STL components. The Standard Template Library (STL) has been developed by Alexander Stepanov,
More informationArrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors
Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8
More informationContainer Class and Integrators, Proxy Class EC6301-OOPS AND DATA STRUCTURES
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
More information1. The term STL stands for?
1. The term STL stands for? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d 2. Which of the following statements regarding the
More information7 TEMPLATES AND STL. 7.1 Function Templates
7 templates and STL:: Function Templates 7 TEMPLATES AND STL 7.1 Function Templates Support generic programming functions have parameterized types (can have other parameters as well) functions are instantiated
More informationSTL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms
STL: C++ Standard Library Standard Template Library (STL) Encapsulates complex data structures and algorithms is a library of generic container classes which are both efficient and functional C++ STL developed
More informationStandard Template Library
Standard Template Library The standard template library (STL) contains CONTAINERS ALGORITHMS ITERATORS A container is a way that stored data is organized in memory, for example an array of elements. Algorithms
More informationIntroduction to Computer Science Midterm 3 Fall, Points
Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do
More informationCS11 Introduction to C++ Spring Lecture 8
CS11 Introduction to C++ Spring 2013-2014 Lecture 8 Local Variables string getusername() { string user; } cout user; return user;! What happens to user when function
More informationDynamic Data Structures
Dynamic Data Structures We have seen that the STL containers vector, deque, list, set and map can grow and shrink dynamically. We now examine how some of these containers can be implemented in C++. To
More informationStandard Template Library. Containers, Iterators, Algorithms. Sequence Containers. Containers
Standard Template Library The standard template library (STL) contains Containers Algorithms Iterators A container is a way that stored data is organized in memory, for example an array of elements. Algorithms
More informationC++ - Lesson 2 This is a function prototype. a' is a function that takes an integer array argument and returns an integer pointer.
C++ - Lesson 2 1. Explain the following declarations: a) int *a(int a[]); This is a function prototype. 'a' is a function that takes an integer array argument and returns an integer pointer. b) const char
More informationSTL: C++ Standard Library
STL: C++ Standard Library Encapsulates complex data structures and algorithms CSC 330 OO Software Design 1 We ve emphasized the importance of software reuse. Recognizing that many data structures and algorithms
More informationCS197c: Programming in C++
CS197c: Programming in C++ Lecture 2 Marc Cartright http://ciir.cs.umass.edu/~irmarc/cs197c/index.html Administration HW1 will be up this afternoon Written assignment Due in class next week See website
More informationC++ is Fun Part 11 at Turbine/Warner Bros.! Russell Hanson
C++ is Fun Part 11 at Turbine/Warner Bros.! Russell Hanson Syllabus 1) First program and introduction to data types and control structures with applications for games learning how to use the programming
More informationLinked Lists. Gaddis Ch. 17. CS 2308 :: Spring 2016 Molly O'Neil
Linked Lists Gaddis Ch. 17 CS 2308 :: Spring 2016 Molly O'Neil List ADT A list is an abstract data type representing an ordered sequence of values For example, both MP3 Player assignments have used lists:
More information! An exception is a condition that occurs at execution time and makes normal continuation of the program impossible.
Exceptions! Exceptions are used to signal error or unexpected events that occur while a program is running.! An exception is a condition that occurs at execution time and makes normal continuation of the
More informationCOEN244: Class & function templates
COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library
More informationC++ Standard Template Library
C++ Standard Template Library CSE 333 Summer 2018 Instructor: Hal Perkins Teaching Assistants: Renshu Gu William Kim Soumya Vasisht C++ s Standard Library C++ s Standard Library consists of four major
More informationC and C++ Courses. C Language
C Language The "C" Language is currently one of the most widely used programming languages. Designed as a tool for creating operating systems (with its help the first Unix systems were constructed) it
More informationIS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class
IS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class Name: A. Fill in the blanks in each of the following statements [Score: 20]: 1. A base class s members can be accessed only
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 07: Linked Lists and Iterators MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Linked Lists 2 Introduction Linked List Abstract Data Type General Implementation of the ListADT
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. First Examination
University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section
More information2
STL Design CSC 330 2 3 4 5 Discussions Associative Containers 6 7 Basic Associative Containers 8 set class 9 map class 10 Example multiset (1) 11 Example multiset (2) 12 Example multiset (3) 13 Example
More information(8 1) Container Classes & Class Templates D & D Chapter 18. Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University
(8 1) Container Classes & Class Templates D & D Chapter 18 Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University Key Concepts Class and block scope Access and utility functions
More informationTopics. Modularity and Object-Oriented Programming. Dijkstra s Example (1969) Stepwise Refinement. Modular program development
Topics Modularity and Object-Oriented Programming 申 @ 케이유티 Modular program development Step-wise refinement Interface, specification, and implementation Language support for modularity Procedural abstraction
More informationCpt S 122 Data Structures. Templates
Cpt S 122 Data Structures Templates Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Function Template Function-template and function-template
More informationLecture-5. STL Containers & Iterators
Lecture-5 STL Containers & Iterators Containers as a form of Aggregation Fixed aggregation An object is composed of a fixed set of component objects Variable aggregation An object is composed of a variable
More informationCSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1
CSE 1 Complexity Analysis Program Efficiency [Sections 12.1-12., 12., 12.9] Count number of instructions executed by program on inputs of a given size Express run time as a function of the input size Assume
More informationQuestion Paper Code : 97044
Reg. No. : Question Paper Code : 97044 B.E./B.Tech. DEGREE EXAMINATION NOVEMBER/DECEMBER 2014 Third Semester Computer Science and Engineering CS 6301 PROGRAMMING AND DATA STRUCTURES-II (Regulation 2013)
More informationThe following is an excerpt from Scott Meyers new book, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs.
The following is an excerpt from Scott Meyers new book, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs. Item 47: Use traits classes for information about types. The
More information1 Short Answer (7 Points Each)
1 Short Answer (7 Points Each) 1. Given the following function, what operations will need to be overloaded in the class T for this code to compile? template T square(t n) { return n * n; } The
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationChapter 17: Linked Lists
Chapter 17: Linked Lists 17.1 Introduction to the Linked List ADT Introduction to the Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures list head
More informationSoftware Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example
Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example CS 311 Data Structures and Algorithms Lecture Slides Friday, September 11, 2009 continued Glenn G. Chappell
More informationAssignment 1: grid. Due November 20, 11:59 PM Introduction
CS106L Fall 2008 Handout #19 November 5, 2008 Assignment 1: grid Due November 20, 11:59 PM Introduction The STL container classes encompass a wide selection of associative and sequence containers. However,
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II
CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays Methods 3 A method: groups a sequence of statement takes input, performs actions, and
More informationContainers and the Standard Template Library (STL)
Containers and the Standard Template Library (STL) Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and
More informationTHE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming
THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming What the heck is STL???? Another hard to understand and lazy to implement stuff? Standard Template Library The standard template
More informationCS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC
CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented
More informationFirst Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19
Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2008 7p-9p, Tuesday, February 19 Name: NetID: Lab Section (Day/Time): This is a closed book and closed
More informationCS 247: Software Engineering Principles. C++ Templates. Reading: Eckel, Vol. 2 Ch. 5 Templates in Depth. U Waterloo CS247 (Spring 2017) p.
CS 247: Software Engineering Principles C++ Templates Reading: Eckel, Vol. 2 Ch. 5 Templates in Depth U Waterloo CS247 (Spring 2017) p.1/16 Overloaded Functions Problem: Code in overloaded functions whose
More informationArrays and functions Multidimensional arrays Sorting and algorithm efficiency
Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same
More informationVectors. CIS 15 : Spring 2007
Vectors CIS 15 : Spring 2007 Functionalia Midterm 2 : Ave. 58% (36.9 / 68) Med. 67% (45.5 / 68) Today: Standard Template Library Vector Template Standard Template Library C++ offers extended functionality
More informationHomework #3 CS2255 Fall 2012
Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation
More informationby Pearson Education, Inc. All Rights Reserved. 2
An important part of every container is the type of iterator it supports. This determines which algorithms can be applied to the container. A vector supports random-access iterators i.e., all iterator
More informationComputational Physics
Computational Physics numerical methods with C++ (and UNIX) 2018-19 Fernando Barao Instituto Superior Tecnico, Dep. Fisica email: fernando.barao@tecnico.ulisboa.pt Computational Physics 2018-19 (Phys Dep
More information2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17
CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays 1 Methods : Method Declaration: Header 3 A method declaration begins with a method header
More informationToday. andyoucanalsoconsultchapters6amd7inthetextbook. cis15-fall2007-parsons-lectvii.1 2
TEMPLATES Today This lecture looks at techniques for generic programming: Generic pointers Templates The standard template library Thebestreferenceis: http://www.cppreference.com/index.html andyoucanalsoconsultchapters6amd7inthetextbook.
More informationClass and Function Templates
Class and Function 1 Motivation for One Way to Look at... Example: Queue of some type Foo C++ What can a parameter be used for? Instantiating a Template Usage of Compiler view of templates... Implementing
More informationDELHI PUBLIC SCHOOL TAPI
Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed
More informationstatic CS106L Spring 2009 Handout #21 May 12, 2009 Introduction
CS106L Spring 2009 Handout #21 May 12, 2009 static Introduction Most of the time, you'll design classes so that any two instances of that class are independent. That is, if you have two objects one and
More informationMotivation for Templates. Class and Function Templates. One Way to Look at Templates...
Class and Function 1 Motivation for 2 Motivation for One Way to Look at... Example: Queue of some type Foo C++ What can a parameter be used for? Instantiating a Template Usage of Compiler view of templates...
More informationcs Java: lecture #6
cs3101-003 Java: lecture #6 news: homework #5 due today little quiz today it s the last class! please return any textbooks you borrowed from me today s topics: interfaces recursion data structures threads
More informationObject-Oriented Programming
s iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 21 Overview s 1 s 2 2 / 21 s s Generic programming - algorithms are written with generic types, that are going to be specified later. Generic programming
More informationLecture 4a Using The Standard Template Library. Jack Applin, Guest Lecturer
Lecture 4a Using The Standard Template Library Jack Applin, Guest Lecturer November 28 th, 2017 2017-12-04 CS253 Fall 2017 Bruce Draper 1 PA9 is online Announcements Efficiency assignment Same as PA8 But
More informationI BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++
No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)
More informationEECE.2160: ECE Application Programming
Fall 2017 Programming Assignment #10: Doubly-Linked Lists Due Monday, 12/18/17, 11:59:59 PM (Extra credit ( 5 pts on final average), no late submissions or resubmissions) 1. Introduction This assignment
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1
Review from Lecture 21 CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 the single most important data structure known to mankind Hash Tables, Hash Functions,
More informationClasses and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?
Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. First Examination
University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section
More informationFinancial computing with C++
Financial Computing with C++, Lecture 6 - p1/24 Financial computing with C++ LG Gyurkó University of Oxford Michaelmas Term 2015 Financial Computing with C++, Lecture 6 - p2/24 Outline Linked lists Linked
More informationFINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING
FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING Question No: 1 ( Marks: 1 ) - Please choose one Classes like TwoDimensionalShape and ThreeDimensionalShape would normally be concrete,
More informationArrays and Linked Lists
Arrays and Linked Lists Abstract Data Types Stacks Queues Priority Queues and Deques John Edgar 2 And Stacks Reverse Polish Notation (RPN) Also known as postfix notation A mathematical notation Where every
More informationTemplates and STL Vectors
Templates and STL Vectors Let s start with a singly-linked-list class of strings. The code to free the list from memory is missing. Here is the relevant code: class Node private: string name; Node* next;
More informationLife cycle of an object construction: creating a new object. Strings: constructors & assignment another type that C and C++ don't provide
Life cycle of an object construction: creating a new object implicitly, by entering the scope where it is declared explicitly, by calling new construction includes initialization copying: using existing
More informationExercise 6.2 A generic container class
Exercise 6.2 A generic container class The goal of this exercise is to write a class Array that mimics the behavior of a C++ array, but provides more intelligent memory management a) Start with the input
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #44 Multidimensional Array and pointers In this video, we will look at the relation between Multi-dimensional
More informationAn Introduction to C++
An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface
More information5 Phases of Software Life Cycle
Quiz One Answer Key 5 Phases of Software Life Cycle Lecture: 5/12 Question: #1 Waterfall Model Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, 2005 Pearson Education, Inc. All
More informationPrelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion
Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 07: Linked Lists MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Linked Lists 2 Introduction Linked List Abstract Data Type SinglyLinkedList ArrayList Keep in Mind Introduction:
More informationProgramming in C++: Assignment Week 1
Programming in C++: Assignment Week 1 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com February 24,
More informationarrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V.
topics: arrays pointers arrays of objects resources: cis15 advanced programming techniques, using c++ summer 2008 lecture # V.1 some of this lecture is covered in parts of Pohl, chapter 3 arrays review
More informationContainer Notes. Di erent Kinds of Containers. Types Defined by Containers. C++11 Container Notes C++11
Di erent Kinds of Containers Container Notes A container is an object that stores other objects and has methods for accessing the elements. There are two fundamentally di erent kinds of containers: Sequences
More informationCS
CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and
More informationList, Stack, and Queues
List, Stack, and Queues R. J. Renka Department of Computer Science & Engineering University of North Texas 02/24/2010 3.1 Abstract Data Type An Abstract Data Type (ADT) is a set of objects with a set of
More information4.1 Ordered Lists Revisited
Chapter 4 Linked-lists 4.1 Ordered Lists Revisited Let us revisit our ordered-list. Let us assume that we use it for storing roll numbers of students in a class in ascending order. We can make the assumption
More informationCOP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008
COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 Lab topic: 1) Take Quiz 4 2) Discussion on Assignment 2 Discussion on Assignment 2. Your task is to
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationCS 162, Lecture 25: Exam II Review. 30 May 2018
CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you
More information(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University
(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming
More informationJava classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.
CSM 61B Abstract Classes & Interfaces Spring 2017 Week 5: February 13, 2017 1 An Appealing Appetizer 1.1 public interface Consumable { public void consume (); public abstract class Food implements Consumable
More informationInsertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue
Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,
More informationIBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?
IBS Software Services Technical Interview Questions Q1. What is the difference between declaration and definition? The declaration tells the compiler that at some later point we plan to present the definition
More informationCS 32. Lecture 5: Templates
CS 32 Lecture 5: Templates Vectors Sort of like what you remember from Physics but sort of not Can have many components Usually called entries Like Python lists Array vs. Vector What s the difference?
More informationLinear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013
Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every
More informationC# Adds Useful Features
C# Adds Useful Features Events and delegates are included to handle asynchronous actions (like keyboard or mouse actions). Properties allow user-defined read and write actions for fields. You can add get
More informationCPSC 427a: Object-Oriented Programming
CPSC 427a: Object-Oriented Programming Michael J. Fischer Lecture 17 November 1, 2011 CPSC 427a, Lecture 17 1/21 CPSC 427a, Lecture 17 2/21 CPSC 427a, Lecture 17 3/21 A bit of history C++ standardization.
More informationCpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University
Cpt S 122 Data Structures Course Review FINAL Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Final When: Wednesday (12/12) 1:00 pm -3:00 pm Where: In Class
More information