C Standard. l C++ For C Programmers :2 nd half. l C++11 feature of the day. l STL. C++ for C Programmers by Ira Pohl

Size: px
Start display at page:

Download "C Standard. l C++ For C Programmers :2 nd half. l C++11 feature of the day. l STL. C++ for C Programmers by Ira Pohl"

Transcription

1 C Standard C++ For C Programmers :2 nd half C++11 feature of the day STL

2 Part I You have completed Part I, and: Know basic C++ Have coded both Min Spanning Tree and Dijkstra s algorithm Followed in my book if available Ch1-6

3 Part II More Standard Template Library New features of C++11, such as move semantics, and lambda expressions AI techniques used in implementing the game of Hex Highlight

4 New in C++11 std Let us introduce new practice and see how it replaces existing practice enum class is a type safe better form of enumeration type

5 Example :enum class enum class Color{RED, GREEN, BLUE}; enum class Stoplight{RED, YELLOW, GREEN}; With simple enums these shared enumerators would be ambiguous In C++11 they constitute separate type Stoplight::RED is different in type from Color::RED; both can be used in the same scope

6 enum class enumerator type The underlying type of enum classes is by default an int; this can be specified to be a different integral type. enum class Color : short {RED, BLUE, GREEN}; enum class Identifier : Integral_Type{ enumerator list};

7 Quiz: Define an enumerator Define a enum class that models three logical values yes, no, maybe- whose underlying type is unsigned and where yes>maybe>no --- also yes worth 2 maybe s

8 Answer enum class WierdLogic :unsigned{ NO, MAYBE = 5, YES = 10 }; // a yes is worth 2 maybe s

9 Standard Template Library Three Legged Stool Containers: Sequence containers vector, deques, list Associative containers set,map Iterators: input random Algorithms: Non-mutating sequence algorithms : Find, Count Mutating Sequence: Copy Random Shuffle, Sorting-Related:sort, Merge Numeric: accumulate, inner product

10 Some New Libraries C++11 <regex> - regular expression <thread> - threading <unordered_map> -hash based map <array> - fixed size array <forward_list> - singly linked list And much more

11 Quiz: In C A C container is? A C iterator is? A C algorithm is? Generics can be done clumsily with?

12 Answers: In C A C container is an array such as int d[100] A C iterator is a pointer int* p = d; A C algorithm is? rand(), sqrt() Generics can be done clumsily with void*

13 Iterator Categories We have seen input and output iterators Must have a single pass algorithm such as find Next up forward, bidirectional, random access

14 Forward

15 Iterator-Escher Staircase

16 C++ Forward Iterator Search forward direction one-by-one. The operator ++ is defined ("advance the iterator") and dereferencing operators * and ->. Iterators may be compared for equality == and!= and may be constructed and copy constructed. A canonical algorithm using this iterator is the STL replace algorithm:

17 replace template<class T> void replace(forwarditerator first, ForwardIterator last, const T& x, const T& y); This algorithm replaces occurences of x by y in the specified iterator range.

18 Square using iterator #include<iostream> #include<iterator> #include<fstream> #include<vector> using namespace std; template<typename ForwardIterator> void square(forwarditerator first, ForwardIterator last) { for(; first!=last; first++) } *first = (*first) * (*first);

19 main int main() {. square(w.begin(), w.end()); } for(auto i: w) // range for cout << i << "\t"; cout << endl;

20 Example: Poker Probability Wish to compute the probability in 5 card stud of making a straight flush Will create abstract data types to have card Will use vector and shuffle from STL

21 Wow A Straight Flush

22 Quiz: Poker probabilities for 5 card stud Flush is approximately A) 1/10, B)1/500, C) 1/10,000 Straight Flush is approximately A) 1/700, B)1/7000, C)1/70,000

23 Some types enum class: short suit{spade, HEART, DIAMOND, CLUB}; class pips{ public: pips(int val):v(val){ assert(v>0 && v <14);} friend ostream& operator<<(ostream& out, pips p); int get_pips(){return v;} private: int v; };

