Introduction to ADTs

Size: px
Start display at page:

Download "Introduction to ADTs"

Transcription

1 Data Structure Introduction to ADTs A particular way of storing and organizing data in a computer so that it can be used efficiently *from Wikipedia A set of data values and associated operations that are precisely specified independent of any particular implementation. *from A data type having - A specific, physical or logical representation of the data - Operations over its data A concrete and logical description May be implemented in various ways - Implementation-dependent Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details. Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation. Options in designing a program that requires new ADT In the course of designing a program and discovering that a new data type is needed, the options are : Use an existing type Build our ADT from scratch by declaring a new class Inherit from an existing class and make slight modifications Fall 2018 Husain Gholoom Lecturer in Computer Science Page 1

2 Example Let's take one real life example of a TV, which you can turn on and off, change the channel, adjust the volume, and add external components such as speakers, VCRs, and DVD players, BUT you do not know its internal details, that is, you do not know how it receives signals over the air or through a cable, how it translates them, and finally displays them on the screen. Thus, we can say a television clearly separates its internal implementation from its external interface and you can play with its interfaces like the power button, channel changer, and volume control without having zero knowledge of its internals. Example Your program can make a call to the sort() function without knowing what algorithm the function actually uses to sort the given values. In fact, the underlying implementation of the sorting functionality could change between releases of the library, and as long as the interface stays the same, your function call will still work. In C++, we use classes to define our own abstract data types (ADT). You can use the cout object of class iostream to stream data to standard output like this: #include <iostream> using namespace std; int main( ) cout << "Hello C++" <<endl; return 0; Here, you don't need to understand how cout displays the text on the user's screen. You need to only know the public interface and the underlying implementation of cout is free to change. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 2

3 Access Labels Enforce Abstraction: In C++, we use access labels to define the abstract interface to the class. A class may contain zero or more access labels: Members defined with a public label are accessible to all parts of the program. The data-abstraction view of a type is defined by its public members. Members defined with a private label are not accessible to code that uses the class. The private sections hide the implementation from code that uses the type Data Abstraction Example: Any C++ program where you implement a class with public and private members is an example of data abstraction. Consider the following example: #include <iostream> using namespace std; class Adder public: // constructor Adder(int i = 0) total = i; ; // interface to outside world void addnum(int number) total += number; // interface to outside world int gettotal() return total; ; private: // hidden data from outside world int total; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 3

4 int main( ) Adder a; a.addnum(10); a.addnum(20); a.addnum(30); cout << "Total " << a.gettotal() <<endl; return 0; When the above code is compiled and executed, it produces the following result: Total 60 Above class adds numbers together, and returns the sum. The public members addnum and gettotal are the interfaces to the outside world and a user needs to know them to use the class. The private member total is something that the user doesn't need to know about, but is needed for the class to operate properly. Benefits of ADT's. ADTs have several benefits: o o o o o o Simplicity: Client programmer does not have to be concerned with details that underlie the implementation of the ADT (eg keeping track of the front and back of a queue) Modularity - Reliability: Dividing a system into components or modules, each of which can be designed, implemented, tested, reasoned about, and reused separately from the rest of the system. Abstractions : Omitting or hiding low-level details with a simpler ideas Encapsulation: Building walls around a module (a hard shell or capsule) so that the module is responsible for its own internal behavior, and bugs in other parts of the system can t damage its integrity. Flexibility for client programmer: can choose from among several implementations of an ADT Example: array stack for efficient time and space Or linked stack for flexibility Independence: ADT programmer can change implementations of ADT without forcing client to change. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 4

5 Data Structures Again The term data structures is often extended to include both concrete AND logical descriptions of complicated data types. A list of data structures could include ADTs - arrays - linked lists - stacks - queues - vectors or lists ADTs and Program Design ADTs are an important part of bottom up program design In practice, programs are built using a combination of top down and bottom up approaches: o Top down: Decompose problem into subproblems, then decompose subproblems. Repeat until subproblems are simple Structure charts are a common design tool o Bottom up Design a set of tools and use them to build a solution the problem The tools are the values and operations of ADTs Designing ADTs is an essential part of bottom up design ADT Operations Categories Declare a variable of the type o ( ie using a type defined in the package ) Allocate a variable of the type o May be done by a declaration o Or may require a special operation ( eg new or constructor-like call ) Fall 2018 Husain Gholoom Lecturer in Computer Science Page 5

