ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.

Slides:



Advertisements
Similar presentations
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Advertisements

Introduction to Programming Lecture 39. Copy Constructor.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
ECE Application Programming Instructor: Dr. Michael Geiger Fall 2012 Lecture 31: Dynamic memory allocation.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Engineering Problem Solving With C++ An Object Based Approach Chapter 9 Pointers and Creating Data Structures.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
CSE 333 – SECTION 4. Overview Pointers vs. references Const Classes, constructors, new, delete, etc. More operator overloading.
Pointers CS362. Pointers A Pointer is a variable that can hold a memory address Pointers can be used to: Indirectly reference existing variables (sometimes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
CSC 2400 Computer Systems I Lecture 5 Pointers and Arrays.
Stack and Heap Memory Stack resident variables include:
6. More on Pointers 14 th September IIT Kanpur C Course, Programming club, Fall
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Lecture Contents Arrays and Vectors: Concepts of pointers and references. Pointer declarations and initialization. Pointer Operators. Dynamic Memory Allocation.
Pointers OVERVIEW.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
Dynamic memory allocation and Pointers Lecture 4.
1 Pointers and Strings Chapter 5 2 What You Will Learn...  How to use pointers Passing arguments to functions with pointers See relationship of pointers.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Exam 3 Preview.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 22: Pointers.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
ECE Application Programming
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
12/23/2015Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 9 An Introduction.
ECE Application Programming Instructors: Dr. Michael Geiger & Nasibeh Nasiri Fall 2015 Lecture 31: Structures (cont.) Dynamic memory allocation.
1 CSC241: Object Oriented Programming Lecture No 05.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT9: Pointer I CS2311 Computer Programming.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 20: Container classes; strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT:10 Advance Pointer Array, String and Dynamic Memory Allocation CS2311 Computer Programming.
Chapter 16 Pointers and Arrays Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them in C. Pointer Address.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
ECE 264 Object-Oriented Software Development
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 16: Destructors, Copy Constructors and Exam 2 Review.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 13: Exam 1 Preview.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
CSCI 125 & 161 / ENGR 144 Lecture 16 Martin van Bommel.
Windows Programming Lecture 03. Pointers and Arrays.
Pointers and Dynamic Arrays
ECE Application Programming
ECE 264 Object-Oriented Software Development
ECE Application Programming
Motivation and Overview
ECE Application Programming
14th September IIT Kanpur
Chapter 15 Pointers, Dynamic Data, and Reference Types
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
C Programming Lecture-8 Pointers and Memory Management
EECE.2160 ECE Application Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Dynamic allocation (continued)
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Instructor: Dr. Michael Geiger Spring 2019 Lecture 23: Exam 2 Preview
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Presentation transcript:

ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview

Lecture outline Announcements/Reminders  Project notes Design due Wednesday, 11/19  Exam 2 Wednesday General exam information Exam review: what we’ve covered since the last exam  Class relationships: association, composition, and aggregation  Initialization lists  Arrays and vectors  Strings  Dynamic memory allocation 10/24/2015 ECE 264: Lecture 26 2

General exam information One 8.5” x 11” double-sided sheet of notes allowed Can use paper based materials (no computers and electronic devices) Start as close to 9:00 as possible and last 50 minutes Exam will be held in rooms: S&E 212 (Classroom) Very similar format to Exam 1: 3 questions, most of which have multiple parts  Question 1: Multiple choice  Question 2: Understanding code (i.e., given some code, what’s output?)  Question 3: Writing short code sequences Sample exam 2 on web site (can ask questions during office hours or other time, the solutions will be uploaded to the teaching website next Monday) 10/24/2015 ECE 264: Lecture 26 3

Review: Class relationships Interactions between different objects  Basic interactions: association  Classes as data members: composition/aggregation  Can model relationships in UML Initialization lists: call one object’s constructor inside another  Most useful with composition—have user-defined object inside another user-defined object  Want to call parameterized constructor for “child” Note: default constructors are called if you do nothing 10/24/2015 ECE 264: Lecture 26 4

Review: Arrays Constant size list of items of same type Can initialize using comma-separated list:  int n[] = {10, 20, 30, 40, 50}; Can access individual elements using []  cout << n[1]; would print 20 Can pass arrays to functions  void printArray(int arr[], int size); Pitfalls  Indexing past array boundaries  Array name is a pointer  passed by reference 10/24/2015 ECE 264: Lecture 26 5

Review: Vectors Vectors allow programmer to create “arrays” that:  Are dynamically resizable  Can be assigned to one another  Can be compared for equality  Contain easier generic boundary checking Can access vectors like arrays: v[0]  Can also use vector functions Examples: vector list; //empty vector vector wordList(n); //capacity:n strings //vector of 8 integers, each initialized to 0 vector intList(8,0); 10/24/2015 ECE 264: Lecture 26 6

Review: Vector methods Common member functions:  bool empty(): true if vector contains no values  void pop_back(): deletes last element in vector Does not actually return the element Gives an error if vector is empty  void push_back(element): add element to end of vector  void resize(int): changes the size of vector  size_t size(): returns the size of vector  at(int): allows you to insert element in vector, but also provides boundary checking : type of elements stored in the vector (e.g. int, double)  void clear(): removes all elements from vector 10/24/2015 ECE 264: Lecture 26 7

Review: Strings The string class : specialized container in STL  Character array + useful functions length() empty( ) c_str()  Returns character array at(int position)  Returns char at array[position] int find(string pattern, int position);  Returns position of first occurrence of pattern or string::npos substr (int start, int len)  Gets len characters, starting at position start  Can use overloaded operators as well == makes sense; other relational operators (, =) trickier = performs string copy +, += can be used for concatenation > behave as expected 10/24/2015 ECE 264: Lecture 26 8

Review: Pointers Pointer: address of another object  Can get address of existing object using &  Can get value of existing pointer using *  Can assign pointers to one another using = Assignment copies address, not value at that address  Pointer declaration: * Array-pointer duality  Array name is immovable pointer to first element  Can “index” pointer like array (e.g., p[1] ) Pointer arithmetic  If p is a pointer, p++ means “point to next element” “Next element” determined by base type  Can compare pointers p == NULL  pointer points nowhere p == q  p and q point to same location 10/24/2015 ECE 264: Lecture 26 9

Review: Pointers (cont.) Common errors  Failing to initialize pointer  Failing to reset pointer after moving it  Incorrect/unintended syntax (most common with pointer arithmetic) Referencing objects through pointers  Use -> in place of dot operator (.) 10/24/2015 ECE 264: Lecture 26 10

Review: Dynamic memory allocation Use new and delete  new int allocates space for 1 integer  new int[20] allocates an array of 20 integers  As with malloc(), new returns pointer to first byte  Can directly initialize element by putting initial value in parentheses e.g. new int(3)  Use delete only to free memory allocated by new If single variable allocated: delete ptr; If array space allocated: delete [] ptr; 10/24/2015 ECE 264: Lecture 26 11