24 Card type { class card public: card():s(suit::spade),v(1){} card(suit s, pips v):s(s),v(v){} friend ostream& operator<<(ostream& out, card c ); suit get_suit(){return s;} pips get_pips(){return v;} private: suit s; pips v; }; ostream& operator<<(ostream& out, card c ){ cout << c.v << c.s; //presumes << overloaded for pips and suit return out; }

25 Deck vector of cards void init_deck(vector <card> & d){ for(int i = 1; i < 14; ++i){ card c(suit::spade, i); d[i-1] = c; } for(int i = 1; i < 14; ++i){ card c( suit:: HEART, i); d[i+12] = c; } for(int i = 1; i < 14; ++i){ card c(suit:: DIAMOND, i); d[i+25] = c; } for(int i = 1; i < 14; ++i){ card c(suit:: CLUB, i); d[i+38] = c; } }

26 C11 auto feature { } { } void print (vector <card> & deck) for(auto p = deck.begin(); p!= deck.end(); ++p) cout << *p; cout << endl; bool is_flush(vector < card > & hand) suit s = hand[0].get_suit(); for(auto p = hand.begin() + 1; p!= hand.end(); ++p) if (s!= p -> get_suit()) return false; return true;

27 Quiz Change print() to use range for() statement

28 Answer: void print (vector <card> & deck) { } for(auto cardval:deck) cout << cardval; cout << endl;

29 straight bool is_straight(vector < card > & hand){ int pips_v[5], i = 0; for(auto p = hand.begin(); p!= hand.end(); ++p) pips_v[i++] = (p -> get_pips()).get_pips(); sort(pips_v, pips_v +5); //stl iterator range if (pips_v[0]!= 1) //non-aces return ( pips_v[0] == pips_v[1] -1 && pips_v[1] == pips_v[2] -1 ) && ( pips_v[2] == pips_v[3] -1 && pips_v[3] == pips_v[4] -1 ); else //aces have a special logic return ( pips_v[0] == pips_v[1] -1 && pips_v[1] == pips_v[2] -1 ) && ( pips_v[2] == pips_v[3] -1 && pips_v[3] == pips_v[4] -1 ) (pips_v[1] == 10)&&(pips_v[2] == 11)&&(pips_v[3] ==12)&& (pips_v[4] == 13); }

30 So straight flush is easy bool is_straight_flush(vector < card > & hand) { } return is_flush(hand) && is_straight(hand);

31 Set up simulation { int main() vector < card > deck(52); srand(time(0)); init_deck(deck); int how_many ; int flush_count = 0; int str_count = 0; int str_flush_count = 0; cout << " How Many shuffles?"; cin >> how_many;

32 STL use to run simulation for(int loop = 0; loop < how_many; ++loop){ random_shuffle(deck.begin(), deck.end()); //STL algorithm vector <card> hand(5); int i = 0; for( auto p = deck.begin(); i < 5; ++p) hand[i++] = *p; if (is_flush(hand)) flush_count++; if (is_straight(hand)) str_count++; if (is_straight_flush(hand)) str_flush_count++ ; } cout << " Flushes " << flush_count << " out of " << how_many << endl; cout << " Straights " << str_count << " out of " << how_many<< endl; cout << " Straight Flushes " << str_flush_count << " out of " << how_many << endl;

33 Quiz at home Write is_4of_akind() Write is_straight_flush() for 7 card stud or 5 card draw.

34 Bidirectional Iterator The bidirectional iterator must allow the elements to be searched in both a forward direction and backward direction. This requires the operation on a forward iterator ++ operator -- ("back up the iterator").

35 reverse A canonical algorithm using this iterator is the STL reverse() algorithm: template<typename T> void reverse(bidirectionaliterator first, BidirectionalIterator last); This algorithm reverses the elements in the specified iterator range.

36 How would you write reverse

37 Move both ends Front++ Back So swap and move would lead to reverse

38 Palindrome

39 Palindrome Otto Dalmatian

40 Palindrome Otto otto Dalmatian

41 Palindrome Otto otto Dalmatian Na it am lad

42 ispalindrome template<typename Bidirectional> bool ispalindrome(bidirectional first, Bidirectional last) { while( true ){ } last--; if(first == last) //assume >= undefined break; if(*first!= *last) return false; first++; if(first == last) break; } return true;

43 How it works The algorithm moves forward and backward testing each position for equality. It checks if a value is not equal and returns false. If all values test as equal then the iterators "meet in the middle" (or pass each other) and it returns true. Compare to how you would do this with a forward only iterator - becomes n*n

44 Random access Iterator The random access iterator must allow the elements to be randomly searched in fixed time. Think indexed array. This requires effectively being able to add or subtract to an iterator value and retrieve a value from the computed position. It also means that iterator values can be compared for less and greater than as well as equality operators.

45 Sort() -hoare quicksort A canonical algorithm using this iterator is the STL sort() algorithm: template<class T> void sort(randomaccessiterator first, RandomAccessIterator last);

46 Pick an element at random template< typename RandomAccess> RandomAccess pickrandel( RandomAccess first, RandomAccess last) { ptrdiff_t temp = last-first; return first + rand()%temp; }

47 ptrdiff_t #include<cstddef> //ptrdiff_t ptrdiff_t. type. <cstddef>. Result of pointer subtraction. This is the type returned by the subtraction operation between two pointers. This is a signed integral type.

48 use cout << *pickrandel(w.begin(),w.end());

49 Standard Template Library Standard template library accepted in July 1994 into C++ ANSI Standard STL library provides containers, iterators and algorithms designed to work efficiently work parametrically work orthogonally

50 Two Varieties of Containers Sequence - ordered by sequence of elements Associative - keys for looking up elements deque! list! vector! set! multiset! map! multimap!

51 Typical Container Interfaces Constructors default constructors, copy constructors Element access Element insertion Element emplacement -new C++11(&&) Element deletion Destructor Iterators

52 Overview of Containers Common set of properties Constructors and destructors Element access, insertion and deletion Allocate and manage memory Associated allocator objects

53 Associative Containers Key based accessible elements set! multiset! map! multimap! Ordering relation Compare Comparison object for the associative container

54 Unordered_map C++11 introduces hash based lookup for map and set unordered_map -uses hash lookup unordered_set - uses hash lookup Advantage much of the time O(1) lookup

55 MAP Program #include <map> #include <unordered_map> #include <string> #include <iostream> using namespace std; //we will use both types of map

56 MAP Program { int main() map<unsigned long, string> worker; unordered_map<unsigned long, unsigned> payroll; unsigned total_pay =0; worker[ ] = "Harold Fish"; payroll[ ] = 67300; worker[ ] = "Phillip Fish"; payroll[ ] = 87300;

57 MAP Worker links id number to name Payroll links id number to salary Ordinary map red-black tree Unordered map hash

58 MAP for(auto p = worker.begin(); p!= worker.end(); ++p) cout << "name " << (*p).second << "\t id no. " << (*p).first << endl; //associate (first, second) // (id no, name)

59 MAP for(auto p = payroll.begin(); p!= payroll.end(); ++p) total_pay += (*p).second; cout << "payroll totals $"<< total_pay << endl;

60 STL Algorithms Library Sorting algorithms Non-mutating sequence algorithms Mutating sequence algorithms Numerical algorithms Generally use iterators to access containers instantiated on given type Resulting code can be competitive in efficiency with special purpose codes

61 Sorting Algorithm Prototypes template<class RandAcc> void sort(randacc b, RandAcc e); Quicksort algorithm over elements b to e template<class RandAcc> void stable_sort(randacc b, RandAcc e); Stable sorting algorithm over elements b to e Elements remain in their relative same position

62 Non-Mutating Sequence Algorithms Do not modify contents of the containers they work on Typical operation is searching container for particular element and returning its position

63 Non-mutating Algorithm template<class InputIter, Class T> InputIter find(inputiter b, InputIter e, const T& t)); Finds position of t in range b to e template<class InputIter, Class Predicate> InputIter find(inputiter b, InputIter e, Predicate p)); Finds position of first element that makes predicate true in range b to e, otherwise position e returned

64 Non-mutating Algorithm Prototypes (2 of 2) template<class InputIter, Class Function> void for_each(inputiter b, InputIter e, Function f)); Apply f to each value found in range b to e

65 Example: Algorithm find() int main() // find pos of "hop" { string words[5] = { "my", "hop", "mop", "hope", "cope"}; string* where; } where = find(words, words + 5, "hop"); cout << *++where << endl; //mop sort(words, words + 5); where = find(words, words + 5, "hop"); cout << *++where << endl; //hope

66 Lambda Expressions; for_each Expression Derived from Lisp Previously for_each needs a function Will use new C++11 idea write an unnamed function in place a lambda expression

67 Old style for_each() #include <algorithm> #include <vector> #include <iostream> using namespace std; void incr(int &i){static int n = 1; i = n++;} void outvec(int i){cout <<i << endl;} { int main() vector <int> v(6); for_each(v.begin(), v.end(), incr ); for_each(v.begin(), v.end(), outvec ); }

68 What got printed? vector <int> v(6); for_each(v.begin(), v.end(), incr ); for_each(v.begin(), v.end(), outvec ); }

69 Answer Static keeps value on exit, so

70 Lambda C++11 Taken from LISP Unnamed function [](int i){cout <<i << endl;} //goes where the function object is required

71 returns Lambda C++11 [] (int n) { return n * 5.5; }//double // deduces the return value no return void [] (int n) -> int { return ++n; } //explicit Read wikipedia about Lambda

72 Mutating Function template<class InputIter, class OutputIter> OutputIter copy(inputiter b1, InputIter e1, OutputIter b2); Copying algorithm over elements b1 to e1 Copy is placed starting at b2 Position returned is end of copy

73 Suggested work Write a small program with vectors that tests using copy()

74 Numerical Algorithms Sums Inner product Adjacent difference Numerical Algorithm functions behave as expected on numerical types where + and * are defined

75 Numerical Algorithm Program int main() { double v1[3] = { 1.0, 2.5, 4.6 }, v2[3] = { 1.0, 2.0, -3.5 }; double sum, inner_p; } sum = accumulate(v1, v1 + 3, 0.0); inner_p = inner_product(v1, v1 + 3, v2, 0.0); cout << "sum = " << sum << ", product = " << inner_p << endl;

76 Numerical Algorithm Prototypes (1 of 2) template<class InputIter, class T> T accumulate(inputiter b, InputIter e, T t); Standard accumulation algorithm whose sum is initially t Successive elements from the range b to e are added to sum

77 Numerical Algorithm Prototypes (2 of 2) template<class InputIter, class T, class BinOp> T accumulate(inputiter b, InputIter e, T t, BinOp bop); Accumulation whose sum is initially t Successive elements from range b to e are summed with sum = bop(sum, element)

78 Function Objects Useful to have function objects to further leverage STL library Numerical functions have built-in meaning using + or *, as well as user-provided binary operators which could be passed in Defined function objects can be found in function.h or built Function objects are classes that have operator() defined Inlined, compiled producing efficient object code"

79 Function Object for minus<int> int main() { double v1[3] = {1.0, 2.5, 4.6}, sum; sum = accumulate(v1, v1 + 3, 0.0, minus<int>()); cout << "sum = " << sum << endl; //sum = -7 } Accumulation using integer minus for binary operation over the array v1[]

80 Generator Object and Integration // The function is represented in class gen class gen { // generator for integrated function public: gen(double x_zero, double increment) : x(x_zero), incr(increment) { } double operator()() { x += incr; return x * x; } }; private: double x, incr;

81 integrate double integrate(gen g, int n) // integrate on (0,1) { vector<double> fx(n); } generate(fx.begin(), fx.end(), g); return (accumulate(fx.begin(), fx.end(), 0.0) / n);

82 End of code int main() { const int n = 10000; } gen g(0.0, 1.0/n); cout << "integration program x**2" << endl; cout << integrate(g, n) << endl;

83 Defined Function Object Classes Arithmetic objects Comparison objects Logical objects

84 Arithmetic Objects (1 of 2) template <class T> struct plus<t> Adds two operands of type T template <class T> struct minus<t> Subtracts two operands of type T template <class T> struct times<t> Multiplies two operands of type T

85 Arithmetic Objects (2 of 2) template <class T> struct divides<t> Divides two operands of type T template <class T> struct modulus<t> Modulus (%) for two operands of type T template <class T> struct negate<t> Unary minus for one argument of type T

86 Function Adapters Creation of function objects using adaption Negators for negating predicate objects Binders for binding a function argument Adapters for pointer to function

87 Use of Function Adapter bind2nd (1 of 2) template <class ForwIter> void print(forwiter first, ForwIter last, { } const char* title) cout << title << endl; while( first!= last) cout << *first++ << '\t'; cout << endl;

88 Use of Function Adapter bind2nd (2 of 2) // use a binder function bind2nd to transform initial sequence of // values to these values doubled int main() { int data[3] = { 9, 10, 11}; } print(data, data + 3, "Original values"); transform(data, data + 3, data, bind2nd(times<int>(), 2)); print(data, data + 3, "New values");

89 STL Based on Templates Key to understanding STL is to use iterator logic When extending STL keep consistent with existing libraries Generality and genericity are not enough: It s not STL if it isn t efficient

90 Next Time: How to play Tic-Tac-Toe The game of Hex term assignment

Module 4. l Graph Algorithms-MST. l HW3. l OO class point. C++ for C Programmers by Ira Pohl

Module 4. l Graph Algorithms-MST. l HW3. l OO class point. C++ for C Programmers by Ira Pohl Module 4 Graph Algorithms-MST HW3 OO class point Homework Week 3 Already built a graph (Abstract Data Type) Used Dijkstra algorithm to generate graph based on density and size Computed average length Minimum

More information

COEN244: Class & function templates

COEN244: 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 information

When we program, we have to deal with errors. Our most basic aim is correctness, but we must

When we program, we have to deal with errors. Our most basic aim is correctness, but we must Chapter 5 Errors When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications, incomplete programs, and our own errors. When

More information

Review Questions for Final Exam

Review Questions for Final Exam CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.

More information

Short Notes of CS201

Short 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 information

CS201 - Introduction to Programming Glossary By

CS201 - 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 information

Chapter 5. The Standard Template Library.

Chapter 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 information

To use various types of iterators with the STL algorithms ( ). To use Boolean functions to specify criteria for STL algorithms ( 23.8).

To use various types of iterators with the STL algorithms ( ). To use Boolean functions to specify criteria for STL algorithms ( 23.8). CHAPTER 23 STL Algorithms Objectives To use various types of iterators with the STL algorithms ( 23.1 23.20). To discover the four types of STL algorithms: nonmodifying algorithms, modifying algorithms,

More information

Review Questions for Final Exam KEY

Review Questions for Final Exam KEY CS 102 / ECE 206 Spring 11 Review Questions for Final Exam KEY The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR,

More information

STL Quick Reference for CS 241

STL Quick Reference for CS 241 STL Quick Reference for CS 241 Spring 2018 The purpose of this document is to provide basic information on those elements of the C++14 standard library we think are most likely to be needed in CS 241.

More information

CSE 100: C++ TEMPLATES AND ITERATORS

CSE 100: C++ TEMPLATES AND ITERATORS CSE 100: C++ TEMPLATES AND ITERATORS Announcements Gradesource and clickers: We ll be making one more pass for unregistered clickers tonight, but after that you ll be on your own How is Assignment 1 going?

More information

IS0020 Program Design and Software Tools Midterm, Fall, 2004

IS0020 Program Design and Software Tools Midterm, Fall, 2004 IS0020 Program Design and Software Tools Midterm, Fall, 2004 Name: Instruction There are two parts in this test. The first part contains 22 questions worth 40 points you need to get 20 right to get the

More information

Templates and Vectors

Templates and Vectors Templates and Vectors 1 Generic Programming function templates class templates 2 the STL vector class a vector of strings enumerating elements with an iterator inserting and erasing 3 Writing our own vector

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Homework 3. Due: Feb 25, 23:59pm. Section 1 (20 pts, 2 pts each) Multiple Choice Questions

Homework 3. Due: Feb 25, 23:59pm. Section 1 (20 pts, 2 pts each) Multiple Choice Questions Homework 3 Due: Feb 25, 23:59pm Section 1 (20 pts, 2 pts each) Multiple Choice Questions Q1: A function that modifies an array by using pointer arithmetic such as ++ptr to process every value of the array

More information

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented

More information

B-Trees. nodes with many children a type node a class for B-trees. an elaborate example the insertion algorithm removing elements

B-Trees. nodes with many children a type node a class for B-trees. an elaborate example the insertion algorithm removing elements B-Trees 1 B-Trees nodes with many children a type node a class for B-trees 2 manipulating a B-tree an elaborate example the insertion algorithm removing elements MCS 360 Lecture 35 Introduction to Data

More information

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words. , ean, arithmetic s s on acters Comp Sci 1570 Introduction to C++ Outline s s on acters 1 2 3 4 s s on acters Outline s s on acters 1 2 3 4 s s on acters ASCII s s on acters ASCII s s on acters Type: acter

More information

SFU CMPT Topic: Function Objects

SFU CMPT Topic: Function Objects SFU CMPT-212 2008-1 1 Topic: Function Objects SFU CMPT-212 2008-1 Topic: Function Objects Ján Maňuch E-mail: jmanuch@sfu.ca Friday 14 th March, 2008 SFU CMPT-212 2008-1 2 Topic: Function Objects Function

More information

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

CS

CS 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 information

CSE 100: C++ TEMPLATES AND ITERATORS

CSE 100: C++ TEMPLATES AND ITERATORS 1 CSE 100: C++ TEMPLATES AND ITERATORS 2 Announcements Look out for the extra weekend section More on git and C++ (iterators) Live demo by your friendly tutors Not mandatory but it will be fun Bring your

More information

Exceptions, Templates, and the STL

Exceptions, 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 information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

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

CSE100. Advanced Data Structures. Lecture 4. (Based on Paul Kube course materials) CSE100 Advanced Data Structures Lecture 4 (Based on Paul Kube course materials) Lecture 4 Binary search trees Toward a binary search tree implementation using C++ templates Reading: Weiss Ch 4, sections

More information

CSE 100: C++ TEMPLATES AND ITERATORS

CSE 100: C++ TEMPLATES AND ITERATORS CSE 100: C++ TEMPLATES AND ITERATORS Announcements iclickers: Please register at ted.ucsd.edu. Start ASAP!! For PA1 (Due next week). 10/6 grading and 10/8 regrading How is Assignment 1 going? A. I haven

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Programación de Computadores. Cesar Julio Bustacara M. Departamento de Ingeniería de Sistemas Facultad de Ingeniería Pontificia Universidad Javeriana

Programación de Computadores. Cesar Julio Bustacara M. Departamento de Ingeniería de Sistemas Facultad de Ingeniería Pontificia Universidad Javeriana POINTERS Programación de Computadores Cesar Julio Bustacara M. Departamento de Ingeniería de Sistemas Facultad de Ingeniería Pontificia Universidad Javeriana 2018-01 Pointers A pointer is a reference to

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

//main.cpp. using namespace std;

//main.cpp. using namespace std; Eric Villanueva CSE 330 Homework 1 (40/40) I d give myself a full 40 out of 40 points. I put a lot of effort into getting my code to work, I also used my own code for most of it. Question 1) #include

More information

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CSE030 Fall 2012 Final Exam Friday, December 14, PM CSE030 Fall 2012 Final Exam Friday, December 14, 2012 3-6PM Write your name here and at the top of each page! Name: Select your lab session: Tuesdays Thursdays Paper. If you have any questions or need

More information

Topics. bool and string types input/output library functions comments memory allocation templates classes

Topics. bool and string types input/output library functions comments memory allocation templates classes C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

Module Operator Overloading and Type Conversion. Table of Contents

Module Operator Overloading and Type Conversion. Table of Contents 1 Module - 33 Operator Overloading and Type Conversion Table of Contents 1. Introduction 2. Operator Overloading 3. this pointer 4. Overloading Unary Operators 5. Overloading Binary Operators 6. Overloading

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

PIC 10A. Final Review: Part I

PIC 10A. Final Review: Part I PIC 10A Final Review: Part I Final exam The final exam is worth 30% of your grade, same weight as 2 midterms. Could be 50% if grading option 2 turns out better for you. Length is also roughly 2 midterms

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14. Lecture 14 1 Exceptions Iterators Random numbers Casting Enumerations Pairs The Big Three Outline 2 Error Handling It is often easier to write a program by first assuming that nothing incorrect will happen

More information

use static size for this buffer

use static size for this buffer Software Design (C++) 4. Templates and standard library (STL) Juha Vihavainen University of Helsinki Overview Introduction to templates (generics) std::vector again templates: specialization by code generation

More information

Today. andyoucanalsoconsultchapters6amd7inthetextbook. cis15-fall2007-parsons-lectvii.1 2

Today. 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 information

COMP322 - Introduction to C++ Lecture 01 - Introduction

COMP322 - Introduction to C++ Lecture 01 - Introduction COMP322 - Introduction to C++ Lecture 01 - Introduction Robert D. Vincent School of Computer Science 6 January 2010 What this course is Crash course in C++ Only 14 lectures Single-credit course What this

More information

Object oriented programming

Object oriented programming Exercises 12 Version 1.0, 9 May, 2017 Table of Contents 1. Virtual destructor and example problems...................................... 1 1.1. Virtual destructor.......................................................

More information

CPSC 427a: Object-Oriented Programming

CPSC 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 information

pointers & references

pointers & references pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using

More information

1. The term STL stands for?

1. 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 information

Introduction to Programming

Introduction to Programming Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

More information

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

Unit 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 information

MODULE 35 --THE STL-- ALGORITHM PART III

MODULE 35 --THE STL-- ALGORITHM PART III MODULE 35 --THE STL-- ALGORITHM PART III My Training Period: hours Note: Compiled using Microsoft Visual C++.Net, win32 empty console mode application. g++ compilation example is given at the end of this

More information

C++ Standard Template Library

C++ 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 information

19.1 The Standard Template Library

19.1 The Standard Template Library Chapter 19: The Template Library From a review of Effective STL : 50 Specific Ways to Improve Your Use of the Standard Template Library by ScottMeyers: It s hard to overestimate the importance of the Standard

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

Introduction to Programming using C++

Introduction to Programming using C++ Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know

More information

The Standard Template Library. An introduction

The 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 information

C++ Modern and Lucid C++ for Professional Programmers

C++ Modern and Lucid C++ for Professional Programmers Informatik C++ Modern and Lucid C++ for Professional Programmers part 9 Prof. Peter Sommerlad Institutsleiter IFS Institute for Software Rapperswil, HS 2015 Functors and Parameterizing STL Functors, Lambdas,

More information

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

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,

More information

PIC 10A. Final Review

PIC 10A. Final Review PIC 10A Final Review Final exam Thursday, December 18, 2014 8:00 AM - 11:00 AM MS 5200. In our usual class room. (Verify on my.ucla.edu!!) The final exam is worth 30% of your grade, same weight as 2 midterms.

More information

C++ for numerical computing - part 2

C++ for numerical computing - part 2 C++ for numerical computing - part 2 Rupert Nash r.nash@epcc.ed.ac.uk 1 / 36 Recap 2 / 36 Iterators std::vector data = GetData(n); // C style iteration - fully explicit for (auto i=0; i!= n; ++i)

More information

Programming in C++ using STL. Rex Jaeschke

Programming in C++ using STL. Rex Jaeschke Programming in C++ using STL Rex Jaeschke Programming in C++ using STL 1997, 1999, 2002, 2007, 2009 Rex Jaeschke. All rights reserved. Edition: 2.0 All rights reserved. No part of this publication may

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

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.

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. 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. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

More information

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured Introduction p. xxix The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured Language p. 6 C Is a Programmer's Language

More information

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit. C++ Basics January 19, 2012 Brian A. Malloy Slide 1 of 24 1. Many find Deitel quintessentially readable; most find Stroustrup inscrutable and overbearing: Slide 2 of 24 1.1. Meyers Texts Two excellent

More information

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

Container 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 information

Roxana Dumitrescu. C++ in Financial Mathematics

Roxana Dumitrescu. C++ in Financial Mathematics Roxana Dumitrescu C++ in Financial Mathematics What have we learnt? Arrays; relation between arrays and pointers.. Returning arrays from functions Passing arrays to functions Intoduction to classes Plan

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

G52CPP C++ Programming Lecture 18

G52CPP C++ Programming Lecture 18 G52CPP C++ Programming Lecture 18 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Welcome Back 2 Last lecture Operator Overloading Strings and streams 3 Operator overloading - what to know

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

CS201 Some Important Definitions

CS201 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 information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1 300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard

More information

CS11 Advanced C++ Fall Lecture 1

CS11 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 information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I 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 information

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them. 1. Why do you think C++ was not named ++C? C++ is a super set of language C. All the basic features of C are used in C++ in their original form C++ can be described as C+ some additional features. Therefore,

More information

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... CISC 2000 Computer Science II Fall, 2014 Note 12/1/2014 1 Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... (a) What s the purpose of inheritance?

More information

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

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

A <Basic> C++ Course

A <Basic> C++ Course A C++ Course 5 Constructors / destructors operator overloading Julien Deantoni adapted from Jean-Paul Rigault courses This Week A little reminder Constructor / destructor Operator overloading Programmation

More information

Outline. 1 About the course

Outline. 1 About the course Outline EDAF50 C++ Programming 1. Introduction 1 About the course Sven Gestegård Robertz Computer Science, LTH 2018 2 Presentation of C++ History Introduction Data types and variables 1. Introduction 2/1

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

A <Basic> C++ Course

A <Basic> C++ Course A C++ Course 5 Constructors / destructors operator overloading Julien DeAntoni adapted from Jean-Paul Rigault courses 1 2 This Week A little reminder Constructor / destructor Operator overloading

More information

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each). A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary

More information

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere

More information

END TERM EXAMINATION

END TERM EXAMINATION END TERM EXAMINATION THIRD SEMESTER [BCA] DECEMBER 2007 Paper Code: BCA 209 Subject: Object Oriented Programming Time: 3 hours Maximum Marks: 75 Note: Attempt all questions. Internal choice is indicated.

More information

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC CMSC 341 Lecture 6 Templates, Stacks & Queues Based on slides by Shawn Lupoli & Katherine Gibson at UMBC Today s Topics Data types in C++ Overloading functions Templates How to implement them Possible

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

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:

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: Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before

More information

TEMPLATES AND ITERATORS

TEMPLATES 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 information

Lambda functions. Zoltán Porkoláb: C++11/14 1

Lambda functions. Zoltán Porkoláb: C++11/14 1 Lambda functions Terminology How it is compiled Capture by value and reference Mutable lambdas Use of this Init capture and generalized lambdas in C++14 Constexpr lambda and capture *this and C++17 Zoltán

More information

CS197c: Programming in C++

CS197c: 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 information

Standard Template Library. Containers, Iterators, Algorithms. Sequence Containers. Containers

Standard 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 information

Review Questions II KEY

Review Questions II KEY CS 102 / ECE 206 Spring 2011 Review Questions II KEY The following review questions are similar to the kinds of questions you will be expected to answer on Exam II (April 7), which will focus on LCR, chs.

More information

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

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 information

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

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp 1 CS 103 Unit 15 Doubly-Linked Lists and Deques Mark Redekopp 2 Singly-Linked List Review Used structures/classes and pointers to make linked data structures Singly-Linked Lists dynamically allocates each

More information

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1 Overview of C++ Prof. Amr Goneid, AUC 2 Overview of C++ Historical C++ Basics Some Library

More information