6 Operations on values ( ie procedures and functions that have values of the type as parameters ): o Query a property of the value or the status of a value or a component of a value o Modify a value (ie through an in/out parameter) o Combining two or more values and return a new value (of the same or different type) o Comparing two or more values o Convert a value to a string o Input/output of values Iterate through subcomponents Commonly used ADTs The purpose of many commonly used ADTs is to: - Store a collection of objects - Potentially organize the objects in a specific way - Provide potentially limited access to the objects These ADTs are often called - Containers - Collections - Container classes The ADT Basic Collections are : There are three basic collections. The basic collection is often called a bag. It stores objects with no ordering of the objects and no restrictions on them. Another unstructured collection is a set where repeated objects are not permitted: it holds at most one copy of each item. A set is often from a predefined universe. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 6

7 A collection where there is an ordering is often called a list. Specific examples include an array, a vector and a sequence. These have the same idea, but vary as to the methods they provide and the efficiency of those methods. Other Examples : A List ADT - Stack and Queue - Tree - Map (or dictionary) Values: ordered (1st, 2nd, etc) set of objects Operations: - constructor: creates an empty list - isempty: is the list empty - size: returns the number of elements - add an element to the end of the list - add an element at any position of the list. - remove an element i from the list - remove the first occurrence of any element from a non-empty list. - return the element at position i - replace an element at any position by another element. A Set ADT Values: collection of unique objects Operations: - constructor: creates an empty set - isempty: is the set empty - size: returns the number of elements - add an element to the set (if not there) - remove an element from the set (if it is there) - iselement(x): true if x is in the set - union: combine two sets into one Fall 2018 Husain Gholoom Lecturer in Computer Science Page 7

8 A Map ADT A collection of unique keys and a collection of values where each key is associated with a single value. Keys have one type, values another. Operations may include: constructor: creates an empty map isempty: returns true if map has no key-value pairs size: returns the number of key-value pairs in the map get(k): returns value associated with key k (if any) put(k,v): associates value v with key k (adds a pair) keyset: returns a set of all the keys in the map A Bag (multi-set) ADT A bag is an ADT or abstract data type defines a way of storing data: it specifies only how the ADT can be used and says nothing about the implementation of the structure. The bag values are unordered collection of objects (may include duplicates) The Bag ADT might have: accessor methods such as size, count Occurrence, possibly an iterator (which steps through all the elements). modifier methods such as add, remove, and addall. A union method which combines two bags to produce a third. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 8

9 The Bag ADT Operations : Inside the bag are some elements, values, or numbers. When you first begin to use a bag, the bag will be empty ( called initial state ) Numbers may be inserted into a bag. The bag can hold many numbers We can even insert the same numbers more than once We may ask about the contents of the bag. We may remove a numbers from a bag. But we remove only one number at a time. We can determine how many numbers are in a bag. Summary of the Bag Operations: - constructor: creates an empty bag - isempty: is the bag empty - size: returns the number of elements - add an element to the bag - remove an element from the bag (if it is there) - removes all copies of an element from the bag - occurrences(x): how many times x is in the bag Implementing an ADT Interface : Implementation : - class declaration - prototypes for the operations - data members for the actual representation - ( *.h ) - function definitions for the operations - depends on data members (their representation) - ( *.cpp ) Fall 2018 Husain Gholoom Lecturer in Computer Science Page 9

10 Example ADT: Bag Version 1 ( header file ) #include<iostream> #include <cassert> using namespace std; class Bag public: Bag (); void insert(int element); void remove(int element); int occurrences(int element) const; bool isempty() const; int size() const; static const int CAPACITY = 20; ; private: int data[capacity]; int count; concrete representation Note : #include <cassert> is a header file in the standard library of the C programming. The macro implements an assertion, which can be used to verify assumptions made by the program and print a diagnostic message if this assumption is false. Member variables of a class can be made static by using the static keyword. Static member variables only exist once in a program regardless of how many class objects are defined! Fall 2018 Husain Gholoom Lecturer in Computer Science Page 10

