CS 215 Final Review Ismail abumuhfouz Fall 2014.

Slides:



Advertisements
Similar presentations
Brown Bag #3 Return of the C++. Topics  Common C++ “Gotchas”  Polymorphism  Best Practices  Useful Titbits.
Advertisements

Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Inheritance, Polymorphism, and Virtual Functions
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Data Structures Using C++ 2E
Programming Languages and Paradigms Object-Oriented Programming.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Pointer Data Type and Pointer Variables
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Pointers OVERVIEW.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
Pointers and Dynamic Memory Allocation Copyright Kip Irvine 2003, all rights reserved. Revised 10/28/2003.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
CS212: Object Oriented Analysis and Design Lecture 17: Virtual Functions.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Recursion ● Recursion is a computer programming technique that allows programmers to divide problems into smaller problems of the same type. ● You can.
Programming with Recursion
Final Exam Review CS 3358.
Chapter 16: Linked Lists.
Learning Objectives Pointers as dada members
C++ Programming:. Program Design Including
Andy Wang Object Oriented Programming in C++ COP 3330
Pointers and Linked Lists
Pointers and Linked Lists
5.13 Recursion Recursive functions Functions that call themselves
Copy Constructor / Destructors Stacks and Queues
Week 4 - Friday CS221.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Andy Wang Object Oriented Programming in C++ COP 3330
Methods Chapter 6.
classes and objects review
Cinda Heeren / Geoffrey Tien
C++ in 90 minutes.
This pointer, Dynamic memory allocation, Constructors and Destructor
LINKED LISTS CSCD Linked Lists.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Linked Lists Chapter 4.
CS 2308 Final Exam Review.
Chapter 15 Pointers, Dynamic Data, and Reference Types
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Recursion Chapter 11.
Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes
Andy Wang Object Oriented Programming in C++ COP 3330
Programming Abstractions
Stacks.
CISC/CMPE320 - Prof. McLeod
Introduction to Data Structure
Chapter 8: Class Relationships
EE 312 Final Exam Review.
Final Exam Review Inheritance Template Functions and Classes
CS 2308 Final Exam Review.
SPL – PS3 C++ Classes.
SPL – PS2 C++ Memory Handling.
Presentation transcript:

CS 215 Final Review Ismail abumuhfouz Fall 2014

Exam format * true/false (10%) * multiple choices (45%) * short answers and coding questions (45%) ◮ answering questions ◮ code reading and writing

Topics General topics it would be good to review for each chapter: Definitions and rules. Technical names of things. Syntax of C++ constructs. Meaning of C++ constructs (reading code). System classes, functions, and header files. Common errors. Algorithms.

Topics Midterm (Chapter 2-5). Vectors & Arrays (Chapter 6). Pointers (Chapter 7). Classes (Chapter 9). Inheritance and polymorphism (Chapter 10). Recursion (Chapter 11). Time Complexity (Chapter 12) Lists, stacks, and queues (Chapter 13).

Chapter 2-5 Types and variables Conditionals and loops Functions ◮ int, long, double, char. ◮ Variable naming rule (letter case), scope, address, value. ◮ Variable should be declared and initialized before use. ◮ static cast<int>(myDouble): cast a double to int. Conditionals and loops ◮ ==, >=, <= ◮ if statement, for loop, while loop, and do-while loop. Functions ◮ Passing by value, passing by reference (&) ◮ Array parameter is passed by reference by default ◮ Everything else is passed by value by default

Chapter 6 Arrays Char arrays Vectors ◮ Declaration of arrays ◮ Array of pointers ◮ Array name is a pointer that points to the first element in this array ◮ int a[5]; What are the types of a, &a, *a, a[2], &(a[2])? Char arrays ◮ C string: char array. ◮ char* myStr1 = “Hello”; (myStr1 points to a const C string) ◮ char* myStr2 = new char[5]; (myStr2 points to a char array in heap memory) ◮ char myStr3[5]; (myStr3 points to a char array in stack memory) ◮ C++ string, aka string object: std::string strObj(“Hello”); ◮ Converting an string object to C string: strObj.c str(); ◮ What is strObj[2] ? Vectors ◮ push back(), pop back() ◮ vector<int>::iterator it; (vector<int> myVec;) ◮ for (it = myVec.begin(); it != myVec.end(); it++) ◮ for (int i = 0; i < myVec.size(); i++)

Pointers and dynamic allocation Chapter 7 Pointers and dynamic allocation ◮ Declaration of pointers ◮ int myInt = 5; int* myIntPtr1 = &myInt; ◮ int* myIntPtr2 = new int[10]; ◮ int* myIntPtr3 = new int; ◮ delete[] myIntPtr2; ◮ delete myIntPtr3; ◮ Should NOT delete myIntPtr1; ◮ Array-pointer duality: a[i] = *(a + i) ◮ Pointer arithmetic: + 1 goes to next element in an array. Common errors ◮ Deferencing uninitialized / NULL pointer ◮ Memory leaks (didn’t free something). ◮ Dangling pointer (using already-deleted memory). ◮ Bounds error (going past the allocated array). ◮ Wrong deletion operator.

