Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview."— Presentation transcript:

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

2 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

3 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

4 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

5 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

6 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

7 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

8 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

9 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

10 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

11 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


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

Similar presentations


Ads by Google