11 Example ADT: Bag Version 1 ( header implementation ) Bag::Bag () count = 0; void Bag::insert(int element) assert (count < CAPACITY); data[count] = element; count++; // what does this do? void Bag::remove(int element) int index = -1; for (int i=0; i<count && index==-1; i++) if (data[i]==element) index = i; if (index!=-1) data[index] = data[count-1]; count--; int Bag::occurrences(int element) const int occurrences=0; for (int i=0; i<count; i++) if (data[i]==element) occurrences++; return occurrences; bool Bag::isEmpty() const return (count==0); int Bag::size() const return count; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 11

12 Bag - driver int main() Bag b; cout << "\nis empty " << b.isempty() << endl ; b.insert(4); b.insert(8); b.insert(4); cout << "is empty " << b.isempty() << endl << endl ; cout << "size " << b.size() << endl ; cout << "how many 4's: " << b.occurrences(4) << endl << endl; b.remove(4); cout << "removed a 4" << endl; cout << "size " << b.size() << endl; cout << "how many 4's: " << b.occurrences(4) << endl << endl; Bag c(b); cout << "copied to c" << endl; cout << "size " << c.size() << endl; cout << "how many 4's: " << c.occurrences(4) << endl << endl; b.insert(10); cout << "added 10 to b" << endl; cout << "b.size " << b.size() << endl; cout << "c.size " << c.size() << endl << endl; cout << "starting insert of 20 items" << endl; for (int i = 0; i < 20; i++) b.insert(33); cout << "inserted 20 more items into b" << endl; return 0; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 12

13 Bag driver : output output of running bagtest is empty 1 is empty 0 size 3 how many 4's: 2 removed a 4 size 2 how many 4's: 1 copied to c size 2 how many 4's: 1 added 10 to b b.size 3 c.size 2 starting insert of 20 items assertion "count < CAPACITY" failed: file "../bagimp.cpp", line 17, function: void Bag::insert(int) 0 [main] L5- Bag 4412 cygwin_exception::open_stackdumpfile: Dumping stack trace to L5- Bag.exe.stackdump One way to resolve is to increase the size of the array Bag Version 1 - Summary Implemented using a fixed size array When adding more elements than fit in the bag, the program exits. One Solution : increase the size of the array in bag.h Better Solution: - use a dynamically allocated array - when its capacity is reached, allocate a new, bigger array. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 13

14 Bag Version -2 : Using Dynamic Memory Allocation ( header file ) class Bag public: Bag (); void insert(int element); void remove(int element); int occurrences(int element) const; bool isempty() const; int size() const; static const int INCREMENT = 20; ; private: int *data; //pointer to bag array // concrete representation int capacity; //size of the array int count; //number of elements currently in array Fall 2018 Husain Gholoom Lecturer in Computer Science Page 14

15 Bag Version 2 ( Header Implementation ) Bag::Bag () count = 0; capacity = INCREMENT; data = new int[capacity]; void Bag::insert(int element) //if count is at the capacity, resize if (count==capacity) capacity += INCREMENT; int *newdata = new int[capacity]; //new array for (int i=0; i<count; i++) //copy values newdata[i] = data[i]; delete [] data; //delete old array data = newdata; //make data point to new data[count] = element; //add new element count++; // no changes to remaining functions! Fall 2018 Husain Gholoom Lecturer in Computer Science Page 15

16 bag driver : output version 2 output of running bagtest is empty 1 is empty 0 size 3 how many 4's: 2 removed a 4 size 2 how many 4's: 1 copied to c size 2 how many 4's: 1 added 10 to b b.size 3 c.size 2 starting insert of 20 items inserted 20 more items into b resizing succeeded! Fall 2018 Husain Gholoom Lecturer in Computer Science Page 16

17 Bag Implementation Using Vector - Summary of the Operations: - constructor: creates an empty bag - drop : add a number to the bag - pick: erase an element from the bag - get_size : returns the number of elements - get_capacity : returns cap - display : display numbers - is_full : is the bag full - subtract : erase common numbers from 2 bags Fall 2018 Husain Gholoom Lecturer in Computer Science Page 17