Chapter 9 Encapsulation: separating interface from implementation. ◮ All access to your class goes through the interface. ⋆ The public member functions (methods). ◮ Member variables (data) are private. ⋆ Only accessible by the methods. A class describes a set of objects with the same behavior. ◮ A class is a type. ◮ An object is a thing of that type. ◮ You use an object by calling its methods. Constructors ◮ Initialize an object’s private data. ◮ Same name as the class. ◮ When does a constructor get called? ◮ Difference between default constructor and overloaded constructor? Destructors ◮ Name is class name with a tilde before it: ∼className(). ◮ No return type, no parameters. ◮ Frees any data allocated in the class. ◮ Automatically called when the object ceases to exist. Xiwei (Jeffrey) Wang (UK CS) CS 215 Final Review

Chapter 10 Inheritance Inherited methods ◮ Implements the “is-a” relationship. What about aggregation? (“has- a”). ◮ Derived class inherits from the base class. ◮ C++ syntax: class Car : public Vehicle {...};. ◮ The derived class has all the members of the base class, plus any additional members declared in the derived class. ◮ Base-class private data is not directly accessible. ⋆ Use the base-class constructor to initialize the data: Derived::Derived(...) : Base(...) {...} ⋆ Use accessors to get their values. Inherited methods ◮ Methods are inherited: can call a base-class method on a derived- class object. ◮ You can override a method by redefining it in the derived class. ⋆ Can call the base class version: BaseClass ::method();.

Chapter 10 Slicing and polymorphism ◮ Putting a derived class object into a base-class variable slices off the derived parts. ⋆ This is usually not what you want. ◮ Base-class pointers and references can safely point to derived objects, without slicing. ⋆ Static type: declared type of the pointer (Person *) ⋆ Dynamic type: what it actually points to (Employee *) ⋆ Polymorphism is when these are different. virtual functions and abstract classes ◮ If you want to use polymorphism, you should declare the methods (the ones that will be overridden in derived classes) in based class as virtual. ◮ If a class contains at least one pure virtual function, it is an abstract class. ◮ You cannot instantiate an abstract class (creating objects of this class)

Chapter 11 Recursion: a function calling itself. ◮ The idea: solve a hard problem by first solving an easier version of the same problem ◮ . . . which you solve by finding an even easier version ◮ . . . until the problem is so easy you can solve it right away. Two components of a recursive function ◮ There must be special cases to handle the simplest tasks directly so that the function will stop calling itself. (Base case) ◮ Every recursive call must simplify the task in some way. (Recursive call )

Chapter 11 Example recursive definitions: Avoiding infinite recursion: ◮ Factorial: Base case: n <= 1 → n! = 1; General case: n > 1 Recursive formula: n! = (n − 1)! ∗ n ◮ Fibonacci: Base cases: n <= 1 → F (0) = F (1) = 1; General case: n > 1 Recursive formula: F (n) = F (n − 1) + F (n − 2) ◮ Merge sort: Base case: a one-element array is already sorted. Recursive call: cut in half, merge sort each half, then merge. Avoiding infinite recursion: ◮ Must check the base case first. ◮ No recursion in the base case! ◮ And the recursive call(s) must bring you closer to the base case. Mutual recursion: A calls B, B calls C, C calls A.

Chapter 12 Run-time complexity ◮ How does the time taken depend on the input size? ◮ Order of complexity: big O notation. ⋆ Calculate the number of operations performed. ⋆ Take only the fastest-growing term (highest exponent). ⋆ Remove any constant factors. ⋆ 3n2 + 6n + 100 becomes O(n2). ⋆ O(1) < O(logn) < O(n) < O(nlogn) < O(n2) < O(n3) < O(2n )

Chapter 13 Stacks Queues Linked list ◮ A stack lets you insert and remove elements at one end only. ◮ Stack is a LIFO (Last-In, First-Out) data structure. Queues ◮ A queue lets you add items to one end of the queue (the back) and remove them from the other end of the queue (the front). ◮ Queue is a FIFO (First-In, First-Out) data structure. Linked list ◮ Linked list is a data structure that supports efficient addition and removal of elements in the middle of a sequence. ◮ A typical doubly linked list node has three fields: data, previous pointer, next pointer. ◮ A typical singly linked list node has two fields: data, and next pointer. ◮ STL linked list: std::list<string> myList; ◮ Iterator: list<string>::iterator it;