18 Vector Bag Implementation - bagvector.h #ifndef BAGVECTOR_H_ #define BAGVECTOR_H_ #include <iostream> #include <vector> using namespace std; class My_Bag private: const static int DS=5; vector<int> b; unsigned int cap; unsigned int size; public: My_Bag(); My_Bag(int); bool drop(int); bool pick(int); int get_size(); int get_capacity(); void display(); bool is_full(); bool subtract(const My_Bag&); ; bool My_Bag::subtract(const My_Bag& q) if (size==0 cap==0) return true; for (int i=0;i<q.b.size();i++) pick(q.b[i]); return true; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 18

19 Vector Bag Implementation ( cont. ) : My_Bag::My_Bag() cap=ds; size=0; My_Bag::My_Bag(int c) if (c<=0) cap=ds; else cap=c; size=0; bool My_Bag::drop(int item) if (size==cap) return false; b.push_back(item); ++size; return true; bool My_Bag::pick(int item) int index=-1; for (unsigned int i=0;i<size;i++) if (b[i]==item) index=i; b.erase(b.begin()+index); --size; return true; return false; int My_Bag::get_size() return size; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 19

20 Vector Bag Implementation ( cont. ) : int My_Bag::get_capacity() return cap; bool My_Bag::is_full() if (size==cap) return true; else return false; void My_Bag::display() cout << "Bag capacity: " << cap << endl; cout << "Current size: " << size << endl; for(unsigned int i=0;i<size;i++) cout << b[i] << ' '; cout << endl; #endif /* BAGVECTOR_H_ */ Fall 2018 Husain Gholoom Lecturer in Computer Science Page 20

21 Vector Bag Implementation ( cont. ) : bagvectordriver.cpp #include <iostream> #include <vector> #include "bagvector.h" using namespace std; int main() My_Bag b1(5); b1.drop(10); b1.drop(10); b1.drop(20); b1.pick(10); b1.drop(20); b1.drop(30); b1.drop(10); b1.pick(20); b1.drop(-100); b1.drop(-100); b1.pick(10); b1.pick(10); b1.pick(30); b1.pick(-1009); b1.drop(20); b1.display(); cout << "==================\n"; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 21

22 bagvectordriver.cpp - ( continued ) My_Bag b2(10); b2.drop(20); b2.drop(20); b2.drop(30); b2.drop(78); b1.subtract(b2); b1.display(); cout << "==================\n"; b2.drop(-100); b2.drop(20); b2.subtract(b1); b2.display(); cout << "==================\n"; b2.drop(10); b1.subtract(b2); b1.display(); cout << "==================\n"; b1.drop(20); b2.subtract(b1); b2.display(); cout << "==================\n"; return 0; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 22

23 Sample Run Bag capacity: 5 Current size: ================== Bag capacity: 5 Current size: ================== Bag capacity: 10 Current size: ================== Bag capacity: 5 Current size: ================== Bag capacity: 10 Current size: ================== Fall 2018 Husain Gholoom Lecturer in Computer Science Page 23

24 ADT - Example -2 : Rolling a Pair of Dice Write a function that rolls a pair of dice until the sum of numbers rolled is a specific number. Also, calculate the number of times the dice are rolled to get the desired sum. Note that the smallest number in each die is 1 and the largest number is 6. So, the smallest sum of the numbers rolled is 2 and the largest sum of the numbers rolled is 12. Use the random number generator to randomly generate a number between 1 and 6 by using the following formula for both die1 and die2 :- die1 = rand() % 6 + 1; die2 = rand() % 6 + 1; sum = die1 + die2; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 24

25 Solution : Rolling a Pair of Dice #include <iostream> #include <cstdlib> #include <ctime> #include "die.h" class die public: die(); //Default constructor //Sets the default number rolled by a die to 1 int roll(); //Function to roll a die. //This function uses a random number generator to randomly //generate a number between 1 and 6, and stores the number //in the instance variable num and returns the number. int getnum() const; //Function to return the number on the top face of the die. //Returns the value of the instance variable num. private: int num; ; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 25

26 die.cpp //Implementation File for the class clocktype using namespace std; die::die() num = 1; srand(time(0)); int die::roll() num = rand() % 6 + 1; return num; int die::getnum() const return num; Fall 2018 Husain Gholoom Lecturer in Computer Science Page 26

27 //The user program that uses the class rolldie int main() die die1; die die2; int sum ; int rollcount = 0; cout << "die1: " << die1.getnum() << endl; cout << "die2: " << die2.getnum() << endl; sum = die1.getnum() + die2.getnum(); cout << "die1 + die2 = " << sum << endl; do cout << "After rolling die1: " << die1.roll() << endl; cout << "After rolling die2: " << die2.roll() << endl; cout << "The sum of the numbers rolled" << " by the dice is: " << die1.getnum() + die2.getnum() << endl; rollcount ++; while ( ( die1.getnum() + die2.getnum() )!= sum); cout << endl; cout << "The number of times the Dice was rolled = " << rollcount<<endl; return 0; //end main Fall 2018 Husain Gholoom Lecturer in Computer Science Page 27

28 Sample Run die1: 1 die2: 1 die1 + die2 = 2 After rolling die1: 5 After rolling die2: 1 The sum of the numbers rolled by the dice is: 6 After rolling die1: 3 After rolling die2: 3 The sum of the numbers rolled by the dice is: 6 After rolling die1: 4 After rolling die2: 3 The sum of the numbers rolled by the dice is: 7 After rolling die1: 1 After rolling die2: 1 The sum of the numbers rolled by the dice is: 2 The number of times the Dice was rolled = 4 Fall 2018 Husain Gholoom Lecturer in Computer Science Page 28

29 C++ Standard Template Library and Standard Library contain components such as : <array> <deque> New in C++11 and TR1. Provides the container class template std::array, a container for a fixed sized array. Provides the container class template std::deque, a double-ended queue. <forward_list> New in C++11 and TR1. Provides the container class template std::forward_list, a singly linked list. <list> <map> <queue> <stack> Provides the container class template std::list, a doubly linked list. Provides the container class templates std::map and std::multimap, sorted associative array and multimap. Provides the container adapter class std::queue, a single-ended queue, and std::priority_queue, a priority queue. Provides the container adapter class std::stack, a stack. <unordered_map> New in C++11 and TR1. Provides the container class template std::unordered_map and std::unordered_multimap, hash tables. <vector> Provides the container class template std::vector, a dynamic array. <algorithm> Provides definitions of many container algorithms such as sorting, searching. <iterator> Provides classes and templates for working with iterators. <string> <regex> Provides the C++ standard string classes and templates. New in C++11. Provides utilities for pattern matching strings using regular expressions. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 29

30 <fstream> Provides facilities for file-based input and output. See fstream. <iomanip> Provides facilities to manipulate output formatting, such as the base used when formatting integers and the precision of floating point values. <istream> Provides the template class std::istream and other supporting classes for input. <ostream> Provides the template class std::ostream and other supporting classes for output. <exception> Provides several types and functions related to exception handling, including std::exception, the base class of all exceptions thrown by the Standard Library. <thread> <mutex> New in C++11. Provide class and namespace for working with threads. New in C This section provides mechanisms for mutual exclusion: ( mutexes, locks, and call once. or exception) from a function that has run in the same thread or another thread. <complex> The header <complex> defines a class template, and numerous functions for representing and manipulating complex numbers. Fall 2018 Husain Gholoom Lecturer in Computer Science Page 30

Introduction to ADTs

Introduction to ADTs Data Structure Introduction to ADTs A particular way of storing and organizing data in a computer so that it can be used efficiently *from Wikipedia A set of data values and associated operations that

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

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

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table

More information

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Outline 12.1 Test-Driving the Craps Game Application 12.2 Random Number Generation 12.3 Using an enum in the Craps

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

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

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list Linked Lists Introduction : Data can be organized and processed sequentially using an array, called a sequential list Problems with an array Array size is fixed Unsorted array: searching for an item is

More information

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list Linked Lists Introduction : Data can be organized and processed sequentially using an array, called a sequential list Problems with an array Array size is fixed Unsorted array: searching for an item is

More information

Heaps. A complete binary tree can be easily stored in an array - place the root in position 1 (for convenience)

Heaps. A complete binary tree can be easily stored in an array - place the root in position 1 (for convenience) Binary heap data structure Heaps A binary heap is a special kind of binary tree - has a restricted structure (must be complete) - has an ordering property (parent value is smaller than child values) Used

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

STL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms

STL 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 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

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

Data Structures (INE2011)

Data Structures (INE2011) Data Structures (INE2011) Electronics and Communication Engineering Hanyang University Haewoon Nam ( hnam@hanyang.ac.kr ) Lecture 1 1 Data Structures Data? Songs in a smartphone Photos in a camera Files

More information

Class and Function Templates

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

Motivation for Templates. Class and Function Templates. One Way to Look at Templates...

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

TDDD38 - Advanced programming in C++

TDDD38 - Advanced programming in C++ TDDD38 - Advanced programming in C++ STL II Christoffer Holm Department of Computer and information science 1 Iterators 2 Associative Containers 3 Container Adaptors 4 Lambda Functions 1 Iterators 2 Associative

More information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

CS2255 HOMEWORK #1 Fall 2012

CS2255 HOMEWORK #1 Fall 2012 CS55 HOMEWORK #1 Fall 01 1.What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; a. 10 b. 7 c. The

More information

EECE.3220: Data Structures Spring 2017

EECE.3220: Data Structures Spring 2017 EECE.3220: Data Structures Spring 2017 Lecture 14: Key Questions February 24, 2017 1. Describe the characteristics of an ADT to store a list. 2. What data members would be necessary for a static array-based

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

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.

More information

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures C++ Review 1 Purpose of Review Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures 2 Class The Class defines the data structure

More information

C++ Functions. Last Week. Areas for Discussion. Program Structure. Last Week Introduction to Functions Program Structure and Functions

C++ Functions. Last Week. Areas for Discussion. Program Structure. Last Week Introduction to Functions Program Structure and Functions Areas for Discussion C++ Functions Joseph Spring School of Computer Science Operating Systems and Computer Networks Lecture Functions 1 Last Week Introduction to Functions Program Structure and Functions

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

Motivation for Templates

Motivation for Templates Motivation for You want both: a list of Location objects a list of MazeMonster objects 1 How can you accomplish this by writing one LinkedList class? state all the ways you can think of doing this state

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

! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples:

! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples: Ch. 8: ADTs: Stacks and Queues Abstract Data Type A data type for which: CS 8 Fall Jill Seaman - only the properties of the data and the operations to be performed on the data are specific, - not concerned

More information

PIC10B/1 Winter 2014 Exam I Study Guide

PIC10B/1 Winter 2014 Exam I Study Guide PIC10B/1 Winter 2014 Exam I Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-8 inclusive) 2. Examples/Homework 3. Textbook The midterm will test 1. Your ability to read a program and understand

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

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

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

CSC 222: Computer Programming II. Spring 2004

CSC 222: Computer Programming II. Spring 2004 CSC 222: Computer Programming II Spring 2004 Stacks and recursion stack ADT push, pop, top, empty, size vector-based implementation, library application: parenthesis/delimiter matching run-time

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

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

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory

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

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

C++ Programming. Classes, Constructors, Operator overloading (Continued) M1 Math Michail Lampis

C++ Programming. Classes, Constructors, Operator overloading (Continued) M1 Math Michail Lampis C++ Programming Classes, Constructors, Operator overloading (Continued) M1 Math Michail Lampis michail.lampis@dauphine.fr Classes These (and the previous) slides demonstrate a number of C++ features related

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

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

Example Final Questions Instructions

Example Final Questions Instructions Example Final Questions Instructions This exam paper contains a set of sample final exam questions. It is for practice purposes only. You ll most likely need longer than three hours to answer all the questions.

More information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

Introduction to C++ Introduction to C++ 1

Introduction to C++ Introduction to C++ 1 1 What Is C++? (Mostly) an extension of C to include: Classes Templates Inheritance and Multiple Inheritance Function and Operator Overloading New (and better) Standard Library References and Reference

More information

Integer Data Types. Data Type. Data Types. int, short int, long int

Integer Data Types. Data Type. Data Types. int, short int, long int Data Types Variables are classified according to their data type. The data type determines the kind of information that may be stored in the variable. A data type is a set of values. Generally two main

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can

More information

Computational Physics

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

CMSC 341 Lecture 6 STL, Stacks, & Queues. Based on slides by Lupoli, Dixon & Gibson at UMBC

CMSC 341 Lecture 6 STL, Stacks, & Queues. Based on slides by Lupoli, Dixon & Gibson at UMBC CMSC 341 Lecture 6 STL, Stacks, & Queues Based on slides by Lupoli, Dixon & Gibson at UMBC Templates 2 Common Uses for Templates Some common algorithms that easily lend themselves to templates: Swap what

More information

STL: C++ Standard Library

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

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Lab 2: ADT Design & Implementation

Lab 2: ADT Design & Implementation Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Topics du Jour: Make your own classes! (cont.) Last time we did a BankAccount class (pretty basic) This time we will do something more like the classes

More information

ADTs & Classes. An introduction

ADTs & Classes. An introduction ADTs & Classes An introduction Quick review of OOP Object: combination of: data structures (describe object attributes) functions (describe object behaviors) Class: C++ mechanism used to represent an object

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

C++_ MARKS 40 MIN

C++_ MARKS 40 MIN C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float

More information

Operator Overloading

Operator Overloading Steven Zeil November 4, 2013 Contents 1 Operators 2 1.1 Operators are Functions.... 2 2 I/O Operators 4 3 Comparison Operators 6 3.1 Equality Operators....... 11 3.2 Less-Than Operators...... 13 1 1 Operators

More information

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed? Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use countercontrolled, sentinel-controlled,

More information

CS 247: Software Engineering Principles. ADT Design

CS 247: Software Engineering Principles. ADT Design CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data

More information

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CMPSC11 Final (Study Guide) Fall 11 Prof Hartman Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) This is a collection of statements that performs

More information

Operator Overloading and Templates. Linear Search. Linear Search in C++ second attempt. Linear Search in C++ first attempt

Operator Overloading and Templates. Linear Search. Linear Search in C++ second attempt. Linear Search in C++ first attempt Operator Overloading and Templates Week 6 Gaddis: 8.1, 14.5, 16.2-16.4 CS 5301 Fall 2015 Jill Seaman Linear Search! Search: find a given target item in an array, return the index of the item, or -1 if

More information

CSC212. Data Structure. Lecture 4 Container Classes. Instructor: George Wolberg Department of Computer Science City College of New York

CSC212. Data Structure. Lecture 4 Container Classes. Instructor: George Wolberg Department of Computer Science City College of New York CSC212 Data Structure Lecture 4 Container Classes Instructor: George Wolberg Department of Computer Science City College of New York 1 Outline Bag class definition/implementation details Inline functions

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

Exam 1 is on Wednesday 10 / 3 / 2018

Exam 1 is on Wednesday 10 / 3 / 2018 Exam 1 is on Wednesday 10 / 3 / 2018 1) True/False : Indicate whether the statement is true or false. _ 1. A class is an example of a structured data type. _ 2. In C++, class is a reserved word and it

More information

Unit 4 Basic Collections

Unit 4 Basic Collections Unit 4 Basic Collections General Concepts Templates Exceptions Iterators Collection (or Container) Classes Vectors (or Arrays) Sets Lists Maps or Tables C++ Standard Template Library (STL Overview A program

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

Chapter 18 - C++ Operator Overloading

Chapter 18 - C++ Operator Overloading Chapter 18 - C++ Operator Overloading Outline 18.1 Introduction 18.2 Fundamentals of Operator Overloading 18.3 Restrictions on Operator Overloading 18.4 Operator Functions as Class Members vs. as friend

More information

CSE 333 Lecture 9 - intro to C++

CSE 333 Lecture 9 - intro to C++ CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia & Agenda Main topic: Intro to C++ But first: Some hints on HW2 Labs: The

More information

Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;

Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std; r6.14 For the operations on partially filled arrays below, provide the header of a func tion. d. Remove all elements that are less than a given value. Sol a. void remove_items_less_than(int arr[], int

More information

Ch 2 ADTs and C++ Classes

Ch 2 ADTs and C++ Classes Ch 2 ADTs and C++ Classes Object Oriented Programming & Design Constructing Objects Hiding the Implementation Objects as Arguments and Return Values Operator Overloading 1 Object-Oriented Programming &

More information

DATA STRUCTURES AND ALGORITHMS LECTURE 08 QUEUES IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD

DATA STRUCTURES AND ALGORITHMS LECTURE 08 QUEUES IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD DATA STRUCTURES AND ALGORITHMS LECTURE 08 S IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD S ABSTRACT DATA TYPE An Abstract Queue (Queue ADT) is an abstract data type that emphasizes specific

More information

Dr. Md. Humayun Kabir CSE Department, BUET

Dr. Md. Humayun Kabir CSE Department, BUET C++ Dr. Md. Humayun Kabir CSE Department, BUET History of C++ Invented by Bjarne Stroustrup at Bell Lab in 1979 Initially known as C with Classes Classes and Basic Inheritance The name was changed to C++

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2305/lab06.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 2 Extend the IntegerSet class from Lab 04 to provide the following

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

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

C++ 11 and the Standard Library: Containers, Iterators, Algorithms

C++ 11 and the Standard Library: Containers, Iterators, Algorithms and the Standard Library:,, Comp Sci 1575 Outline 1 2 3 4 Outline 1 2 3 4 #i n clude i n t main ( ) { i n t v a l u e 0 = 5 ; // C++ 98 i n t v a l u e 1 ( 5 ) ; // C++ 98 i n t v a

More information

Container Class and Integrators, Proxy Class EC6301-OOPS AND DATA STRUCTURES

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

Arrays and Linked Lists

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

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) Review for Test 1 (Chapter 1-5) 1. Software development 1. Pre-conditions and Post-conditions 2. Running time analysis Big O Timing loops and nested loops 1) Write the simplest big-o expression to describe

More information

Scott Gibson. Pointers & Dynamic Memory. Pre & Co Requisites. Random Access Memory. Data Types. Atomic Type Sizes

Scott Gibson. Pointers & Dynamic Memory. Pre & Co Requisites. Random Access Memory. Data Types. Atomic Type Sizes Scott Gibson Pointers & Dynamic Memory Lecture #1 Office: LAH 103 Email: sgibson@brookdalecc.edu sgib@optonline.net Web: www.brookdalecc.edu/fac/cos/sgibson Phone: (732) 224 2285 1 2 Pre & Co Requisites

More information

2 ADT Programming User-defined abstract data types

2 ADT Programming User-defined abstract data types Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Pre-Course: Variables, Basic Types, Control Structures Kostas Alexis Slides inspired by the course Modern C++, Uni Bonn: http://www.ipb.uni-bonn.de/teaching/modern-cpp/

More information

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011 The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

More information

G52CPP C++ Programming Lecture 18. Dr Jason Atkin

G52CPP C++ Programming Lecture 18. Dr Jason Atkin G52CPP C++ Programming Lecture 18 Dr Jason Atkin 1 Last lecture Operator Overloading Strings and streams 2 Operator overloading - what to know Know that you can change the meaning of operators Know that

More information

! A data type for which: ! An ADT may be implemented using various. ! Examples:

! A data type for which: ! An ADT may be implemented using various. ! Examples: Stacks and Queues Unit 6 Chapter 19.1-2,4-5 CS 2308 Fall 2018 Jill Seaman 1 Abstract Data Type A data type for which: - only the properties of the data and the operations to be performed on the data are

More information

Exceptions. Why Exception Handling?

Exceptions. Why Exception Handling? Exceptions An exception is an object that stores information transmitted outside the normal return sequence. It is propagated back through calling stack until some function catches it. If no calling function

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

Lectures 4 & 5 Container Classes

Lectures 4 & 5 Container Classes CSC212 Data Structure - Section FG Lectures 4 & 5 Container Classes Instructor: Feng HU Department of Computer Science City College of New York 1 Container Classes A container class is a data type that

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Lecture-5. STL Containers & Iterators

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

Introducing C++ to Java Programmers

Introducing C++ to Java Programmers Introducing C++ to Java Programmers by Kip Irvine updated 2/27/2003 1 Philosophy of C++ Bjarne Stroustrup invented C++ in the early 1980's at Bell Laboratories First called "C with classes" Design Goals:

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information